Commit 7ad58811 authored by alex@thinkpad's avatar alex@thinkpad
Browse files

Lua: initial sketch for camera.gui (Canon GUI modes)

Moved display.idle to camera.gui.idle; removed camera.state

--HG--
branch : lua_fix
parent 1a55233d4b5c
......@@ -14,6 +14,7 @@
#include <bmp.h>
#include <imath.h>
#include <math.h>
#include <zebra.h>
#include "lua_common.h"
......@@ -42,6 +43,8 @@ static int luaCB_fec_index(lua_State * L);
static int luaCB_fec_newindex(lua_State * L);
static int luaCB_fec_tostring(lua_State * L);
static int luaCB_gui_index(lua_State * L);
static int luaCB_gui_newindex(lua_State * L);
static const char * lua_camera_shutter_fields[] =
{
......@@ -85,6 +88,17 @@ static const char * lua_camera_ec_fields[] =
NULL
};
static const char * lua_camera_gui_fields[] =
{
"menu",
"play",
"play_photo",
"play_movie",
"qr",
"idle",
NULL
};
static int luaCB_camera_index(lua_State * L)
{
LUA_PARAM_STRING_OPTIONAL(key, 2, "");
......@@ -214,11 +228,22 @@ static int luaCB_camera_index(lua_State * L)
/// TODO: Celsius.
// @tfield int temperature readonly
else if(!strcmp(key, "temperature")) lua_pushinteger(L, efic_temp);
/// Get the current Canon GUI state of the camera (PLAY, QR etc; see gui-common.h).
///
/// TODO: add constants; expose functions to change GUI mode.
// @tfield int state readonly
else if(!strcmp(key, "state")) lua_pushinteger(L, gui_state);
/// Gets a @{gui} object that controls Canon GUI state (PLAY, MENU, QR, various dialogs)
// @tfield gui gui
else if(!strcmp(key, "gui"))
{
lua_newtable(L);
lua_newtable(L);
lua_pushcfunction(L, luaCB_gui_index);
lua_setfield(L, -2, "__index");
lua_pushcfunction(L, luaCB_gui_newindex);
lua_setfield(L, -2, "__newindex");
lua_pushcfunction(L, luaCB_pairs);
lua_setfield(L, -2, "__pairs");
lua_pushlightuserdata(L, lua_camera_gui_fields);
lua_setfield(L, -2, "fields");
lua_setmetatable(L, -2);
}
else lua_rawget(L, 1);
return 1;
}
......@@ -695,6 +720,84 @@ static int luaCB_fec_newindex(lua_State * L)
return 0;
}
/// Canon GUI controls (PLAY, MENU, QR and so on)
//@type gui
static int luaCB_gui_index(lua_State * L)
{
LUA_PARAM_STRING_OPTIONAL(key, 2, "");
/// Get/Set whether Canon menu is active or not
// @tfield bool menu
if(!strcmp(key,"menu")) lua_pushboolean(L, is_menu_mode());
/// Get/Set whether the camera is in PLAY mode (image or video review)
// @tfield bool play
else if(!strcmp(key,"play")) lua_pushboolean(L, is_play_mode());
/// Get whether the camera is in PLAY mode with a still photo selected
// @tfield bool play_photo
else if(!strcmp(key,"play_photo")) lua_pushboolean(L, is_pure_play_photo_mode());
/// Get whether the camera is in PLAY mode with a H.264 movie selected
// @tfield bool play_movie
else if(!strcmp(key,"play_movie")) lua_pushboolean(L, is_pure_play_movie_mode());
/// Get whether the camera is in QR mode (QuickReview, the image review mode used right after taking a picture)
// @tfield bool qr
else if(!strcmp(key,"qr")) lua_pushboolean(L, !is_play_mode() && is_play_or_qr_mode());
/// Get whether the camera is "idle" (i.e. in standby, with no other dialogs active)
// @tfield bool idle
else if(!strcmp(key,"idle")) lua_pushboolean(L, display_idle());
else lua_rawget(L, 1);
return 1;
}
static int luaCB_gui_tostring(lua_State * L)
{
char status[50] = "";
if (is_menu_mode()) { STR_APPEND(status, "MENU"); }
else if (is_play_mode()) { STR_APPEND(status, "PLAY"); }
else if (is_pure_play_photo_mode()) { STR_APPEND(status, "PLAY,PH"); }
else if (is_pure_play_movie_mode()) { STR_APPEND(status, "PLAY,MV"); }
else if (is_play_mode()) { STR_APPEND(status, "PLAY"); }
else
{
if (display_idle()) { STR_APPEND(status, "IDLE,"); }
else { STR_APPEND(status, "BUSY,"); }
if (is_movie_mode()) { STR_APPEND(status, "MV"); }
else if (lv) { STR_APPEND(status, "LV"); }
else { STR_APPEND(status, "PH"); }
}
lua_pushfstring(L, status);
return 0;
}
static int luaCB_gui_newindex(lua_State * L)
{
LUA_PARAM_STRING_OPTIONAL(key, 2, "");
int status = 1;
if(!strcmp(key, "mode"))
{
LUA_PARAM_INT(value, 3);
SetGUIRequestMode(value);
msleep(500);
status = (get_gui_mode() == value);
}
else if(!strcmp(key, "play"))
{
LUA_PARAM_BOOL(value, 3);
if (value) enter_play_mode();
else exit_play_qr_mode();
status = (is_play_mode() == value);
}
else if(!strcmp(key, "menu"))
{
LUA_PARAM_BOOL(value, 3);
if (value) enter_menu_mode();
else exit_menu_mode();
status = (is_menu_mode() == value);
}
if(!status) return luaL_error(L, "set 'camera.gui.%s' failed", key);
return 0;
}
static const char * lua_camera_fields[] =
{
"shutter",
......@@ -710,7 +813,7 @@ static const char * lua_camera_fields[] =
"model_short",
"firmware",
"temperature",
"state",
"gui",
NULL
};
......
......@@ -289,10 +289,9 @@ static int luaCB_display_notify_box(lua_State * L)
static int luaCB_display_index(lua_State * L)
{
LUA_PARAM_STRING_OPTIONAL(key, 2, "");
if(!strcmp(key, "idle")) lua_pushboolean(L, display_idle());
/// The width of the display (720)
//@tfield int width
else if(!strcmp(key, "width")) lua_pushinteger(L, 720);
if(!strcmp(key, "width")) lua_pushinteger(L, 720);
/// The height of the display (480)
//@tfield int height
else if(!strcmp(key, "height")) lua_pushinteger(L, 480);
......@@ -303,7 +302,7 @@ static int luaCB_display_index(lua_State * L)
static int luaCB_display_newindex(lua_State * L)
{
LUA_PARAM_STRING_OPTIONAL(key, 2, "");
if(!strcmp(key, "idle") || !strcmp(key, "height") || !strcmp(key, "width"))
if (!strcmp(key, "height") || !strcmp(key, "width"))
{
return luaL_error(L, "'%s' is readonly!", key);
}
......
......@@ -230,8 +230,83 @@ function test_io()
printf("\n")
end
function test_camera_gui()
printf("Testing Canon GUI functions...\n")
camera.gui.play = true
assert(camera.gui.play == true)
-- half-shutter should exit playback mode
key.press(KEY.HALFSHUTTER)
msleep(1000)
assert(camera.gui.play == false)
key.press(KEY.UNPRESS_HALFSHUTTER)
-- randomly switch between PLAY, MENU and IDLE (with or without LiveView)
for i = 1,100 do
-- we can request MENU or PLAY mode from anywhere
-- we can only exit these modes if we are already there
if math.random(1,2) == 1 then
if math.random(1,2) == 1 then
printf("Enter PLAY mode...\n");
camera.gui.play = true
assert(camera.gui.play == true)
assert(camera.gui.menu == false)
assert(camera.gui.idle == false)
elseif camera.gui.play then
printf("Exit PLAY mode...\n");
camera.gui.play = false
assert(camera.gui.play == false)
assert(camera.gui.menu == false)
assert(camera.gui.idle == true)
end
else
if math.random(1,2) == 1 then
printf("Enter MENU mode...\n");
camera.gui.menu = true
assert(camera.gui.menu == true)
assert(camera.gui.play == false)
assert(camera.gui.idle == false)
elseif camera.gui.menu then
printf("Exit MENU mode...\n");
camera.gui.menu = false
assert(camera.gui.menu == false)
assert(camera.gui.play == false)
assert(camera.gui.idle == true)
end
end
-- also play around with LiveView
if camera.gui.menu == false and camera.gui.play == false then
if math.random(1,2) == 1 then
-- do something with LiveView, but not as often as switching MENU/PLAY
if not lv.enabled then
printf("Start LiveView...\n");
lv.start()
elseif lv.paused then
printf("Resume LiveView...\n");
lv.resume()
elseif math.random(1,10) < 9 then
-- this gets taken less often than the next one, why?
-- fixme: biased random?
printf("Pause LiveView...\n");
lv.pause()
else
printf("Stop LiveView...\n");
lv.stop()
end
end
end
end
lv.stop()
printf("Canon GUI tests completed.\n")
printf("\n")
end
function test_menu()
printf("Testing menu API...\n")
printf("Testing ML menu API...\n")
menu.open()
assert(menu.select("Expo", "ISO"))
......@@ -387,7 +462,9 @@ function test_menu()
-- exercise the menu backend a bit
for i = 1,5 do
menu.open()
assert(camera.gui.idle == false)
menu.close()
assert(camera.gui.idle == true)
end
printf("Menu tests completed.\n")
......@@ -460,16 +537,17 @@ function test_keys()
printf("Testing half-shutter...\n")
for i = 1,10 do
-- open Canon menu
key.press(KEY.MENU)
camera.gui.menu = true
msleep(1000)
-- fixme: expose things like QR_MODE, PLAY_MODE, enter_play_mode...
assert(camera.state == 1)
assert(camera.gui.menu == true)
assert(camera.gui.idle == false)
key.press(KEY.HALFSHUTTER)
msleep(200)
assert(key.last == KEY.HALFSHUTTER)
msleep(1000)
-- half-shutter should close Canon menu
assert(camera.state == 0)
assert(camera.gui.menu == false)
assert(camera.gui.idle == true)
key.press(KEY.UNPRESS_HALFSHUTTER)
msleep(200)
assert(key.last == KEY.UNPRESS_HALFSHUTTER)
......@@ -856,6 +934,13 @@ function test_camera_take_pics()
local size_jpg = print_file_size(image_path_jpg)
assert(size_cr2 or size_jpg)
-- let's review it
assert(camera.gui.qr or camera.gui.idle)
camera.gui.play = true
assert(camera.gui.play == true)
assert(camera.gui.play_photo == true)
assert(camera.gui.play_movie == false)
msleep(2000)
printf("Two burst pictures...\n")
......@@ -969,6 +1054,7 @@ function test_lv()
assert(lv.enabled, "LiveView did not start")
assert(not lens.autofocusing)
assert(lv.vidmode == "PH-LV")
assert(camera.gui.idle == true)
msleep(2000)
......@@ -1224,6 +1310,13 @@ function test_movie()
assert(not movie.recording)
console.show(); assert(console.visible)
-- let's review it
assert(camera.gui.idle == true)
camera.gui.play = true
assert(camera.gui.play == true)
assert(camera.gui.play_movie == true)
assert(camera.gui.play_photo == false)
printf("Movie recording tests completed.\n")
printf("\n")
end
......@@ -1240,6 +1333,7 @@ function api_tests()
printf("Module tests...\n")
test_io()
test_camera_gui()
test_menu()
test_camera_take_pics()
msleep(1000)
......
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