From bd66c51ee8ab92465a495ca6ec88f12823b6f0c4 Mon Sep 17 00:00:00 2001 From: reyalP Date: Sun, 9 Jan 2011 02:59:52 +0000 Subject: [PATCH] Thanks to ultimaA, Lua and ubasic optional at compile time, from http://chdk.setepontos.com/index.php?topic=5793.msg59376#msg59376 with minor modifications: http://chdk.setepontos.com/index.php?topic=5793.msg59606#msg59606 git-svn-id: http://tools.assembla.com/svn/chdk/trunk@1034 6794e30b-3f2a-0410-a806-a2bbca1c07ff --- core/conf.c | 2 + core/gui.c | 139 ++++++++++++++++++++++++----------------- core/gui_draw.c | 1 - core/gui_menu.c | 1 - core/kbd.c | 15 ++++- core/luascript.c | 2 - core/main.c | 3 +- core/motion_detector.h | 2 - core/ptp.c | 34 +++++++--- core/script.c | 61 +++++++++++++++--- include/gui.h | 3 + include/script.h | 8 +++ 12 files changed, 187 insertions(+), 84 deletions(-) diff --git a/core/conf.c b/core/conf.c index fe3f2d0d..548352fa 100644 --- a/core/conf.c +++ b/core/conf.c @@ -421,7 +421,9 @@ static void conf_change_font_cp() { } static void conf_change_script_file() { +#ifdef OPT_SCRIPTING script_load(conf.script_file, 2); +#endif } static void conf_change_menu_rbf_file() { diff --git a/core/gui.c b/core/gui.c index 94b25e44..9606322c 100644 --- a/core/gui.c +++ b/core/gui.c @@ -36,7 +36,6 @@ #endif #include "gui_grid.h" #include "histogram.h" -#include "script.h" #include "motion_detector.h" #include "raw.h" #ifdef OPT_CURVES @@ -45,12 +44,15 @@ #ifdef OPT_EDGEOVERLAY #include "edgeoverlay.h" #endif +#ifdef OPT_SCRIPTING + #include "script.h" + int script_params_has_changed=0; +#endif //------------------------------------------------------------------- #define OPTIONS_AUTOSAVE #define SPLASH_TIME 20 -int script_params_has_changed=0; //shortcuts //------------------------------------------------------------------ // #define KEY_NONE (KEY_DUMMY+1) @@ -144,8 +146,6 @@ static void gui_draw_mastermind(int arg); #endif static void gui_draw_fselect(int arg); static void gui_draw_osd_le(int arg); -static void gui_load_script(int arg); -static void gui_load_script_default(int arg); #ifdef OPT_TEXTREADER static void gui_draw_read(int arg); static void gui_draw_read_last(int arg); @@ -243,8 +243,6 @@ static const char* gui_space_warn_type_enum(int change, int arg); static const char* gui_bad_pixel_enum(int change, int arg); static const char* gui_video_af_key_enum(int change, int arg); static const char* gui_show_movie_time(int change, int arg); -static const char* gui_script_autostart_enum(int change, int arg); -static const char* gui_script_param_set_enum(int change, int arg); static const char* gui_override_disable_enum(int change, int arg); #ifdef OPT_CURVES static const char* gui_conf_curve_enum(int change, int arg); @@ -261,6 +259,13 @@ static void gui_menuproc_edge_load(int arg); static const char* gui_edge_pano_enum(int change, int arg); #endif +#ifdef OPT_SCRIPTING +static void gui_load_script(int arg); +static void gui_load_script_default(int arg); +static const char* gui_script_autostart_enum(int change, int arg); +static const char* gui_script_param_set_enum(int change, int arg); +#endif + void rinit(); @@ -305,6 +310,8 @@ static CMenuItem remote_submenu_items[] = { }; static CMenu remote_submenu = {0x86,LANG_MENU_REMOTE_PARAM_TITLE, NULL, remote_submenu_items }; + +#ifdef OPT_SCRIPTING static CMenuItem script_submenu_items_top[] = { {0x35,LANG_MENU_SCRIPT_LOAD, MENUITEM_PROC, (int*)gui_load_script }, {0x5f,LANG_MENU_SCRIPT_DELAY, MENUITEM_INT|MENUITEM_F_UNSIGNED, &conf.script_shoot_delay }, @@ -332,7 +339,7 @@ static CMenuItem script_submenu_items_bottom[] = { static CMenuItem script_submenu_items[sizeof(script_submenu_items_top)/sizeof(script_submenu_items_top[0])+SCRIPT_NUM_PARAMS+ sizeof(script_submenu_items_bottom)/sizeof(script_submenu_items_bottom[0])]; static CMenu script_submenu = {0x27,LANG_MENU_SCRIPT_TITLE, NULL, script_submenu_items }; - +#endif static CMenuItem games_submenu_items[] = { #ifdef OPT_GAME_REVERSI @@ -393,7 +400,9 @@ static CMenuItem debug_submenu_items[] = { {0x2a,LANG_MENU_DEBUG_BENCHMARK, MENUITEM_PROC, (int*)gui_draw_bench }, {0x5c,LANG_MENU_DEBUG_SHORTCUT_ACTION, MENUITEM_ENUM, (int*)gui_debug_shortcut_enum }, {0x5c,LANG_MENU_RAW_TIMER, MENUITEM_BOOL, &conf.raw_timer }, +#ifdef OPT_LUA {0x5c,LANG_MENU_LUA_RESTART, MENUITEM_BOOL, &conf.debug_lua_restart_on_error }, +#endif #if CAM_MULTIPART {0x33,LANG_MENU_DEBUG_CREATE_MULTIPART , MENUITEM_PROC, (int*)gui_menuproc_break_card }, #endif @@ -858,7 +867,9 @@ static CMenuItem root_menu_items[] = { {0x26,LANG_MENU_MAIN_ZEBRA_PARAM, MENUITEM_SUBMENU, (int*)&zebra_submenu }, {0x22,LANG_MENU_MAIN_OSD_PARAM, MENUITEM_SUBMENU, (int*)&osd_submenu }, {0x28,LANG_MENU_MAIN_VISUAL_PARAM, MENUITEM_SUBMENU, (int*)&visual_submenu }, +#ifdef OPT_SCRIPTING {0x27,LANG_MENU_MAIN_SCRIPT_PARAM, MENUITEM_SUBMENU, (int*)&script_submenu }, +#endif {0x29,LANG_MENU_MAIN_MISC, MENUITEM_SUBMENU, (int*)&misc_submenu }, #ifndef OPTIONS_AUTOSAVE {0x33,LANG_MENU_MAIN_SAVE_OPTIONS, MENUITEM_PROC, (int*)gui_menuproc_save }, @@ -1034,6 +1045,8 @@ const char* gui_conf_curve_enum(int change, int arg) { return modes[conf.curve_enable]; } #endif + +#ifdef OPT_SCRIPTING //------------------------------------------------------------------- const char* gui_script_autostart_enum(int change, int arg) { static const char* modes[]={ "Off", "On", "Once"}; @@ -1058,6 +1071,55 @@ const char* gui_script_param_set_enum(int change, int arg) { return modes[conf.script_param_set]; } +//------------------------------------------------------------------- +void gui_update_script_submenu() { + register int p=0, i; + + for (i=0; i", MAKE_COLOR(COLOR_ALT_BG, COLOR_FG)); +#ifdef OPT_SCRIPTING if ((mode_get()&MODE_MASK) == MODE_REC) { draw_txt_string(0, 14, script_title, MAKE_COLOR(COLOR_ALT_BG, COLOR_FG)); if (state_kbd_script_run) show_md_grid=5; @@ -1881,6 +1925,7 @@ void gui_redraw() md_draw_grid(); } } +#endif console_draw(); break; case GUI_MODE_NONE: @@ -2070,10 +2115,12 @@ void gui_kbd_process() #endif } #endif +#ifdef OPT_SCRIPTING } else if (kbd_is_key_clicked(KEY_SET)) { gui_menu_init(&script_submenu); gui_mode = GUI_MODE_MENU; draw_restore(); +#endif } else { #if !CAM_HAS_MANUAL_FOCUS && CAM_CAN_SD_OVERRIDE if (kbd_is_key_clicked(SHORTCUT_MF_TOGGLE)) { @@ -2236,7 +2283,9 @@ void gui_kbd_leave() #ifdef OPTIONS_AUTOSAVE conf_save_new_settings_if_changed(); #endif - ubasic_error = 0; +#ifdef OPT_UBASIC + ubasic_error = UBASIC_E_NONE; +#endif draw_restore(); if (gui_mode == GUI_MODE_READ && !rbf_load(conf.menu_rbf_file)) rbf_load_from_8x16(current_font); @@ -2564,6 +2613,7 @@ void gui_draw_osd() { gui_draw_debug_vals_osd(); +#ifdef OPT_UBASIC if (ubasic_error){ const char *msg; if (ubasic_error >= UBASIC_E_ENDMARK) { @@ -2574,6 +2624,7 @@ void gui_draw_osd() { sprintf(osd_buf, "uBASIC:%d %s ", ubasic_linenumber(), msg); draw_txt_string(0, 0, osd_buf, MAKE_COLOR(COLOR_RED, COLOR_YELLOW)); } +#endif } #ifndef OPTIONS_AUTOSAVE @@ -2771,34 +2822,6 @@ void gui_draw_fselect(int arg) { gui_fselect_init(LANG_STR_FILE_BROWSER, "A", NULL); } -//------------------------------------------------------------------- -static void gui_load_script_selected(const char *fn) { - if (fn) - script_load(fn, 1); -} -void gui_load_script(int arg) { - DIR *d; - char *path="A/CHDK/SCRIPTS"; - - // if exists "A/CHDK/SCRIPTS" go into - d=opendir(path); - if (d) { - closedir(d); - } else { - path="A"; - } - - gui_fselect_init(LANG_STR_SELECT_SCRIPT_FILE, path, gui_load_script_selected); -} - -void gui_load_script_default(int arg) { - script_load(conf.script_file, 0); - if (conf.script_param_save) { - save_params_values(1); - } -} - - //------------------------------------------------------------------- static void gui_grid_lines_load_selected(const char *fn) { if (fn) diff --git a/core/gui_draw.c b/core/gui_draw.c index 94047ba7..59deefb4 100644 --- a/core/gui_draw.c +++ b/core/gui_draw.c @@ -4,7 +4,6 @@ #include "keyboard.h" #include "conf.h" #include "font.h" -#include "ubasic.h" #include "gui_draw.h" //------------------------------------------------------------------- diff --git a/core/gui_menu.c b/core/gui_menu.c index 7b98c980..cb9621a1 100644 --- a/core/gui_menu.c +++ b/core/gui_menu.c @@ -3,7 +3,6 @@ #include "core.h" #include "keyboard.h" #include "conf.h" -#include "ubasic.h" #include "font.h" #include "lang.h" #include "gui.h" diff --git a/core/kbd.c b/core/kbd.c index ce85cc49..129da3cb 100644 --- a/core/kbd.c +++ b/core/kbd.c @@ -106,6 +106,7 @@ static int nTxtbl[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13}; static int nTxtbl[]={0,1,2,3,4,5,6,7,8,9}; #endif +#ifdef OPT_SCRIPTING // remote autostart void script_autostart() { @@ -115,6 +116,8 @@ void script_autostart() script_console_add_line("***Autostart***"); //lang_str(LANG_CONSOLE_TEXT_STARTED)); script_start_gui( 1 ); } +#endif + void exit_alt() { kbd_blocked = 0; @@ -233,6 +236,7 @@ long kbd_process() } } /*-------------------- Alex scriptless remote additions end ---------------------*/ +#ifdef OPT_SCRIPTING if (kbd_is_key_pressed(KEY_SHOOT_FULL)) { key_pressed = 100; if (!state_kbd_script_run) { @@ -240,19 +244,26 @@ long kbd_process() } else if (state_kbd_script_run == 2 || state_kbd_script_run == 3) { script_console_add_line(lang_str(LANG_CONSOLE_TEXT_INTERRUPTED)); script_end(); - } else if (L) { + } +#ifdef OPT_LUA + else if (L) { state_kbd_script_run = 2; lua_run_restore(); script_console_add_line(lang_str(LANG_CONSOLE_TEXT_INTERRUPTED)); script_end(); - } else { + } +#endif +#ifdef OPT_UBASIC + else { state_kbd_script_run = 2; if (jump_label("restore") == 0) { script_console_add_line(lang_str(LANG_CONSOLE_TEXT_INTERRUPTED)); script_end(); } } +#endif } +#endif action_stack_process_all(); if (!state_kbd_script_run) diff --git a/core/luascript.c b/core/luascript.c index ac3db0ed..4c5a5212 100644 --- a/core/luascript.c +++ b/core/luascript.c @@ -8,7 +8,6 @@ #include "lauxlib.h" #include "conf.h" #include "shot_histogram.h" -#include "ubasic.h" #include "stdlib.h" #include "raw.h" #include "raw_merge.h" @@ -565,7 +564,6 @@ static int luaCB_md_detect_motion( lua_State* L ) int parameters = (luaL_optnumber(L,14,1)); int pixels_step = (luaL_optnumber(L,15,6)); int msecs_before_trigger = (luaL_optnumber(L,16,0)); - ubasic_set_variable(0, 0); if(md_init_motion_detector( columns, rows, pixel_measure_mode, detection_timeout, measure_interval, threshold, draw_grid, 0, diff --git a/core/main.c b/core/main.c index b1a7c1d0..73627aa4 100644 --- a/core/main.c +++ b/core/main.c @@ -6,7 +6,6 @@ #include "gui.h" #include "histogram.h" #include "raw.h" -#include "motion_detector.h" #ifdef OPT_EDGEOVERLAY #include "edgeoverlay.h" #endif @@ -144,12 +143,14 @@ void core_spytask() { #endif auto_started = 0; +#ifdef OPT_SCRIPTING if (conf.script_startup==1) script_autostart(); // remote autostart if (conf.script_startup==2) { conf.script_startup=0; conf_save(); script_autostart(); } +#endif while (1) { if (raw_data_available) { diff --git a/core/motion_detector.h b/core/motion_detector.h index a712f262..8845b305 100644 --- a/core/motion_detector.h +++ b/core/motion_detector.h @@ -95,8 +95,6 @@ function md_get_cell_diff ( #include "../include/platform.h" #include "../include/stdlib.h" -#include "../include/script.h" - #define MOTION_DETECTOR_CELLS 1024 diff --git a/core/ptp.c b/core/ptp.c index 796b2954..221afb13 100644 --- a/core/ptp.c +++ b/core/ptp.c @@ -1,17 +1,18 @@ #include "camera.h" #ifdef CAM_CHDK_PTP +#include "stddef.h" #include "platform.h" #include "stdlib.h" #include "ptp.h" -#include "action_stack.h" -#include "lua.h" #include "kbd.h" #include "core.h" static int buf_size=0; +#ifdef OPT_LUA #include "script.h" +#include "action_stack.h" static lua_State *get_lua_thread(lua_State *L) { @@ -23,6 +24,7 @@ static lua_State *get_lua_thread(lua_State *L) return Lt; } +#endif static int handle_ptp( int h, ptp_data *data, int opcode, int sess_id, int trans_id, @@ -97,7 +99,9 @@ static int handle_ptp( { static union { char *str; +#ifdef OPT_LUA lua_State *lua_state; +#endif } temp_data; static int temp_data_kind = 0; // 0: nothing, 1: ascii string, 2: lua object static int temp_data_extra; // size (ascii string) or type (lua object) @@ -127,7 +131,12 @@ static int handle_ptp( break; case PTP_CHDK_ScriptStatus: ptp.num_param = 1; +// TODO script_is_running should always be defined, just ret 0 if script disabled +#ifdef OPT_SCRIPTING ptp.param1 = script_is_running()?PTP_CHDK_SCRIPT_STATUS_RUN:0; +#else + ptp.param1 = 0; +#endif break; case PTP_CHDK_GetMemory: if ( param2 == 0 || param3 < 1 ) // null pointer or invalid size? @@ -184,8 +193,8 @@ static int handle_ptp( case PTP_CHDK_TempData: if ( param2 & PTP_CHDK_TD_DOWNLOAD ) { - const char *s; - size_t l; + const char *s = NULL; + size_t l = 0; if ( temp_data_kind == 0 ) { @@ -197,9 +206,12 @@ static int handle_ptp( { s = temp_data.str; l = temp_data_extra; - } else { // temp_data_kind == 2 + } +#ifdef OPT_LUA + else { // temp_data_kind == 2 s = lua_tolstring(get_lua_thread(temp_data.lua_state),1,&l); } +#endif if ( !send_ptp_data(data,s,l) ) { @@ -211,10 +223,13 @@ static int handle_ptp( if ( temp_data_kind == 1 ) { free(temp_data.str); - } else if ( temp_data_kind == 2 ) + } +#ifdef OPT_LUA + else if ( temp_data_kind == 2 ) { lua_close(temp_data.lua_state); } +#endif temp_data_kind = 0; temp_data_extra = data->get_data_size(data->handle); @@ -238,10 +253,13 @@ static int handle_ptp( if ( temp_data_kind == 1 ) { free(temp_data.str); - } else if ( temp_data_kind == 2 ) + } +#ifdef OPT_LUA + else if ( temp_data_kind == 2 ) { lua_close(temp_data.lua_state); } +#endif temp_data_kind = 0; } break; @@ -370,6 +388,7 @@ static int handle_ptp( } break; +#ifdef OPT_LUA case PTP_CHDK_ExecuteScript: { int s; @@ -450,6 +469,7 @@ static int handle_ptp( break; } +#endif default: ptp.code = PTP_RC_ParameterNotSupported; diff --git a/core/script.c b/core/script.c index 92d9ff0f..fdf1a44d 100644 --- a/core/script.c +++ b/core/script.c @@ -8,14 +8,16 @@ #include "script.h" #include "console.h" #include "action_stack.h" -#include "luascript.h" -#include "lauxlib.h" #include "motion_detector.h" #include "shot_histogram.h" #include "lang.h" #include "gui_lang.h" #include "kbd.h" +#ifdef OPT_LUA +#include "lauxlib.h" +#endif + //------------------------------------------------------------------- const char *script_source_str=NULL; //ERR99 @@ -79,7 +81,10 @@ int script_param_order[SCRIPT_NUM_PARAMS]; static char script_params_update[SCRIPT_NUM_PARAMS]; static int script_loaded_params[SCRIPT_NUM_PARAMS]; static long running_script_stack_name = -1; + +#ifdef OPT_LUA static int state_lua_kbd_first_call_to_resume; // AUJ +#endif //------------------------------------------------------------------- static void process_title(const char *title) { @@ -449,6 +454,7 @@ void script_console_add_line(const char *str) } } +#ifdef OPT_LUA static int is_lua() { int len; @@ -460,6 +466,7 @@ static int is_lua() && ( s[len-3] == 'l' || s[len-3] == 'L' ) && s[len-4] == '.'; } +#endif static void wait_and_end(void) { @@ -478,6 +485,7 @@ static void process_script() int Lres; if (state_kbd_script_run != 3) { +#ifdef OPT_LUA if( L ) { int top; if (state_lua_kbd_first_call_to_resume) { @@ -505,13 +513,16 @@ static void process_script() script_end(); } } else +#endif { +#ifdef OPT_UBASIC ubasic_run(); if (ubasic_finished()) { script_console_add_line(lang_str(LANG_CONSOLE_TEXT_FINISHED)); action_pop(); script_end(); } +#endif } } } @@ -530,6 +541,7 @@ static int script_action_stack(long p) if(md_detect_motion()==0) { action_pop(); +#ifdef OPT_LUA if (L) { // We need to recover the motion detector's @@ -537,8 +549,11 @@ static int script_action_stack(long p) // it onto the thread's stack. lua_pushnumber( Lt, md_get_result() ); } else +#endif { +#ifdef OPT_UBASIC ubasic_set_md_ret(md_get_result()); +#endif } } break; @@ -569,11 +584,15 @@ int script_is_running() void script_end() { script_print_screen_end(); +#ifdef OPT_LUA if( L ) { lua_script_reset(); - } - else { + } else +#endif + { +#ifdef OPT_UBASIC ubasic_end(); +#endif } md_close_motion_detector(); shot_histogram_set(0); @@ -610,6 +629,7 @@ long script_start_gui( int autostart ) else script_console_add_line(lang_str(LANG_CONSOLE_TEXT_STARTED)); +#ifdef OPT_LUA if( is_lua() ) { if( !lua_script_start(script_source_str) ) { script_print_screen_end(); @@ -625,12 +645,16 @@ long script_start_gui( int autostart ) } } state_lua_kbd_first_call_to_resume = 1; - } else { // ubasic + } else +#endif + { // ubasic +#ifdef OPT_UBASIC ubasic_init(script_source_str); for (i=0; i 0) { return (kbd_is_key_pressed(k)); } else { - if (is_lua()) +#ifdef OPT_LUA + if (is_lua()) { luaL_error( L, "unknown key" ); - else + } else +#endif + { +#ifdef OPT_UBASIC ubasic_error = UBASIC_E_UNK_KEY; +#endif + } } return 0; } @@ -673,15 +706,21 @@ int camera_is_clicked(const char *s) if (k > 0) { return (kbd_last_clicked == k); } else { - if (is_lua()) +#ifdef OPT_LUA + if (is_lua()) { luaL_error( L, "unknown key" ); - else + } else +#endif + { +#ifdef OPT_UBASIC ubasic_error = UBASIC_E_UNK_KEY; +#endif + } } return 0; } - +#ifdef OPT_UBASIC void camera_press(const char *s) { // For Lua, luaCB_keyfunc handles this command. @@ -732,4 +771,6 @@ void camera_wait_click(int t) { action_wait_for_click(t); } +#endif +#endif diff --git a/include/gui.h b/include/gui.h index 0138d9e9..74d0d5c5 100644 --- a/include/gui.h +++ b/include/gui.h @@ -32,6 +32,9 @@ extern void draw_pixel(coord x, coord y, color cl); extern enum Gui_Mode gui_get_mode(); extern void gui_set_mode(enum Gui_Mode mode); + +#ifdef OPT_SCRIPTING extern void gui_update_script_submenu(); +#endif #endif diff --git a/include/script.h b/include/script.h index 6842d283..380be09b 100644 --- a/include/script.h +++ b/include/script.h @@ -6,8 +6,13 @@ #define SCRIPT_NUM_PARAMS 26 #define SCRIPT_DATA_PATH "A/CHDK/DATA/" +#ifdef OPT_UBASIC #include "ubasic.h" +#endif + +#ifdef OPT_LUA #include "../core/luascript.h" +#endif //------------------------------------------------------------------- extern const char *script_source_str; @@ -31,6 +36,9 @@ long script_stack_start(); int script_is_running(); void script_end(); long script_start_gui( int autostart ); + +#ifdef OPT_LUA long script_start_ptp( char *script , int keep_result ); +#endif #endif