Commit 5b323bba authored by alex@thinkpad's avatar alex@thinkpad
Browse files

Lua: added some new APIs to the "lv" module: lv.paused, lv.running, lv.zoom...

Lua: added some new APIs to the "lv" module: lv.paused, lv.running, lv.zoom get/set, lv.wait(num_frames)

--HG--
branch : lua_fix
parent eed82e3cc92c
......@@ -29,9 +29,18 @@ struct lvinfo_item_entry
static int luaCB_lv_index(lua_State * L)
{
LUA_PARAM_STRING_OPTIONAL(key, 2, "");
/// Whether or not LV is running.
/// Whether or not LV is enabled (may be running or paused).
// @tfield bool enabled
if(!strcmp(key, "enabled")) lua_pushboolean(L, lv);
if(!strcmp(key, "enabled")) lua_pushboolean(L, lv || LV_PAUSED);
/// Whether or not LV is paused (shutter open, but sensor inactive; useful for powersaving).
// @tfield bool paused
else if(!strcmp(key, "paused")) lua_pushboolean(L, LV_PAUSED);
/// Whether or not LV is running (that is, enabled and not paused).
// @tfield bool running
else if(!strcmp(key, "running")) lua_pushboolean(L, lv);
/// Get/set LiveView zoom factor (1, 5, 10).
// @tfield bool zoom
else if(!strcmp(key, "zoom")) lua_pushinteger(L, lv_dispsize);
else lua_rawget(L, 1);
return 1;
}
......@@ -45,6 +54,22 @@ static int luaCB_lv_newindex(lua_State * L)
if(value && !lv && !LV_PAUSED) force_liveview();
else if(lv) close_liveview();
}
else if(!strcmp(key, "zoom"))
{
LUA_PARAM_INT(value, 3);
if (!lv)
{
return luaL_error(L, "LiveView must be enabled");
}
set_lv_zoom(value);
if (lv_dispsize != value)
{
return luaL_error(L, "Could not set LiveView zoom");
}
}
else
{
lua_rawset(L, 1);
......@@ -92,6 +117,27 @@ static int luaCB_lv_stop(lua_State * L)
return 0;
}
/***
Wait for N LiveView frames in LiveView.
@tparam int num_frames
@function wait
*/
static int luaCB_lv_wait(lua_State * L)
{
LUA_PARAM_INT(num_frames, 1);
int ok = wait_lv_frames(num_frames);
if (!ok)
{
return luaL_error(L,
lv ? "lv.wait failed (timeout?)"
: "lv.wait failed (LV stopped)"
);
}
return 0;
}
static LVINFO_UPDATE_FUNC(lua_lvinfo_update)
{
struct lvinfo_item_entry * entry = (struct lvinfo_item_entry *)item;
......@@ -321,6 +367,9 @@ static int luaCB_lvinfo_newindex(lua_State * L)
static const char * lua_lv_fields[] =
{
"enabled",
"paused",
"running",
"zoom",
NULL
};
......@@ -330,6 +379,7 @@ static const luaL_Reg lvlib[] =
{ "pause", luaCB_lv_pause },
{ "resume", luaCB_lv_resume },
{ "stop", luaCB_lv_stop },
{ "wait", luaCB_lv_wait },
{ "info", luaCB_lv_info },
{ NULL, NULL }
};
......
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