Changeset 1034 for trunk


Ignore:
Timestamp:
01/09/11 02:59:52 (2 years ago)
Author:
reyalP
Message:

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

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/conf.c

    r986 r1034  
    422422 
    423423static void conf_change_script_file() { 
     424#ifdef OPT_SCRIPTING 
    424425    script_load(conf.script_file, 2); 
     426#endif 
    425427} 
    426428 
  • trunk/core/gui.c

    r1022 r1034  
    3737#include "gui_grid.h" 
    3838#include "histogram.h" 
    39 #include "script.h" 
    4039#include "motion_detector.h" 
    4140#include "raw.h" 
     
    4645        #include "edgeoverlay.h" 
    4746#endif 
     47#ifdef OPT_SCRIPTING 
     48    #include "script.h" 
     49    int script_params_has_changed=0; 
     50#endif 
    4851//------------------------------------------------------------------- 
    4952 
     
    5154#define SPLASH_TIME               20 
    5255 
    53 int script_params_has_changed=0; 
    5456//shortcuts 
    5557//------------------------------------------------------------------ 
     
    145147static void gui_draw_fselect(int arg); 
    146148static void gui_draw_osd_le(int arg); 
    147 static void gui_load_script(int arg); 
    148 static void gui_load_script_default(int arg); 
    149149#ifdef OPT_TEXTREADER 
    150150static void gui_draw_read(int arg); 
     
    244244static const char* gui_video_af_key_enum(int change, int arg); 
    245245static const char* gui_show_movie_time(int change, int arg); 
    246 static const char* gui_script_autostart_enum(int change, int arg); 
    247 static const char* gui_script_param_set_enum(int change, int arg); 
    248246static const char* gui_override_disable_enum(int change, int arg); 
    249247#ifdef OPT_CURVES 
     
    260258static void gui_menuproc_edge_load(int arg); 
    261259static const char* gui_edge_pano_enum(int change, int arg); 
     260#endif 
     261 
     262#ifdef OPT_SCRIPTING 
     263static void gui_load_script(int arg); 
     264static void gui_load_script_default(int arg); 
     265static const char* gui_script_autostart_enum(int change, int arg); 
     266static const char* gui_script_param_set_enum(int change, int arg); 
    262267#endif 
    263268 
     
    306311static CMenu remote_submenu = {0x86,LANG_MENU_REMOTE_PARAM_TITLE, NULL, remote_submenu_items }; 
    307312 
     313 
     314#ifdef OPT_SCRIPTING 
    308315static CMenuItem script_submenu_items_top[] = { 
    309316    {0x35,LANG_MENU_SCRIPT_LOAD,             MENUITEM_PROC,                      (int*)gui_load_script }, 
     
    333340                               sizeof(script_submenu_items_bottom)/sizeof(script_submenu_items_bottom[0])]; 
    334341static CMenu script_submenu = {0x27,LANG_MENU_SCRIPT_TITLE, NULL, script_submenu_items }; 
    335  
     342#endif 
    336343 
    337344static CMenuItem games_submenu_items[] = { 
     
    394401    {0x5c,LANG_MENU_DEBUG_SHORTCUT_ACTION,   MENUITEM_ENUM,          (int*)gui_debug_shortcut_enum }, 
    395402    {0x5c,LANG_MENU_RAW_TIMER,               MENUITEM_BOOL,          &conf.raw_timer }, 
     403#ifdef OPT_LUA 
    396404    {0x5c,LANG_MENU_LUA_RESTART,             MENUITEM_BOOL,          &conf.debug_lua_restart_on_error }, 
     405#endif 
    397406#if CAM_MULTIPART 
    398407    {0x33,LANG_MENU_DEBUG_CREATE_MULTIPART , MENUITEM_PROC,             (int*)gui_menuproc_break_card }, 
     
    859868    {0x22,LANG_MENU_MAIN_OSD_PARAM,          MENUITEM_SUBMENU,   (int*)&osd_submenu }, 
    860869    {0x28,LANG_MENU_MAIN_VISUAL_PARAM,       MENUITEM_SUBMENU,   (int*)&visual_submenu }, 
     870#ifdef OPT_SCRIPTING 
    861871    {0x27,LANG_MENU_MAIN_SCRIPT_PARAM,       MENUITEM_SUBMENU,   (int*)&script_submenu }, 
     872#endif 
    862873    {0x29,LANG_MENU_MAIN_MISC,               MENUITEM_SUBMENU,   (int*)&misc_submenu }, 
    863874#ifndef OPTIONS_AUTOSAVE 
     
    10351046} 
    10361047#endif 
     1048 
     1049#ifdef OPT_SCRIPTING 
    10371050//------------------------------------------------------------------- 
    10381051const char* gui_script_autostart_enum(int change, int arg) { 
     
    10591072} 
    10601073 
     1074//------------------------------------------------------------------- 
     1075void gui_update_script_submenu() { 
     1076    register int p=0, i; 
     1077 
     1078    for (i=0; i<sizeof(script_submenu_items_top)/sizeof(script_submenu_items_top[0]); ++p, ++i) { 
     1079        script_submenu_items[p]=script_submenu_items_top[i]; 
     1080    } 
     1081    for (i=0; i<SCRIPT_NUM_PARAMS; ++i) { 
     1082        if (script_param_order[i]) { 
     1083            script_submenu_items[p].symbol=0x0; 
     1084            script_submenu_items[p].text=(int)script_params[script_param_order[i]-1]; 
     1085            script_submenu_items[p].type=MENUITEM_INT; 
     1086            script_submenu_items[p].value=&conf.ubasic_vars[script_param_order[i]-1]; 
     1087            ++p; 
     1088        } 
     1089    } 
     1090    for (i=0; i<sizeof(script_submenu_items_bottom)/sizeof(script_submenu_items_bottom[0]); ++p, ++i) { 
     1091        script_submenu_items[p]=script_submenu_items_bottom[i]; 
     1092    } 
     1093} 
     1094 
     1095//------------------------------------------------------------------- 
     1096static void gui_load_script_selected(const char *fn) { 
     1097    if (fn) 
     1098        script_load(fn, 1); 
     1099} 
     1100 
     1101void gui_load_script(int arg) { 
     1102    DIR   *d; 
     1103    char  *path="A/CHDK/SCRIPTS"; 
     1104 
     1105    // if exists "A/CHDK/SCRIPTS" go into 
     1106    d=opendir(path); 
     1107    if (d) { 
     1108        closedir(d); 
     1109    } else { 
     1110        path="A"; 
     1111    } 
     1112 
     1113    gui_fselect_init(LANG_STR_SELECT_SCRIPT_FILE, path, gui_load_script_selected); 
     1114} 
     1115 
     1116void gui_load_script_default(int arg) { 
     1117    script_load(conf.script_file, 0); 
     1118    if (conf.script_param_save) { 
     1119        save_params_values(1); 
     1120    } 
     1121} 
     1122#endif 
    10611123 
    10621124//------------------------------------------------------------------- 
     
    12911353//------------------------------------------------------------------- 
    12921354const char* gui_alt_power_enum(int change, int arg) { 
    1293     static const char* modes[]={ "Never", "Alt", "Script","Always" }; 
     1355// Script option is retained even if scripting is disabled, otherwise conf values will change 
     1356// Equivalent to ALT 
     1357    static const char* modes[]={ "Never", "Alt", "Script", "Always" }; 
    12941358        gui_enum_value_change(&conf.alt_prevent_shutdown,change,sizeof(modes)/sizeof(modes[0])); 
    12951359         
     
    15661630        return lang_str((int)gui_change_simple_enum(&conf.bad_pixel_removal,change,(const char **)modes,sizeof(modes)/sizeof(modes[0]))); 
    15671631}  
    1568   
    1569 //------------------------------------------------------------------- 
    1570 void gui_update_script_submenu() { 
    1571     register int p=0, i; 
    1572  
    1573     for (i=0; i<sizeof(script_submenu_items_top)/sizeof(script_submenu_items_top[0]); ++p, ++i) { 
    1574         script_submenu_items[p]=script_submenu_items_top[i]; 
    1575     } 
    1576     for (i=0; i<SCRIPT_NUM_PARAMS; ++i) { 
    1577         if (script_param_order[i]) { 
    1578             script_submenu_items[p].symbol=0x0; 
    1579             script_submenu_items[p].text=(int)script_params[script_param_order[i]-1]; 
    1580             script_submenu_items[p].type=MENUITEM_INT; 
    1581             script_submenu_items[p].value=&conf.ubasic_vars[script_param_order[i]-1]; 
    1582             ++p; 
    1583         } 
    1584     } 
    1585     for (i=0; i<sizeof(script_submenu_items_bottom)/sizeof(script_submenu_items_bottom[0]); ++p, ++i) { 
    1586         script_submenu_items[p]=script_submenu_items_bottom[i]; 
    1587     } 
    1588 } 
    15891632 
    15901633//------------------------------------------------------------------- 
     
    18741917            gui_draw_osd(); 
    18751918            draw_txt_string(20, 14, "<ALT>", MAKE_COLOR(COLOR_ALT_BG, COLOR_FG)); 
     1919#ifdef OPT_SCRIPTING 
    18761920            if ((mode_get()&MODE_MASK) == MODE_REC) { 
    18771921                draw_txt_string(0, 14, script_title, MAKE_COLOR(COLOR_ALT_BG, COLOR_FG)); 
     
    18821926                } 
    18831927            } 
     1928#endif 
    18841929            console_draw(); 
    18851930            break; 
     
    20712116                                } 
    20722117#endif 
     2118#ifdef OPT_SCRIPTING 
    20732119            } else if (kbd_is_key_clicked(KEY_SET)) { 
    20742120                gui_menu_init(&script_submenu); 
    20752121                gui_mode = GUI_MODE_MENU; 
    20762122                draw_restore(); 
     2123#endif 
    20772124            } else { 
    20782125#if !CAM_HAS_MANUAL_FOCUS && CAM_CAN_SD_OVERRIDE 
     
    22372284    conf_save_new_settings_if_changed(); 
    22382285#endif 
    2239     ubasic_error = 0; 
     2286#ifdef OPT_UBASIC 
     2287    ubasic_error = UBASIC_E_NONE; 
     2288#endif 
    22402289    draw_restore(); 
    22412290    if (gui_mode == GUI_MODE_READ && !rbf_load(conf.menu_rbf_file)) 
     
    25652614        gui_draw_debug_vals_osd(); 
    25662615 
     2616#ifdef OPT_UBASIC 
    25672617    if (ubasic_error){ 
    25682618        const char *msg; 
     
    25752625        draw_txt_string(0, 0, osd_buf, MAKE_COLOR(COLOR_RED, COLOR_YELLOW)); 
    25762626    } 
     2627#endif 
    25772628} 
    25782629 
     
    27712822    gui_fselect_init(LANG_STR_FILE_BROWSER, "A", NULL); 
    27722823} 
    2773  
    2774 //------------------------------------------------------------------- 
    2775 static void gui_load_script_selected(const char *fn) { 
    2776     if (fn) 
    2777         script_load(fn, 1); 
    2778 } 
    2779 void gui_load_script(int arg) { 
    2780     DIR   *d; 
    2781     char  *path="A/CHDK/SCRIPTS"; 
    2782  
    2783     // if exists "A/CHDK/SCRIPTS" go into 
    2784     d=opendir(path); 
    2785     if (d) { 
    2786         closedir(d); 
    2787     } else { 
    2788         path="A"; 
    2789     } 
    2790  
    2791     gui_fselect_init(LANG_STR_SELECT_SCRIPT_FILE, path, gui_load_script_selected); 
    2792 } 
    2793  
    2794 void gui_load_script_default(int arg) { 
    2795     script_load(conf.script_file, 0); 
    2796     if (conf.script_param_save) { 
    2797         save_params_values(1); 
    2798     } 
    2799 } 
    2800  
    28012824 
    28022825//------------------------------------------------------------------- 
  • trunk/core/gui_draw.c

    r804 r1034  
    55#include "conf.h" 
    66#include "font.h" 
    7 #include "ubasic.h" 
    87#include "gui_draw.h" 
    98 
  • trunk/core/gui_menu.c

    r936 r1034  
    44#include "keyboard.h" 
    55#include "conf.h" 
    6 #include "ubasic.h" 
    76#include "font.h" 
    87#include "lang.h" 
  • trunk/core/kbd.c

    r1032 r1034  
    107107#endif 
    108108 
     109#ifdef OPT_SCRIPTING 
    109110// remote autostart 
    110111void script_autostart() 
     
    116117    script_start_gui( 1 ); 
    117118} 
     119#endif 
     120 
    118121void exit_alt() 
    119122{ 
     
    234237        } 
    235238/*-------------------- Alex scriptless remote additions end ---------------------*/ 
     239#ifdef OPT_SCRIPTING 
    236240        if (kbd_is_key_pressed(KEY_SHOOT_FULL)) { 
    237241            key_pressed = 100; 
     
    241245                script_console_add_line(lang_str(LANG_CONSOLE_TEXT_INTERRUPTED)); 
    242246                script_end(); 
    243             } else if (L) { 
     247            } 
     248#ifdef OPT_LUA 
     249            else if (L) { 
    244250                state_kbd_script_run = 2; 
    245251                                lua_run_restore(); 
    246252                script_console_add_line(lang_str(LANG_CONSOLE_TEXT_INTERRUPTED)); 
    247253                script_end(); 
    248             } else { 
     254            } 
     255#endif 
     256#ifdef OPT_UBASIC 
     257            else { 
    249258                state_kbd_script_run = 2; 
    250259                if (jump_label("restore") == 0) { 
     
    253262                } 
    254263            } 
    255         } 
     264#endif 
     265        } 
     266#endif 
    256267 
    257268        action_stack_process_all(); 
  • trunk/core/luascript.c

    r1032 r1034  
    99#include "conf.h" 
    1010#include "shot_histogram.h" 
    11 #include "ubasic.h" 
    1211#include "stdlib.h" 
    1312#include "raw.h" 
     
    566565  int pixels_step = (luaL_optnumber(L,15,6)); 
    567566  int msecs_before_trigger = (luaL_optnumber(L,16,0)); 
    568   ubasic_set_variable(0, 0); 
    569567  if(md_init_motion_detector( 
    570568    columns, rows, pixel_measure_mode, detection_timeout,  
  • trunk/core/main.c

    r1022 r1034  
    77#include "histogram.h" 
    88#include "raw.h" 
    9 #include "motion_detector.h" 
    109#ifdef OPT_EDGEOVERLAY 
    1110    #include "edgeoverlay.h" 
     
    145144    auto_started = 0; 
    146145 
     146#ifdef OPT_SCRIPTING 
    147147    if (conf.script_startup==1) script_autostart();    // remote autostart 
    148148    if (conf.script_startup==2) { 
     
    151151        script_autostart(); 
    152152    } 
     153#endif 
    153154 
    154155    while (1) { 
  • trunk/core/motion_detector.h

    r1000 r1034  
    9696#include "../include/platform.h" 
    9797#include "../include/stdlib.h" 
    98 #include "../include/script.h" 
    99  
    10098 
    10199#define MOTION_DETECTOR_CELLS 1024 
  • trunk/core/ptp.c

    r1022 r1034  
    11#include "camera.h" 
    22#ifdef CAM_CHDK_PTP 
     3#include "stddef.h" 
    34#include "platform.h" 
    45#include "stdlib.h" 
    56#include "ptp.h" 
    6 #include "action_stack.h" 
    7 #include "lua.h" 
    87#include "kbd.h" 
    98 
     
    1211static int buf_size=0; 
    1312 
     13#ifdef OPT_LUA 
    1414#include "script.h" 
     15#include "action_stack.h" 
    1516 
    1617static lua_State *get_lua_thread(lua_State *L) 
     
    2425  return Lt; 
    2526} 
     27#endif 
    2628 
    2729static int handle_ptp( 
     
    98100  static union { 
    99101    char *str; 
     102#ifdef OPT_LUA 
    100103    lua_State *lua_state; 
     104#endif 
    101105  } temp_data; 
    102106  static int temp_data_kind = 0; // 0: nothing, 1: ascii string, 2: lua object 
     
    128132    case PTP_CHDK_ScriptStatus: 
    129133      ptp.num_param = 1; 
     134// TODO script_is_running should always be defined, just ret 0 if script disabled 
     135#ifdef OPT_SCRIPTING 
    130136      ptp.param1 = script_is_running()?PTP_CHDK_SCRIPT_STATUS_RUN:0; 
     137#else 
     138      ptp.param1 = 0; 
     139#endif 
    131140      break; 
    132141    case PTP_CHDK_GetMemory: 
     
    185194      if ( param2 & PTP_CHDK_TD_DOWNLOAD ) 
    186195      { 
    187         const char *s; 
    188         size_t l; 
     196        const char *s = NULL; 
     197        size_t l = 0; 
    189198 
    190199        if ( temp_data_kind == 0 ) 
     
    198207          s = temp_data.str; 
    199208          l = temp_data_extra; 
    200         } else { // temp_data_kind == 2 
     209        } 
     210#ifdef OPT_LUA 
     211        else { // temp_data_kind == 2 
    201212          s = lua_tolstring(get_lua_thread(temp_data.lua_state),1,&l); 
    202213        } 
     214#endif 
    203215 
    204216        if ( !send_ptp_data(data,s,l) ) 
     
    212224        { 
    213225          free(temp_data.str); 
    214         } else if ( temp_data_kind == 2 ) 
     226        } 
     227#ifdef OPT_LUA 
     228        else if ( temp_data_kind == 2 ) 
    215229        { 
    216230          lua_close(temp_data.lua_state); 
    217231        } 
     232#endif 
    218233        temp_data_kind = 0; 
    219234 
     
    239254        { 
    240255          free(temp_data.str); 
    241         } else if ( temp_data_kind == 2 ) 
     256        } 
     257#ifdef OPT_LUA 
     258        else if ( temp_data_kind == 2 ) 
    242259        { 
    243260          lua_close(temp_data.lua_state); 
    244261        } 
     262#endif 
    245263        temp_data_kind = 0; 
    246264      } 
     
    371389      break; 
    372390 
     391#ifdef OPT_LUA 
    373392    case PTP_CHDK_ExecuteScript: 
    374393      { 
     
    451470        break; 
    452471      } 
     472#endif 
    453473 
    454474    default: 
  • trunk/core/script.c

    r1032 r1034  
    99#include "console.h" 
    1010#include "action_stack.h" 
    11 #include "luascript.h" 
    12 #include "lauxlib.h" 
    1311#include "motion_detector.h" 
    1412#include "shot_histogram.h" 
     
    1614#include "gui_lang.h" 
    1715#include "kbd.h" 
     16 
     17#ifdef OPT_LUA 
     18#include "lauxlib.h" 
     19#endif 
    1820 
    1921//------------------------------------------------------------------- 
     
    8082static int script_loaded_params[SCRIPT_NUM_PARAMS]; 
    8183static long running_script_stack_name = -1; 
     84 
     85#ifdef OPT_LUA 
    8286static int state_lua_kbd_first_call_to_resume;  // AUJ 
     87#endif 
    8388 
    8489//------------------------------------------------------------------- 
     
    450455} 
    451456 
     457#ifdef OPT_LUA 
    452458static int is_lua() 
    453459{ 
     
    461467    && s[len-4] == '.'; 
    462468} 
     469#endif 
    463470 
    464471static void wait_and_end(void) 
     
    479486 
    480487    if (state_kbd_script_run != 3) { 
     488#ifdef OPT_LUA 
    481489        if( L ) { 
    482490            int top; 
     
    506514            }     
    507515        } else 
     516#endif 
    508517        { 
     518#ifdef OPT_UBASIC 
    509519            ubasic_run(); 
    510520            if (ubasic_finished()) { 
     
    513523                script_end(); 
    514524            }     
     525#endif 
    515526        } 
    516527    } 
     
    531542            { 
    532543                action_pop(); 
     544#ifdef OPT_LUA 
    533545                if (L) 
    534546                { 
     
    538550                       lua_pushnumber( Lt, md_get_result() ); 
    539551                } else 
     552#endif 
    540553                { 
     554#ifdef OPT_UBASIC 
    541555                    ubasic_set_md_ret(md_get_result()); 
     556#endif 
    542557                } 
    543558            } 
     
    570585{ 
    571586    script_print_screen_end(); 
     587#ifdef OPT_LUA 
    572588    if( L ) { 
    573589      lua_script_reset(); 
    574     } 
    575     else { 
     590    } else 
     591#endif 
     592    { 
     593#ifdef OPT_UBASIC 
    576594      ubasic_end(); 
     595#endif 
    577596    } 
    578597        md_close_motion_detector(); 
     
    611630        script_console_add_line(lang_str(LANG_CONSOLE_TEXT_STARTED)); 
    612631 
     632#ifdef OPT_LUA 
    613633    if( is_lua() ) { 
    614634        if( !lua_script_start(script_source_str) ) { 
     
    626646        } 
    627647        state_lua_kbd_first_call_to_resume = 1; 
    628     } else { // ubasic 
     648    } else 
     649#endif 
     650    { // ubasic 
     651#ifdef OPT_UBASIC 
    629652        ubasic_init(script_source_str); 
    630653 
     
    632655            ubasic_set_variable(i, conf.ubasic_vars[i]); 
    633656        } 
     657#endif 
    634658    } 
    635659 
     
    641665} 
    642666 
     667#ifdef OPT_LUA 
    643668long script_start_ptp( char *script , int keep_result ) 
    644669{ 
     
    651676  return script_stack_start(); 
    652677} 
    653  
     678#endif 
     679 
     680#ifndef UBASIC_TEST 
    654681int camera_is_pressed(const char *s) 
    655682{ 
     
    659686        return (kbd_is_key_pressed(k)); 
    660687    } else { 
    661         if (is_lua()) 
     688#ifdef OPT_LUA 
     689        if (is_lua()) { 
    662690            luaL_error( L, "unknown key" ); 
    663         else 
     691        } else 
     692#endif 
     693        { 
     694#ifdef OPT_UBASIC 
    664695            ubasic_error = UBASIC_E_UNK_KEY; 
     696#endif 
     697        } 
    665698    } 
    666699    return 0; 
     
    674707        return (kbd_last_clicked == k); 
    675708    } else { 
    676         if (is_lua()) 
     709#ifdef OPT_LUA 
     710        if (is_lua()) { 
    677711            luaL_error( L, "unknown key" ); 
    678         else 
     712        } else 
     713#endif 
     714        { 
     715#ifdef OPT_UBASIC 
    679716            ubasic_error = UBASIC_E_UNK_KEY; 
     717#endif 
     718        } 
    680719    } 
    681720    return 0; 
    682721} 
    683722 
    684  
     723#ifdef OPT_UBASIC 
    685724void camera_press(const char *s) 
    686725{ 
     
    733772    action_wait_for_click(t); 
    734773} 
    735  
     774#endif 
     775 
     776#endif 
  • trunk/include/gui.h

    r993 r1034  
    3333extern enum Gui_Mode gui_get_mode(); 
    3434extern void gui_set_mode(enum Gui_Mode mode); 
     35 
     36#ifdef OPT_SCRIPTING 
    3537extern void gui_update_script_submenu(); 
     38#endif 
    3639 
    3740#endif 
  • trunk/include/script.h

    r1021 r1034  
    77#define SCRIPT_DATA_PATH            "A/CHDK/DATA/" 
    88 
     9#ifdef OPT_UBASIC 
    910#include "ubasic.h" 
     11#endif 
     12 
     13#ifdef OPT_LUA 
    1014#include "../core/luascript.h" 
     15#endif 
    1116 
    1217//------------------------------------------------------------------- 
     
    3237void script_end(); 
    3338long script_start_gui( int autostart ); 
     39 
     40#ifdef OPT_LUA 
    3441long script_start_ptp( char *script , int keep_result ); 
     42#endif 
    3543 
    3644#endif 
Note: See TracChangeset for help on using the changeset viewer.