--[[ ******************************************************** Script for USB RC-Remote Aurico RC-CHDK2 Special version using only one RC-channel for shoot&zoom Requires CHDK 1.3 v3442 or later for USB high speed mode Version: 1.01 Date: 2016/08/27 Licence: GPL Author: Werner_O THX to msl ******************************************************** @title RC-CHDK1 v1.01 @chdk_version 1.3 @param a Enable AutoMode USB-Port @default a 1 @range a 0 1 @param t Time Limit for Zoom-Out (100ms) @default t 10 @range t 3 20 @param m Zoom Mode @default m 0 @values m STEP+-1 TIME_ms @param z Zoom Time (ms) @default z 10 @range z 1 500 @param c Console Messages @default c 1 @values c HIDE SHOW @param l USB Time Limit (10ms) @default l 13 @range l 10 40 @param x Start in USB Test-Mode @default x 0 @range x 0 1 ]] --Predefinition of the used variables: AutoMode = a TimeLimit = l InOutTime = t * 100 ZoomMode = m if (c == 1) or (x == 1) then ShowConsole = 1 set_console_layout(0, 0, 26, 8) else ShowConsole = c end ZoomTime = z TestMode = x messages = {} zoom_step = get_zoom() MaxZoom = get_zoom_steps() - 1 --amount of available zoom steps current_tick = get_tick_count() --will be changed later last_tick = get_tick_count() --will be changed later current_tick2 = get_tick_count() --will be changed later last_tick2 = get_tick_count() --will be changed later --Subfunction restore() used at script interrupt: function restore() messages = {} table.insert(messages, "Aborting Script:") if AutoMode == 1 then set_config_value(121,0) --Disable USB remote table.insert(messages, "USB remote disabled") end if high_speed then --Disable USB high speed mode if automatically 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 table.insert(messages, "High speed mode disabled") end if ShowConsole == 1 then cls() table.insert(messages, "Finished!") print_messages() sleep(3000) console_redraw() end end --Subfunction wait_message(): function wait_message() if ShowConsole == 1 then print("Waiting for USB Impulse...") print("(Press MENU to EXIT)") last_tick = get_tick_count() end end --Subfunction zoom_message(): function zoom_message() if ShowConsole == 1 then zoom_step = get_zoom() print(string.format("#Zoom-Step: %d of %d", zoom_step, MaxZoom)) end end --Subfunction print_message(): function print_message() if ShowConsole == 1 then print(message) end end --Subfunction print_messages(): function print_messages() if ShowConsole == 1 then for i=1, #messages do print(messages[i]) end end end --Subfunction command_shoot(): function command_shoot() count = get_exp_count() shoot() repeat sleep(10) until get_exp_count() ~= count --wait until camera has stored the picture if ShowConsole == 1 then cls() print("Shooting successful") wait_message() end end --Subfunction zoomin_time(): function zoomin_time() if ShowConsole == 1 then cls() if get_zoom() < MaxZoom then --is current zoom position lower than max.? print(string.format("ZOOM-IN for %03d ms", ZoomTime)) press("zoom_in") sleep(ZoomTime) release("zoom_in") zoom_message() else zoom_message() print("MAX. ZOOM POSITION!") end wait_message() else if get_zoom() < MaxZoom then press("zoom_in") sleep(ZoomTime) release("zoom_in") end end end --Subfunction zoomout_time(): function zoomout_time() if ShowConsole == 1 then cls() if get_zoom() > 0 then --is current zoom position higher than min.? print(string.format("ZOOM-OUT for %03d ms", ZoomTime)) press("zoom_out") sleep(ZoomTime) release("zoom_out") zoom_message() else zoom_message() print("MIN. ZOOM POSITION!") end wait_message() else if get_zoom() > 0 then press("zoom_out") sleep(ZoomTime) release("zoom_out") end end end --Subfunction zoomin_step(): function zoomin_step() current_zoom = get_zoom() next_zoom = current_zoom if ShowConsole == 1 then cls() if get_zoom() < MaxZoom then --is current zoom position lower than max.? repeat next_zoom = (next_zoom + 1) print("ZOOM-IN +1 STEP") set_zoom(next_zoom) sleep(1000) until (get_zoom() > current_zoom) zoom_message() else zoom_message() print("MAX. ZOOM POSITION!") end wait_message() else if get_zoom() < MaxZoom then repeat next_zoom = (next_zoom + 1) set_zoom(next_zoom) sleep(1000) until (get_zoom() > current_zoom) end end end --Subfunction zoomout_step(): function zoomout_step() current_zoom = get_zoom() next_zoom = current_zoom if ShowConsole == 1 then cls() if get_zoom() > 0 then --is current zoom position higher than min.? repeat next_zoom = (next_zoom - 1) print("ZOOM-OUT -1 STEP") set_zoom(next_zoom) sleep(1000) until (get_zoom() < current_zoom) zoom_message() else zoom_message() print("MIN. ZOOM POSITION!") end wait_message() else if get_zoom() > 0 then repeat next_zoom = (next_zoom - 1) set_zoom(next_zoom) sleep(1000) until (get_zoom() < current_zoom) end end end --Start main script: --Enable Shooting Mode when started in Playback Mode if get_mode() == false then --True at found playback mode message = "Activate Record Mode..." print_message() set_record(1) sleep(1000) while get_mode() == false do sleep(10) end if ShowConsole == 1 then message = "Record Mode activated!" print_message() sleep(3000) cls() end end message = "Script started - State:" print_message() if AutoMode == 1 then set_config_value(121,1) --enable USB remote message = "USB remote: Enabled" print_message() end high_speed = false --Enable USB high speed mode if possible, available since CHDK-DE 1.3 v3442 --Command for CHDK 1.3 >= v3791 or CHDK 1.4/1.5 (boolean): if type(set_remote_timing) == "function" then high_speed = set_remote_timing(1000) --Command for CHDK 1.3 >= v3585 to < v3791 (boolean): elseif type(enable_remote_hp_timer) == "function" then high_speed = enable_remote_hp_timer(1000) --Command for CHDK 1.3 >= v3442 to < v3585 (number): elseif type(enable_highspeed_usb) == "function" then enable_highspeed_usb(1000) high_speed = true end if high_speed then TimeLimit = l * 10 message = "High speed mode: Enabled" print_message() else message = "High speed mode: n/a" print_message() end if TestMode == 1 then print("USB Test Mode: Enabled") sleep(3000) console_redraw() sleep(3000) cls() print("USB Test Mode:") wait_message() else if ShowConsole == 1 then sleep(3000) console_redraw() sleep(3000) cls() wait_message() end end --Start main loop: repeat current_tick = get_tick_count() if ((current_tick - last_tick) >= 2900) and (ShowConsole == 1) then --redraw console after 2.9 sec if console messages are activated last_tick = current_tick console_redraw() end u = get_usb_power() if u > 0 then if TestMode == 1 then --true in USB test mode cls() print("USB Impulse recognized:") if high_speed then print(string.format("Impulse Length = %d ms", u)) else print(string.format("Impulse Length = %d0 ms", u)) end print("**************************") print("USB Test Mode:") wait_message() else --true in shooting mode if u < TimeLimit then --true if USB impulse is shorter than TimeLimit command_shoot() else --true if USB impulse is longer than TimeLimit last_tick2 = get_tick_count() if ShowConsole == 1 then cls() print("Wait for ZoomOut Impulse..") end repeat current_tick2 = get_tick_count() v = get_usb_power() until (v >= TimeLimit) or ((current_tick2 - last_tick2) >= InOutTime) if (v >= TimeLimit) then if ZoomMode == 1 then zoomout_time() else zoomout_step() end else if ZoomMode == 1 then zoomin_time() else zoomin_step() end end end end end until is_pressed("menu") restore()