--[[ ******************************************************** Script for USB RC-Remote Aurico RC-CHDK2 Requires CHDK 1.3 v3442 or later for USB high speed mode Version: 1.09 Date: 2015/02/26 Licence: GPL Author: Werner_O THX to msl ******************************************************** @title Aurico RC-CHDK2 v1.09 @chdk_version 1.3 @param a Enable AutoMode USB-Port @default a 1 @range a 0 1 @param t Zoom Time (10ms) @default t 2 @range t 1 50 @param s Disable Shoot @default s 0 @range s 0 1 @param h Halfshoot instead Video @default h 0 @range h 0 1 @param v Disable Video/Halfshoot @default v 0 @range v 0 1 @param z Disable Zoom @default z 0 @range z 0 1 @param b USB Time Limit 1 (10ms) @default b 13 @range b 5 15 @param c USB Time Limit 2 (10ms) @default c 23 @range c 10 24 @param d USB Time Limit 3 (10ms) @default d 33 @range d 15 40 @param x Start in USB Test-Mode @default x 0 @range x 0 1 @param p Result Report Time (s) @default p 3 @range p 1 5 ]] --Define console layout: set_console_layout(0, 0, 25, 7) --Definitions variables: SleepTime = p * 1000 ZoomTime = t * 10 AutoMode = a Limit_1 = b Limit_2 = c Limit_3 = d HalfShoot = h HalfShootState = 0 TestMode = x ShootLock = s VideoHalfshootLock = v VideoState = 0 ZoomLock = z HighSpeedMode1 = 0 HighSpeedMode2 = false HighSpeedMode3 = false MaxZoom = get_zoom_steps() - 1 --amount of available zoom steps Ready = false --Definition subfunction restore() used at script interrupt: function restore() if AutoMode == 1 then set_config_value(121,0) --Disable USB remote print("USB remote disabled") end if HighSpeedMode1 > 0 then HighSpeedMode1 = enable_highspeed_usb(0) --Disable USB high precision timer using 1st command print("High speed mode disabled") elseif HighSpeedMode2 == true then HighSpeedMode2 = enable_remote_hp_timer(0) --Disable USB high precision timer using 2nd command print("High speed mode disabled") elseif HighSpeedMode3 == true then HighSpeedMode3 = set_remote_timing(0) --Disable USB high precision timer using 3rd command print("High speed mode disabled") end sleep(3000) console_redraw() end --Definition subfunction command_shoot(): function command_shoot() if ShootLock == 0 then --true if shoot function is not disabled if HalfShootState == 0 then --true if halfshoot is deactived count = get_exp_count() shoot() repeat sleep(10) until get_exp_count() ~= count --wait until camera has stored the picture print("Shooting successful:") print("Waiting for USB Impulse") print("(Press MENU to EXIT)") else --true if halfshoot is actived count = get_exp_count() press("shoot_full_only") repeat sleep(10) until get_exp_count() ~= count --wait until camera has stored the picture release("shoot_full_only") end else cls() print("(Shoot is disabled)") end end --Definition subfunction command_video() (start/stop video): function command_video() if VideoHalfshootLock == 0 then --true if video/halfshoot function is not disabled if get_video_button() == 1 then --has the camera a separate video button? click("video") --start/stop video if VideoState == 0 then --true if no video recording active cls() print("Video Record started") VideoState = 1 else cls() print("Video Record stopped") VideoState = 0 end else cls() print("No videobutton available") end else cls() print("(Video is disabled)") end end --Definition subfunction command_halfshoot() (enable/disable halfshoot): function command_halfshoot() if VideoHalfshootLock == 0 then --true if video/halfshoot function is not disabled if HalfShootState == 0 then --true if no halfshoot active press("shoot_half") repeat sleep(10) until get_shooting() == true --wait until camera is ready HalfShootState = 1 else release "shoot_half" HalfShootState = 0 end else cls() print("(Halfshoot is disabled)") end end --Definition subfunction command_zoomin(): function command_zoomin() if ZoomLock == 0 then --true if zoom function is not disabled if HalfShootState == 1 then --release halfshoot if currently aktiv release "shoot_half" HalfShootState = 0 end if get_zoom() < MaxZoom then --is zoom position lower than max.? press("zoom_in") sleep(ZoomTime) release("zoom_in") else cls() print("Max. zoom position!") end else cls() print("(Zoom is disabled)") end end --Definition subfunction command_zoomout(): function command_zoomout() if ZoomLock == 0 then --true if zoom function is not disabled if HalfShootState == 1 then --release halfshoot if currently aktiv release "shoot_half" HalfShootState = 0 end if get_zoom() > 0 then --is zoom position higher than min.? press("zoom_out") sleep(ZoomTime) release("zoom_out") else cls() print("Min. zoom position!") end else cls() print("(Zoom is disabled)") end end --Is either shoot and/or video activated? Causes script abort if no picture or video record is possible if ShootLock == 1 then if VideoHalfshootLock == 1 or HalfShoot == 1 then Ready = false end else Ready = true end if Ready == true then if AutoMode == 1 then set_config_value(121,1) --enables USB remote end --Enable USB-High-Speed-Mode if possible: 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 if chdk_version >= 130 then if ((chdk_version < 140) and (chdk_build >= 3442) and (chdk_build < 3585)) then HighSpeedMode1 = enable_highspeed_usb(1000) --Enable USB high precision timer with 1st command at found CHDK 1.3 revision >= 3442 and < 3585 --Change values for Limit 1 to 3 if USB High-Speed-Mode is enabled Limit_1 = b * 10 Limit_2 = c * 10 Limit_3 = d * 10 elseif ((chdk_version < 140) and (chdk_build >= 3585) and (chdk_build < 3791)) then HighSpeedMode2 = enable_remote_hp_timer(1000) --Enable USB high precision timer with 2nd command at found CHDK 1.3 revision >= 3585 and < 3791 --Change values for Limit 1 to 3 if USB High-Speed-Mode is enabled Limit_1 = b * 10 Limit_2 = c * 10 Limit_3 = d * 10 elseif ((chdk_version < 140) and (chdk_build >= 3791)) or (chdk_version >= 140) then HighSpeedMode3 = set_remote_timing(1000) --Enable USB high precision timer with 3rd command at found CHDK 1.3 revision >= 3791 or CHDK 1.4 --Change values for Limit 1 to 3 if USB High-Speed-Mode is enabled Limit_1 = b * 10 Limit_2 = c * 10 Limit_3 = d * 10 end end print("Script started - State:") --start messages at script start if TestMode == 1 then --messages for test mode if AutoMode == 1 then print("USB remote: Enabled") end if ((HighSpeedMode1 > 0) or (HighSpeedMode2 == true) or (HighSpeedMode3 == true)) then print("High speed mode: Enabled") else print("High speed mode: Disabled") end print("USB Test Mode: Enabled") print("Waiting for USB impulse...") print("(Press MENU to EXIT)") else --messages shown at script start: if AutoMode == 1 then print("USB remote: Enabled") end if ((HighSpeedMode1 > 0) or (HighSpeedMode2 == true) or (HighSpeedMode3 == true)) then print("High speed mode: Enabled") else print("High speed mode: n/a") end if ShootLock == 0 then print("Shoot: Enabled") else print("Shoot: Disabled") end if HalfShoot == 0 then print("Video: Enabled") print("Halfshoot: Disabled") else print("Video: Disabled") print("Halfshoot: Enabled") end if ZoomLock == 0 then print("Zoom: Enabled") else print("Zoom: Disabled") end sleep(3000) for i=1, 2 do console_redraw() sleep(3000) end cls() print("Waiting for USB Impulse") print("(Press MENU to EXIT)") end repeat u = get_usb_power() if u > 0 then if TestMode == 1 then --true in USB test mode cls() print("USB Impulse recognized:") if HighSpeedMode == true then print(string.format("Impulse Length = %d ms", u)) else print(string.format("Impulse Length = %d0 ms", u)) end print(string.format("(Script paused for %d sec)", p)) sleep(SleepTime) --pause to display result cls() print("USB Test Mode:") print("Waiting for USB Impulse") print("(Press MENU to EXIT)") else --true in shooting mode if u < Limit_1 then --true if USB impulse is shorter than Limit_1 command_shoot() elseif u < Limit_2 then --true if USB impulse is shorter than Limit_2 if HalfShoot == 0 then --true if paramater "halfshoot instead video" is disabled command_video() else command_halfshoot() end elseif u < Limit_3 then --true if USB impulse is shorter than Limit_3 command_zoomin() else --true if USB impulse is longer than Limit_3 command_zoomout() end end end until is_pressed("menu") cls() if AutoMode == 1 then set_config_value(121,0) --disables USB remote print("USB remote disabled") end else cls() print("Neither Shoot nor Video") print("are enabled currently.") print("Please reconfigure the") print("script settings in CHDK!") end restore()