Skip to content

Instantly share code, notes, and snippets.

@jean80it
Created June 12, 2013 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jean80it/5767968 to your computer and use it in GitHub Desktop.
Save jean80it/5767968 to your computer and use it in GitHub Desktop.
A CHDK DOF-stack script modified to take a given amount of shots. Runs on an A810 HD. See comments for more.
@title DOF stackmaker
rem original script at http://chdk.wikia.com/wiki/UBASIC/Scripts:_macro_DOFstacker
rem slightly modified in order to take a given amounts of shots on an A810 HD
@param a closeStart dist (mm)
@default a 0
@param b closeStart dist (cm)
@default b 0
@param c closeStart dist (m)
@default c 0
@param i advance
@default i 10
let a=1000*c+10*b+a
if a<0 then let a=0
rem Zero offset for each model (or each invididual) cam may differ from 62
rem let a=a+62
@param d Show helptext? (1=yes)
@default d 1
@param e Snap HDR sets? (1=yes)
@default e 0
@param f ExpComp limit (1 or 2)
@default f 2
rem each IF statement may contain only a single relational operator
if e<0 then let e=0
if e>1 then let e=0
if f<1 then let f=1
if f>2 then let f=2
@param g Number of focal steps
@default g 0
@param h Number focal steps (x10)
@default h 2
get_zoom z
if z>0 then gosub "nozoom"
let x=10*h+g
if x*i+a>1199 then gosub "crazysteps"
if d=1 then gosub "instruct"
if e=1 then gosub "chkslider"
gosub "countdown"
rem if e=1 then click "erase"
rem NO! Make this a precondition/requirement! We cannot guess cursor position;
rem a single, or double click may be required (depends on ModeDial position)
for y=0 to x
set_focus y*i+a
rem if e=1 then gosub "hdrset" else gosub "regshoot"
rem workaround "ELSE" bug
if e=1 then gosub "hdrset"
if e=0 then gosub "regshoot"
next y
:theend
end
:instruct
print "ensure MANUAL FOCUS"
print "selected before using"
print "this script or CAM MAY"
print "CRASH (powerdown)"
print "paused --[ click SET ]--"
wait_click
print "RECOMMENDED SETUP:"
print "ModeDial to Av (f5.6)"
print "set REVIEW off"
print "set flash OFF"
print "paused --[ click SET ]--"
wait_click
print "ALSO RECOMMENDED:"
print "Move away from cam or"
print "sit ENTIRELY still "
print "during the session..."
print "paused --[ click SET ]--"
wait_click
print "...because the TINIEST"
print "vibration will produce"
print "blur / misalignment"
print "in your series of shots"
print "paused --[ click SET ]--"
wait_click
return
:chkslider
rem ExpBracketing option has been selected
print "ENSURE ExpComp slider"
print "is visible onscreen"
print "IF IT IS NOT, INTERRUPT"
print "SCRIPT NOW and set it"
print "paused --[ click SET ]--"
wait_click
return
:countdown
for n=1 to 5
print "starting in:", 6-n,"secs..."
sleep 940
next n
for n=1 to 5
print " "
next n
return
:regshoot
print "shooting..."
print "."
shoot
return
:hdrset
for n=1 to 3
if n>1 then goto "noinit"
:ecinit
for p=1 to 12
click "left"
sleep 100
next p
:noinit
rem each IF statement may contain only a single relational operator
rem also need to workaround the uBasic "ELSE" bug
rem if n=1 & f=1 then gosub "triple"
if n=1 then goto "checkstep"
if n>1 then goto "nocheckstep"
:checkstep
if f=1 then let q=1
if f=2 then let q=0
if q=1 then gosub "triple"
:nocheckstep
if n>1 then gosub "triple"
shoot
next n
return
:triple
let v=f*3
for s=1 to v
click "right"
sleep 100
next s
return
:nozoom
rem Focus nearer than 5cm requires widest zoom (7.3mm focal length)
rem (I chose not to, but code could override using set_zoom 0)
print "***TO USE THIS SCRIPT***"
print "You MUST set camera"
print "to widest zoom"
print "then RESTART script."
wait_click
goto "theend"
return
:crazysteps
if x>11359 then gosub "infcrazy"
if x<11359 then gosub "hypcrazy"
return
:hypcrazy
rem 1199 is 1157+62 (1557mm is hyperfocal dist for f5.6 at 7.3mm focal length)
rem NOTE: user may have selected a different aperture
print "selected Start value is"
print "beyond hyperfocal dist!"
print "Most frames will have"
print "same (redundant) focus!"
print "paused --[ click SET ]--"
wait_click
return
:infcrazy
rem 11359 may not be a constant across various cameras; it is the
rem INF boundry get_focus value ***for 7.3mm focal length only*** on my A620
print "these Start+Step values"
print "will result in numerous"
print "identical / redundant"
print "INFINITY-focused frames"
print "paused --[ click SET ]--"
wait_click
return
@waterwingz
Copy link

You seem to be working around the limitations of CHDK's uBASIC quite a bit here.

You might want to consider using Lua - a much more capable language that is also supported by CHDK.

@jean80it
Copy link
Author

Thanks for your suggestion. I actually found the original code somewhere on the web and just modified tiny bits to fit my needs in a bigger project, in which focus stack is just the beginning.
Details here : http://www.stareat.it/sp.aspx?g=3ce7bc36fb334b8d85e6900b0bdf11c3
and here: http://www.stareat.it/sp.aspx?g=c8cc90e0dde845599e28aae7639fde6e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment