@title CAMremote-SDM
rem by VP-Systems
rem 12-11-2011

m=0
z=0
f=0
set_zoom_speed 10
set_zoom 0
sync_off

rem goto "cr_fast"

rem CAMremote-1/2 (4-pin USB connector). Control Method: USB/CHDK
:cr_normal
print "CR: USB/CHDK"
while 1
  do
    c = get_usb_power
  until c>0
  print c
  if c>65 then gosub "pwroff"
  if c>58 then gosub "stop_video"
  if c>52 then gosub "tvdn"
  if c>46 then gosub "tvup"
  if c>40 then gosub "avdn"
  if c>33 then gosub "avup"
  if c>27 then gosub "rec_video"
  if c>20 then gosub "zout"
  if c>13 then gosub "zin"
  if c>8 then gosub "focusoff"
  if c>5 then gosub "focus"
  if c>0 then gosub "shoot"
wend
end

rem CAMremote-2 (Mini USB connector).  Control Method: USB/CHDK+
:cr_fast
print "CR: USB/CHDK+"
while 1
  do
    c = get_usb_power
  until c>0
  if c>41 then gosub "pwroff"
  if c>21 then gosub "lensoff"
  if c>19 then gosub "stop_video"
  if c>17 then gosub "tvdn"
  if c>15 then gosub "tvup"
  if c>13 then gosub "avdn"
  if c>11 then gosub "avup"
  if c>8 then gosub "rec_video"
  if c>7 then gosub "zout"
  if c>5 then gosub "zin"
  if c>3 then gosub "focusoff"
  if c>1 then gosub "focus"
  if c>0 then gosub "shoot"
wend
end

:shoot
  if m=1 then gosub "stop_video"
  print "shoot:";c
  c=0
  press "shoot_full"
  sleep 1500
  release "shoot_full"
  release "shoot_half"
  return

:rec_video
  if m=1 then return
  movie_mode
  sleep 2000
  print "rec_video:";c
  c=0
  press "shoot_full"
  sleep 500
  release "shoot_full"
  m=1
  c=0
  return

:stop_video
  if m=0 then return
  print "stop_video:";c
  c=0
  press "shoot_full"
  sleep 500
  release "shoot_full"
  m=0
  sleep 1000
  record_mode
  sleep 1000
  return

:focus
  print "focus:";c
  c=0
  press "shoot_half"
  f=1
  sleep_for 500
  return

:focusoff
  print "release:";c
  c=0
  release "shoot_half"
  sleep_for 500
  return

:zin
  if f=1 then release "shoot_half"
  if z<9 then z=z+1
  print "zoomin:";c
  c=0
  set_zoom_to_step z
rem set_zoom z
  sleep_for 1000
rem  release "shoot_half"
  return

:zout
  if f=1 then release "shoot_half"
  if z<>0 then z=z-1
  print "zoomout:";c
  c=0
  set_zoom_to_step z
rem set_zoom z
  sleep_for 1000
rem  release "shoot_half"
  return

:avup
  print "Av+ Skip:";c
  c=0
rem  set_av_rel 0+1
  return

:avdn
  print "Av- Skip:";c
  c=0
rem  set_av_rel 0-1
  return

:tvup
  print "Tv+ Skip:";c
  c=0
rem  set_tv_rel 0+1
  return

:tvdn
  print "Tv- Skip:";c
  c=0
rem  set_tv_rel 0-1
  return

:lensoff
  print "lensoff not supported"
  goto "pwroff"

:pwroff
  print "poweroff"
  c=0
  sleep 500
  shut_down

return
