--[[ ****************************************** Script version: v1.06 Requires CHDK >= 1.3 USB high speed mode requires >= CHDK v3442 Licence: GPL (c) Werner_O 2015/05/17 Thx to msl ****************************************** @title USB Remote 1.06 @chdk_version 1.3 @param m Shoot-Mode @default m 0 @values m PHOTO VIDEO AUTO @param t Auto-Time Limit (100ms) @default t 5 @range t 1 15 @param f Foc-Mode (HYP Av/M only) @default f 0 @values f AF MAN HYP INF @param d Man. Focus Distance (mm) @default d 2000 @range d 0 65000 @param a Auto-Mode USB-Port @default a 1 @range a 0 1 @param s Save-Mode: P,Tv,Av,M only @default s 1 @range s 0 1 ]] --Definition of the used variables: shoot_mode = m --Definition shoot-mode: PHOTO, VIDEO or AUTO foc_mode = f --Definition focus-mode: AF, MAN, HYP or INF if foc_mode == 2 then --True with choosen hyperfocal distance last_av96 = get_user_av_id() --Any found changes of the aperture value will cause new MF-settings in focus-mode HYP end usb_time_limit = t * 10 --Predefinition USB time limit; will changed later at found possible usb high speed mode usb_auto = a --Automatically enable/disable remote-mode for USB-Port if wanted save_mode = s --Allow only programs P, Tv, Av or M if activated mf_mode = 0 --Predefinition MF-mode; might be changed later afl_mode = 0 --Predefinition AFL-mode; might be changed later last_zoom = get_zoom() --Store current zoom position --Definition console-layout: set_console_layout(0, 0, 33, 6) --Subfunction restore(), used at script aborting via keys SHOOT or MENU: function restore() cls() if get_movie_status() == 4 then --True at running video record click("video") --Stop video record repeat sleep(100) until get_movie_status() <= 1 --Wait until videoprocessing has finished print("Video recording stopped") end if usb_auto == 1 then set_config_value(121,0) --Disable USB remote function print("USB remote disabled") end if high_speed then --Disable USB high speed mode if enabled if type(set_remote_timing) == "function" then set_remote_timing(0) elseif type(enable_remote_hp_timer) == "function" then enable_remote_hp_timer(0) elseif type(enable_highspeed_usb) == "function" then enable_highspeed_usb(0) end print("USB High speed mode disabled") end if foc_mode > 0 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 foc_mode == 1 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() end end --Subfunction set_fixfoc() to set and show the results: function set_fixfoc() if foc_mode == 1 then --True at setting manual focus distance = d --Set focus distance in mm fix_mode = "Manual focus" elseif foc_mode == 2 then --True at setting hyperfocal distance last_av96 = get_user_av_id() distance = get_dofinfo().hyp_dist --Get value for hyperfocal distance fix_mode = "Hyperfocal distance" else --True at setting infinite distance 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 foc_mode == 1 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() last_zoom = get_zoom() print("Waiting for USB-impulse...") print("(Click MENU to exit)") sleep(3000) console_redraw() 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 start_stop_video(): function start_stop_video() if get_movie_status() == 4 then --True at currently running video recording click("video") --Stop video record repeat sleep(100) until ((get_movie_status() <= 1) or (get_movie_status() == 6)) --Wait until videoprocessing has finished cls() print("Video recording stopped") else click("video") --Start video record cls() print("Video recording started") end print("Waiting for USB-impulse...") print("(Click MENU to exit)") end --Subfunction take_photo(): function take_photo() 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 --Get information to CHDK version/build and other values needed to run this script successfully: chdk_version = tonumber(string.sub(string.gsub(get_buildinfo().build_number, "%p", ""), 1, 3)) --Get CHDK version as integer number chdk_build = tonumber(get_buildinfo().build_revision) --Get CHDK build as integer number capmode = require("capmode") --Include lua-library capmode.lua from folder A/CHDK/LUALIB cmode = capmode.get_name() --Get name of the currently activated program video_button = get_video_button() --Is a separate video button available (1 = Yes; 0 = No)? rec,vid = get_mode() --Get current video recording state (variable "vid": true or false) --1) Abort, if CHDK version is < 1.30 err = {} if chdk_version < 130 then table.insert(err, "Error: This script") table.insert(err, "requires CHDK >= 1.3!") end --2) Abort, if video recording is currently active if vid == true then table.insert(err, "Error: Stop video recording") table.insert(err, "before running this script!") end --3) Abort in save-mode, if another program as P, Tv, Av or M is active if save_mode == 1 then if not (cmode == "P" or cmode == "TV" or cmode == "AV" or cmode == "M") then table.insert(err, "Error: Save-mode is active,") table.insert(err, "select program P, Tv, Av or M!") end end --4) Abort at choosen focus distance HYP, if programS Av or M are not active if foc_mode == 2 then if not (cmode == "AV" or cmode == "M") then table.insert(err, "Error: Hyperfocal distance") table.insert(err, "requires program Av or M!") end end --5) Abort at shoot modes VIDEO or AUTO, if no separate video button is available if (shoot_mode > 0) and (video_button == 0) then table.insert(err, "Error: No video button found at") table.insert(err, "this cam - select mode PHOTO!") end --Start main script if no errors were found: if #err == 0 then if usb_auto == 1 then set_config_value(121,1) --Automatically enable USB remote function if wanted print("USB remote enabled") end --Enable USB high speed mode if possible: high_speed = false if type(set_remote_timing) == "function" then high_speed = set_remote_timing(1000) elseif type(enable_remote_hp_timer) == "function" then high_speed = enable_remote_hp_timer(1000) elseif type(enable_highspeed_usb) == "function" then enable_highspeed_usb(1000) high_speed = true end if high_speed then print("USB high speed mode enabled") usb_time_limit = t * 100 else print("USB high speed mode n/a") end if foc_mode > 0 then --True at focus-settings MAN, HYP or INF 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 automatically") else set_aflock(1) --Enable AFL-mode instead MF-mode afl_mode = 1 print("AFL-mode enabled automatically") end else print("CAM is already in MF-mode") end set_fixfoc() --Set a fixed focus setting via this subfunction else --True for focus setting AF print("Waiting for USB-impulse...") print("(Click MENU to exit)") end --Start main loop: counter = 1 repeat if foc_mode == 2 then --True with choosen hyperfocal distance current_av96 = get_user_av_id() mstring1 = "" if (last_av96 ~= current_av96) then mstring1 = "Found changed Av value!" last_av96 = current_av96 end end mstring2 = "" if ((get_zoom() ~= last_zoom) and (foc_mode > 0)) then mstring2 = "Found changed zoom position!" end if (((mstring1 ~= "") or (mstring2 ~= "")) and (get_movie_status() ~= 4)) then cls() if (mstring1 ~= "") then print(mstring1) end if (mstring2 ~= "") then print(mstring2) end print("The fixed focus settings will") print("be actualized in 2 sec:") sleep(2000) cls() set_fixfoc() --Force a new fixed focus setting after a changed zoom position with forced MF or changed Av value at hyperfocal mode end usb = get_usb_power() --Wait for an USB impulse if usb > 0 then --True after a recognized USB-impulse if shoot_mode == 0 then --True at activated photo shooting take_photo() elseif shoot_mode == 1 then --True at activated video recording start_stop_video() else --True at activated AUTO for Shoot-Mode if (usb >= usb_time_limit) and (get_movie_status() <= 1) then --True at stopped/paused video recording and USB-impulse >= usb_time_limit start_stop_video() elseif get_movie_status() == 4 then --True while currently running video recording start_stop_video() else take_photo() end end end until is_pressed("menu") --Abort script after pressing key MENU restore() --Run this subfunction to reset the cam to the settings before script start else --True if table "err" is not empty cls() for i=1, #err do print(err[i]) end play_sound(6) --Play error sound sleep(3000) console_redraw() end