I was curious to see how well this would actually work. The results were better than I expected using my A1200 but still nothing I would consider a precision measurement.
--[[
@title Distance Meter
--]]
function update_display(msg)
draw_string(xpos,ypos,string.sub(msg, (string.len(msg)/2)-6, (string.len(msg)/2)+5), white, blue, text_size)
end
transparent = 256
black = 257
white = 258
red = 259
green = 263
blue = 266
yellow = 271
xpos = 50
ypos = 50
text_size = 2
strmsg = " start "
if ( get_mode() == false ) then -- switch to shooting mode on start up
sleep(1000)
set_record(1)
while ( get_mode() == false) do sleep(100) end
end
sleep(500)
repeat
press("shoot_half")
count = 0
repeat
update_display(strmsg)
sleep(100)
count = count + 1
if (count > 40 ) then timeout = true end
until (get_shooting() == true ) or (timeout == true)
release("shoot_half")
if ( timeout == true ) then
strmsg = " timeout "
else
sd = get_focus()
if ( sd == -1 ) then
strmsg = " infinity "
else
strmsg = " "..get_focus() .." mm "
end
end
for i=0, 10, 1 do
update_display(strmsg)
sleep(100)
end
until false