Commit 1e70943d authored by alex@thinkpad's avatar alex@thinkpad
Browse files

Lua: exposed lens_info.focus_pos as lens.focus_pos and added an API test

--HG--
branch : focus
parent 5bb56350473f
......@@ -26,6 +26,13 @@ static int luaCB_lens_index(lua_State * L)
/// Get the current focus distance (in mm)
// @tfield int focus_distance readonly
else if(!strcmp(key, "focus_distance")) lua_pushinteger(L, lens_info.focus_dist * 10);
/// Get the raw relative focus motor position, in steps.
/// This counter is 0 at camera startup, its range depend on the lens,
/// and is updated only when the focus motor moves. It will lose track
/// of the lens position during manual focus, unless you use a focus-by-wire lens.
/// Details: http://www.magiclantern.fm/forum/index.php?topic=4997
// @tfield int focus_distance readonly
else if(!strcmp(key, "focus_pos")) lua_pushinteger(L, lens_info.focus_pos);
/// Get the hyperfocal distance of the lens (in mm)
// @tfield int hyperfocal readonly
else if(!strcmp(key, "hyperfocal")) lua_pushinteger(L, lens_info.hyperfocal);
......
......@@ -701,6 +701,7 @@ function test_lens_focus()
printf("Focusing backward...\n")
while lens.focus(-1,3,true) do end
printf("Focus distance: %s\n", lens.focus_distance)
printf("Focus motor position: %d\n", lens.focus_pos)
msleep(500)
......@@ -708,13 +709,20 @@ function test_lens_focus()
for j,wait in pairs{true,false} do
printf("Focusing forward with step size %d, wait=%s...\n", step, wait)
local steps_front = 0
local focus_pos_0 = lens.focus_pos
while lens.focus(1,step,true) do
printf(".")
steps_front = steps_front + 1
end
-- note: focus distance and position may not be reported right away
msleep(500)
printf("\n")
printf("Focus distance: %s\n", lens.focus_distance)
printf("Focus motor position: %d\n", lens.focus_pos)
local focus_pos_1 = lens.focus_pos
msleep(500)
printf("Focusing backward with step size %d, wait=%s...\n", step, wait)
......@@ -723,15 +731,26 @@ function test_lens_focus()
printf(".")
steps_back = steps_back + 1
end
msleep(500)
printf("\n")
printf("Focus distance: %s\n", lens.focus_distance)
printf("Focus motor position: %d\n", lens.focus_pos)
local focus_pos_2 = lens.focus_pos
msleep(500)
local motor_steps_front = math.abs(focus_pos_1 - focus_pos_0)
local motor_steps_back = math.abs(focus_pos_2 - focus_pos_1)
local motor_steps_lost = math.abs(focus_pos_2 - focus_pos_0)
printf("Focus range: %s steps forward, %s steps backward. \n", steps_front, steps_back)
printf("Motor steps: %s forward, %s backward, %s lost. \n", motor_steps_front, motor_steps_back, motor_steps_lost)
msleep(500)
end
end
printf("Focus test completed.\n")
printf("\nFocus test completed.\n")
else
printf("Focus test skipped.\n")
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment