Subtitle : Getting the "set_focus()" command in CHDK scripts, or the "Override Subject Distance" menu item in the Enhanced Photo Operations menu, to work.
set_aflock()
- set_aflock(1) causes the Canon firmware to stop focussing when shooting
- does an initial focus measurement and sets focus at that value when called
- set_aflock(0) restores camera automatic focussing.
- seems to works on almost all cameras
- using set_aflock() may be necessary on some camera for set_focus() to work (elph310). On other cameras, it has no effect on whether set_focus() works.
- on some cameras, the set_aflock() command must be issued after a "half-press" focus completes and before the half press is released
- if you call set_aflock() and then set_focus() (in a mode on your camera where that works) then the focus for all subsequent shots will stay at the value specified in set_focus(). If set_aflock() has not been called then set_focus() will only apply to the next shot - after that the camera will revery to auto focus.
set_focus()
- script command that may or may not actually set the focus setting (in mm) the next time the camera shoots.
- on some cameras, set_focus() will only work if the camera is in Canon AFL mode (ex: A1200)
- on some cameras, set_focus() will only work if the camera is in Canon MF mode (ex: SX50HS)
- on some cameras, set_focus() will work when set_aflock(1) has been called (ex: elph310)
- on some cameras, set_focus() will only work when the camera is in P mode (or at least not in AUTO)
- on some cameras, set_focus works every time regardless of mode (ex: G10, SD940)
- Notes :
- Canon AFL mode is typically achieved via simulated button presses using click() - see your camera manual for the correct sequence. May require holding a "half press" while another key is clicked.
- Canon MF mode is may be achieved via simulated button presses, post_levent_for_npt call, and/or call_event_proc calls.
- When in Canon MF mode, focus will be set immediately when a set_focus() command is issued. Otherwise the focus will not take effect until after the "half-pres" part of the shooting sequence.
Forum Links
http://chdk.setepontos.com/index.php?topic=9533.0
http://chdk.setepontos.com/index.php?topic=8016.msg94251#msg94251
http://chdk.setepontos.com/index.php?topic=6672.msg75166#msg75166
Test Script
--[[
@title MF Test Suite
@param f MF Mode
@default f 0
@values f None AFlock AFL MF1 MF2 MF3
--]]
set_console_layout(1 ,1, 45, 14 )
print( "f-tester v1/2")
sleep(1000)
if ( get_mode() == false ) then
set_record(1)
while ( get_mode() == false ) do sleep(100) end
end
if( f==1) then -- set_aflock()
print("aflock mode")
set_aflock(1)
end
if( f==2) then -- enable Canon AFL lock focus via key presses
print("AFL mode")
local count = 0
local timeout = false
press("shoot_half")
repeat
sleep(50)
count = count + 1
if (count > 40 ) then timeout = true end
until (get_focus_ok() == 1 ) or (timeout == true)
if (timeout == true) then print("Warning : focus attempt timed out")
else click("left")
end
sleep(100)
release("shoot_half")
end
if( f==3) then -- MF1 lock focus via key presses
print("MF1 mode")
click("up")
end
if( f==4) then -- MF2 lock focus using levent for key press
print("MF2 mode")
post_levent_for_npt("PressSw1AndMF")
end
if( f==5) then -- MF3 lock focus using event_proc for key press
print("MF3 mode")
call_event_proc("SS.Create")
call_event_proc("SS.MFOn")
end
sleep(1000)
print("Focus state=".. get_focus_mode())
for focus=100,300,100 do
set_focus(focus)
sleep(2000)
press("shoot_half")
sleep(1000)
before=get_focus()
click("shoot_full")
release("shoot_half")
after=get_focus()
if ((focus-after)/5 == 0) then fstr=" : okay" else fstr=" : fault" end
print("Set:"..focus," Before:"..before," After:"..after..fstr)
sleep(2000)
press("shoot_half")
sleep(1000)
before=get_focus()
click("shoot_full")
release("shoot_half")
after=get_focus()
if ((focus-after)/5 == 0) then fstr=" : locked" else fstr=" : unlocked" end
print(" "..focus," Before:"..before," After:"..after..fstr)
sleep(1000)
end