--[[ ************************** Script version: v0.91 beta Requires CHDK 1.3! Licence: GPL (c) Werner_O 2014/11/15 ************************** @title USB Remote v0.91 @param s Shoot-Mode @default s 0 @values s PHOTO VIDEO @param f Foc-Mode (HYP Av/M only) @default f 0 @values f MAN HYP INF AF @param d Man. Focus Distance (mm) @default d 2000 @range d 0 66000 @param a Auto-Mode USB-Port @default a 1 @range a 0 1 ]] --Definition of the used variables: shoot_mode = s fixfoc = f if a == 1 then auto_mode = 1 --Definition Auto-mode for USB-Port else auto_mode = 0 end videostate = get_video_button() --Is a separate videobutton available (1 = Yes; 0 = No)? mf_mode = 0 --Predefinition MF-mode afl_mode = 0 --Predefinition AFL-mode usbhighspeedmode = false --Predefinition USB high precision timer ready = true --Predefinition script ready to run successfully --Definition console-layout: set_console_layout(0, 0, 33, 6) --Subfunction set_fixfoc() to set and show the results: function set_fixfoc() if fixfoc == 0 then distance = d --Set focus distance in mm fix_mode = "Manual focus" elseif fixfoc == 1 then distance = get_dofinfo().hyp_dist fix_mode = "Hyperfocal distance" else distance = -1 fix_mode = "Infinite distance" end local count = 0 local timeout = false set_focus(distance) press("shoot_half") repeat sleep(50) count = count + 1 if count > 40 then timeout = true end until get_shooting() or timeout release("shoot_half") focus = get_focus() print(string.format("Used MF-type: %s", fix_mode)) if fixfoc == 0 then message = "Wanted focus:" x = distance x_string = tostring(distance) print_focus() end message = "Focus set to:" x = focus x_string = tostring(focus) print_focus() if usb_mode == 1 then print("..Waiting for USB-impulse..") print("(Click MENU to exit)") else print("Click SET to shoot") print("(or click MENU to exit)") end end --Subfunction print_focus() to show wanted/realized distances: function print_focus() if (x < 0) then --True at distance infinite print(string.format("%s infinite", message)) elseif (x < 1000) then --True at distances < 1 m print(string.format("%s %03d mm", message, focus)) elseif (x < 10000) then --True at distances >= 1 m to < 10 m local string1 = string.sub(x_string, 1, 1) local string2 = string.sub(x_string, 2, 4) print(string.format("%s %s,%s m", message, string1, string2)) elseif (x < 100000) then --True at distances >= 10 m to < 100 m local string1 = string.sub(x_string, 1, 2) local string2 = string.sub(x_string, 3, 4) print(string.format("%s %s,%s m", message, string1, string2)) else --True at distances > 100 m local string1 = string.sub(x_string, 1, 3) local string2 = string.sub(x_string, 4, 4) print(string.format("%s %s,%s m", message, string1, string2)) end end --Subfunction Restore, used at script aborting via keys SHOOT or MENU: function restore() cls() if auto_mode == 1 then set_config_value(121,0) --Disable USB remote print("USB remote disabled") end if usbhighspeedmode == true then usbhighspeedmode = enable_remote_hp_timer(0) --Disable USB high precision timer print("USB high speed mode disabled") end if fixfoc < 3 then if mf_mode == 1 then set_mf(0) --Disable MF-mode print("Auto-MF has been disabled") elseif afl_mode == 1 then set_aflock(0) --Disable AFL-mode print("Auto-AFL has been disabled") else --True with native activated MF-mode print("Cam left in native MF-mode") end print(string.format("Used MF-type: %s", fix_mode)) if fixfoc == 0 then message = "Wanted focus:" x = distance x_string = tostring(distance) print_focus() end message = "Focus set to:" x = focus x_string = tostring(focus) print_focus() sleep(3000) console_redraw() sleep(3000) end end --Start main script - Check CHDK version and used progam for hyperfocal distance: capmode = require("capmode") --Include lua-library capmode.lua from folder A/CHDK/LUALIB cmode = capmode.get_name() --Get name of the used program if tonumber(string.sub(string.gsub(get_buildinfo().build_number, "%p", ""), 1, 3)) >= 130 then --Get CHDK version if fixfoc == 1 then if not (cmode == "AV" or cmode == "M") then ready = false errmessage1 = "Error: Hyperfocal distance" errmessage2 = "requires program Av or M!" end end if tonumber(get_buildinfo().build_revision) >= 3585 then --Get CHDK build number usbhighspeedmode = enable_remote_hp_timer(1000) --Enable USB high precision timer print("USB high speed mode enabled") end if (ready == true) and (fixfoc < 3) then if not (get_focus_state() < 0) then --True if cam is not in manual MF-mode x = set_mf(1) --Try to enable MF-mode if x == 1 then --At cams with available MF-mode x will be 1 mf_mode = 1 print("MF-Mode enabled") else set_aflock(1) --Enable AFL-mode instead MF-mode afl_mode = 1 print("AFL-Mode enabled") end end end else --CHDK version is to old; Error message and script aborting in main loop ready = false errmessage1 = "Error: This script" errmessage2 = "requires CHDK 1.3!" end --Start main loop if ready: if ready == true then if auto_mode == 1 then set_config_value(121,1) --Enable USB remote automatically if wanted print("USB remote enabled") end if fixfoc < 3 then set_fixfoc() end --True for focus settings not equal AF counter = 1 repeat usb = get_usb_power() --Wait for USB impulse if usb > 0 then if shoot_mode == 1 then --True at activated video recording if videostate == 1 then --True if a separate video button is available if get_movie_status() <= 1 then --True at stopped/paused video record click("video") --Start video record sleep(100) else click("video") --Stop video record repeat sleep(100) until get_movie_status() <= 1 --Wait until videoprocessing has finished end else print("No video button found:") print("Video record is not available") sleep(3000) end else --True at activated video recording count = get_exp_count() shoot() repeat sleep(10) until get_exp_count() ~= count cls() print(string.format("Shoot successful, picture %d", counter)) print("..Waiting for USB-impulse..") print("(Click MENU to exit)") counter = counter + 1 end end until is_pressed("menu") restore() else print(errmessage1) print(errmessage2) sleep(3000) end