Changeset 1020 for trunk


Ignore:
Timestamp:
01/04/11 05:09:10 (2 years ago)
Author:
reyalP
Message:

more script code refactoring from ultima in http://chdk.setepontos.com/index.php?topic=5793.msg59228#msg59228
minor modifications from the patch - didn't include ubasic error change, include lstate.h only in luascript.c

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/gui.c

    r1008 r1020  
    55#include "conf.h" 
    66#include "camera.h" 
    7 #include "ubasic.h" 
    87#include "font.h" 
    98#include "lang.h" 
  • trunk/core/kbd.c

    r1017 r1020  
    77#include "action_stack.h" 
    88#include "camera.h" 
     9#include "histogram.h" 
     10#include "gui_lang.h" 
     11#include "console.h" 
    912#include "lang.h" 
    10 #include "ubasic.h" 
    11 #include "histogram.h" 
    12 #include "script.h" 
    1313#include "gui_lang.h" 
    14 #include "motion_detector.h" 
    15 #include "console.h" 
    16 #include "lua.h" 
    17 #include "lualib.h" 
    18 #include "lauxlib.h" 
    19 #include "luascript.h" 
    20 #include "../lib/lua/lstate.h"  // for L->nCcalls, baseCcalls 
    21 #include "shot_histogram.h" 
    22  
    23 static int script_action_stack(long p); 
    24  
     14 
     15long kbd_last_clicked; 
     16int state_kbd_script_run; 
     17int kbd_blocked; 
     18static long delay_target_ticks; 
    2519static int soft_half_press = 0; 
    26 static int kbd_blocked; 
    2720static int key_pressed; 
    28 int state_kbd_script_run; 
    29 int state_lua_kbd_first_call_to_resume; // AUJ 
    30 static long delay_target_ticks; 
    31 static long running_script_stack_name = -1; 
    32 long kbd_last_clicked; 
    33  
    3421 
    3522// ------ add by Masuji SUTO (start) -------------- 
     
    120107#endif 
    121108 
    122 void md_kbd_sched_immediate_shoot(int no_release) 
    123 { 
    124     action_pop();// REMOVE MD ITEM 
    125    
    126     // stack operations are reversed! 
    127     if (!no_release)  // only release shutter if allowed 
    128     { 
    129       action_push_release(KEY_SHOOT_FULL); 
    130       action_push_delay(20); 
    131     } 
    132     action_push(AS_MOTION_DETECTOR); // it will removed right after exit from this function 
    133     kbd_key_press(KEY_SHOOT_FULL); // not a stack operation... pressing right now 
    134 } 
    135  
    136 static lua_State* L, *Lt; 
    137 static int lua_keep_result; 
    138  
    139 static int is_lua() 
    140 { 
    141   int len; 
    142   char const* s; 
    143   s = conf.script_file; 
    144   len = strlen( s ); 
    145   return len >= 4 && ( s[len-1] == 'a' || s[len-1] == 'A' ) 
    146     && ( s[len-2] == 'u' || s[len-2] == 'U' ) 
    147     && ( s[len-3] == 'l' || s[len-3] == 'L' ) 
    148     && s[len-4] == '.'; 
    149 } 
    150  
    151 static void lua_count_hook(lua_State *L, lua_Debug *ar) 
    152 { 
    153   if( L->nCcalls <= L->baseCcalls ) 
    154     lua_yield( L, 0 ); 
    155 } 
    156  
    157 void lua_script_reset() 
    158 { 
    159   if ( !lua_keep_result ) 
    160   { 
    161     lua_close( L ); 
    162     L = 0; 
    163   } 
    164   Lt = 0; 
    165 } 
    166  
    167 static int lua_script_start( char const* script ) 
    168 { 
    169   lua_keep_result = 0; 
    170   L = lua_open(); 
    171   luaL_openlibs( L ); 
    172   register_lua_funcs( L ); 
    173  
    174   Lt = lua_newthread( L ); 
    175   lua_setfield( L, LUA_REGISTRYINDEX, "Lt" ); 
    176   if( luaL_loadstring( Lt, script ) != 0 ) { 
    177     script_console_add_line( lua_tostring( Lt, -1 ) ); 
    178     lua_script_reset(); 
    179     return 0; 
    180   } 
    181   lua_sethook(Lt, lua_count_hook, LUA_MASKCOUNT, 1000 ); 
    182   return 1; 
    183 } 
    184  
    185 int script_is_running() 
    186 { 
    187     return !action_stack_is_finished(running_script_stack_name); 
    188 } 
    189  
    190 static long script_stack_start() 
    191 { 
    192     running_script_stack_name = action_stack_create(&script_action_stack, AS_SCRIPT_RUN); 
    193     return running_script_stack_name; 
    194 } 
    195  
    196 long script_start_ptp( char *script , int keep_result ) 
    197 { 
    198   lua_script_start(script); 
    199   lua_keep_result = keep_result; 
    200   state_lua_kbd_first_call_to_resume = 1; 
    201   state_kbd_script_run = 1; 
    202   kbd_blocked = 1; 
    203   auto_started = 0; 
    204   return script_stack_start(); 
    205 } 
    206  
    207 void *lua_get_result() 
    208 { 
    209   lua_State* r = L; 
    210   L = 0; 
    211   return r; 
    212 } 
    213  
    214  
    215 static void wait_and_end(void) 
    216 { 
    217         script_console_add_line("PRESS SHUTTER TO CLOSE"); 
    218  
    219         // We're not running any more, but we have scheduled stuff that 
    220         // needs to finish. So keep the script marked as running, but don't 
    221         // call any more scripting functions. 
    222         state_kbd_script_run = 3;        
    223 } 
    224  
    225 long script_start_gui( int autostart ) 
    226 { 
    227     int i; 
    228  
    229     shot_histogram_set(0); 
    230     if (autostart) 
    231         auto_started = 1; 
    232     else 
    233         auto_started = 0; 
    234  
    235     kbd_last_clicked = 0; 
    236  
    237     /*if (!autostart)*/ kbd_key_release_all(); 
    238  
    239     console_clear(); 
    240     script_print_screen_init(); 
    241  
    242     if (conf.script_param_save) { 
    243         save_params_values(0); 
    244     } 
    245     if( autostart ) 
    246         script_console_add_line("***Autostart***"); 
    247     else 
    248         script_console_add_line(lang_str(LANG_CONSOLE_TEXT_STARTED)); 
    249  
    250     if( is_lua() ) { 
    251         if( !lua_script_start(script_source_str) ) { 
    252             script_print_screen_end(); 
    253             wait_and_end(); 
    254             return -1; 
    255         } 
    256         for (i=0; i<SCRIPT_NUM_PARAMS; ++i) { 
    257             if( script_params[i][0] ) { 
    258                 char var = 'a'+i; 
    259                 lua_pushlstring( L, &var, 1 ); 
    260                 lua_pushnumber( L, conf.ubasic_vars[i] ); 
    261                 lua_settable( L, LUA_GLOBALSINDEX ); 
    262             } 
    263         } 
    264         state_lua_kbd_first_call_to_resume = 1; 
    265     } else { // ubasic 
    266         ubasic_init(script_source_str); 
    267  
    268         for (i=0; i<SCRIPT_NUM_PARAMS; ++i) { 
    269             ubasic_set_variable(i, conf.ubasic_vars[i]); 
    270         } 
    271     } 
    272  
    273     state_kbd_script_run = 1; 
    274  
    275     conf_update_prevent_shutdown(); 
    276  
    277     return script_stack_start(); 
    278 } 
    279  
    280 void script_end() 
    281 { 
    282     script_print_screen_end(); 
    283     if( L ) { 
    284       lua_script_reset(); 
    285     } 
    286     else { 
    287       ubasic_end(); 
    288     } 
    289         md_close_motion_detector(); 
    290         shot_histogram_set(0); 
    291     kbd_key_release_all(); 
    292     state_kbd_script_run = 0; 
    293  
    294     conf_update_prevent_shutdown(); 
    295  
    296     vid_bitmap_refresh(); 
    297 } 
    298  
    299 static void process_script() 
    300 {   // Note: This function is called from an action stack for AS_SCRIPT_RUN. 
    301      
    302     long t; 
    303     int Lres; 
    304  
    305     if (state_kbd_script_run != 3) { 
    306         if( L ) { 
    307             int top; 
    308             if (state_lua_kbd_first_call_to_resume) { 
    309                 state_lua_kbd_first_call_to_resume = 0; 
    310                 top = 0; 
    311             } else { 
    312                 top = lua_gettop(Lt); 
    313             } 
    314             Lres = lua_resume( Lt, top ); 
    315  
    316             if (Lres != LUA_YIELD && Lres != 0) { 
    317                 script_console_add_line( lua_tostring( Lt, -1 ) ); 
    318                 if(conf.debug_lua_restart_on_error){ 
    319                     lua_script_reset(); 
    320                     script_start_gui(0); 
    321                 } else { 
    322                     wait_and_end(); 
    323                 } 
    324                 return; 
    325             } 
    326  
    327             if (Lres != LUA_YIELD) { 
    328                 script_console_add_line(lang_str(LANG_CONSOLE_TEXT_FINISHED)); 
    329                 action_pop(); 
    330                 script_end(); 
    331             }     
    332         } else 
    333         { 
    334             ubasic_run(); 
    335             if (ubasic_finished()) { 
    336                 script_console_add_line(lang_str(LANG_CONSOLE_TEXT_FINISHED)); 
    337                 action_pop(); 
    338                 script_end(); 
    339             }     
    340         } 
    341     } 
    342 } 
    343  
    344 static int script_action_stack(long p) 
    345 { 
    346     // process stack operations 
    347     switch (p) { 
    348         case AS_SCRIPT_RUN: 
    349             if (state_kbd_script_run) 
    350                 process_script(); 
    351             else 
    352                 action_pop(); 
    353             break; 
    354         case AS_MOTION_DETECTOR: 
    355             if(md_detect_motion()==0) 
    356             { 
    357                 action_pop(); 
    358                 if (L) 
    359                 { 
    360                        // We need to recover the motion detector's 
    361                        // result and push 
    362                        // it onto the thread's stack. 
    363                        lua_pushnumber( Lt, md_get_result() ); 
    364                 } else 
    365                 { 
    366                     ubasic_set_md_ret(md_get_result()); 
    367                 } 
    368             } 
    369             break; 
    370         default: 
    371             if (!action_stack_standard(p) && !state_kbd_script_run) 
    372             { 
    373                 /*finished();*/ 
    374                 action_pop(); 
    375                 script_end(); 
    376             } 
    377             break; 
    378     } 
    379      
    380     return 1; 
    381 } 
    382  
    383 void ubasic_camera_press(const char *s) 
     109void camera_press(const char *s) 
    384110{ 
    385111    long k = keyid_by_name(s); 
     
    391117} 
    392118 
    393 void ubasic_camera_release(const char *s) 
     119void camera_release(const char *s) 
    394120{ 
    395121    long k = keyid_by_name(s); 
     
    401127} 
    402128 
    403 void ubasic_camera_click(const char *s) 
     129void camera_click(const char *s) 
    404130{ 
    405131    long k = keyid_by_name(s); 
     
    411137} 
    412138 
    413 void ubasic_camera_wait_click(int timeout) 
     139void camera_wait_click(int timeout) 
    414140{ 
    415141    action_push(timeout); 
     
    417143} 
    418144 
    419 int ubasic_camera_is_pressed(const char *s) 
     145int camera_is_pressed(const char *s) 
    420146{ 
    421147    long k = keyid_by_name(s); 
     
    429155} 
    430156 
    431 int ubasic_camera_is_clicked(const char *s) 
     157int camera_is_clicked(const char *s) 
    432158{ 
    433159    long k = keyid_by_name(s); 
     
    441167} 
    442168 
    443 void ubasic_camera_sleep(long v) 
     169void camera_sleep(long v) 
    444170{ 
    445171    action_push_delay(v); 
    446172} 
    447173 
    448 void ubasic_camera_shoot() 
     174void camera_shoot() 
    449175{ 
    450176    action_push(AS_SHOOT); 
     
    13241050} 
    13251051 
     1052void kbd_set_block(int bEnableBlock) { 
     1053    kbd_blocked = bEnableBlock ? 1 : 0; 
     1054} 
     1055 
    13261056long kbd_use_up_down_left_right_as_fast_switch() { 
    13271057    static long key_pressed = 0; // ??? static masking a global 
  • trunk/core/kbd.h

    r1000 r1020  
    44int keyid_by_name (const char *n); 
    55int script_is_running(); 
    6  
     6void kbd_set_block(int bEnableBlock); 
    77extern long kbd_last_clicked; 
    88 
  • trunk/core/luascript.c

    r1014 r1020  
    77#include "lualib.h" 
    88#include "lauxlib.h" 
    9 #include "../include/conf.h" 
     9#include "conf.h" 
    1010#include "shot_histogram.h" 
    1111#include "ubasic.h" 
     
    1616#include "console.h" 
    1717#include "action_stack.h" 
     18 
     19#include "../lib/lua/lstate.h"  // for L->nCcalls, baseCcalls 
     20 
     21lua_State* L; 
     22lua_State* Lt; 
     23int lua_keep_result; 
     24 
     25void *lua_consume_result() 
     26{ 
     27  lua_State* r = L; 
     28  L = 0; 
     29  return r; 
     30} 
     31 
     32void lua_script_reset() 
     33{ 
     34  if ( !lua_keep_result ) 
     35  { 
     36    lua_close( L ); 
     37    L = 0; 
     38  } 
     39  Lt = 0; 
     40} 
     41 
     42static void lua_count_hook(lua_State *L, lua_Debug *ar) 
     43{ 
     44  if( L->nCcalls <= L->baseCcalls ) 
     45    lua_yield( L, 0 ); 
     46} 
     47 
     48int lua_script_start( char const* script ) 
     49{ 
     50  lua_keep_result = 0; 
     51  L = lua_open(); 
     52  luaL_openlibs( L ); 
     53  register_lua_funcs( L ); 
     54 
     55  Lt = lua_newthread( L ); 
     56  lua_setfield( L, LUA_REGISTRYINDEX, "Lt" ); 
     57  if( luaL_loadstring( Lt, script ) != 0 ) { 
     58    script_console_add_line( lua_tostring( Lt, -1 ) ); 
     59    lua_script_reset(); 
     60    return 0; 
     61  } 
     62  lua_sethook(Lt, lua_count_hook, LUA_MASKCOUNT, 1000 ); 
     63  return 1; 
     64} 
    1865 
    1966#ifdef OPT_CURVES 
     
    452499{ 
    453500  int timeout = luaL_optnumber( L, 1, 0 ); 
    454   ubasic_camera_wait_click(timeout); 
     501  camera_wait_click(timeout); 
    455502  return lua_yield( L, 0 ); 
    456503} 
     
    458505static int luaCB_is_pressed( lua_State* L ) 
    459506{ 
    460   lua_pushboolean( L, ubasic_camera_is_pressed(luaL_checkstring( L, 1 ))); 
     507  lua_pushboolean( L, camera_is_pressed(luaL_checkstring( L, 1 ))); 
    461508  return 1; 
    462509} 
     
    464511static int luaCB_is_key( lua_State* L ) 
    465512{ 
    466   lua_pushboolean( L, ubasic_camera_is_clicked(luaL_checkstring( L, 1 ))); 
     513  lua_pushboolean( L, camera_is_clicked(luaL_checkstring( L, 1 ))); 
    467514  return 1; 
    468515} 
  • trunk/core/luascript.h

    r515 r1020  
    44#include "lua.h" 
    55 
     6void *lua_consume_result(); 
     7void lua_script_reset(); 
     8int lua_script_start( char const* script ); 
    69extern void register_lua_funcs( lua_State* L ); 
    710 
     11extern lua_State* L; 
     12extern lua_State* Lt; 
     13extern int lua_keep_result; 
     14 
    815#endif 
  • trunk/core/motion_detector.c

    r1017 r1020  
    3232#include "action_stack.h" 
    3333#include "console.h" 
     34#include "keyboard.h" 
    3435 
    3536#include "gui.h" 
     
    3839 
    3940#define MD_XY2IDX(x,y) ((y)*motion_detector->columns+x) 
    40  
    41 void md_kbd_sched_immediate_shoot(int no_release); 
    42  
    4341 
    4442enum { 
     
    115113static struct motion_detector_s *motion_detector=NULL; 
    116114 
    117  
    118 //motion_detector->curr=NULL; 
    119  
    120  
     115static void md_kbd_sched_immediate_shoot(int no_release) 
     116{ 
     117    action_pop();// REMOVE MD ITEM 
     118   
     119    // stack operations are reversed! 
     120    if (!no_release)  // only release shutter if allowed 
     121    { 
     122      action_push_release(KEY_SHOOT_FULL); 
     123      action_push_delay(20); 
     124    } 
     125    action_push(AS_MOTION_DETECTOR); // it will removed right after exit from this function 
     126    kbd_key_press(KEY_SHOOT_FULL); // not a stack operation... pressing right now 
     127} 
    121128 
    122129static int clip(int v) { 
  • trunk/core/ptp.c

    r1005 r1020  
    44#include "stdlib.h" 
    55#include "ptp.h" 
    6 #include "script.h" 
    76#include "action_stack.h" 
    87#include "lua.h" 
     
    109 
    1110#define BUF_SIZE 0x20000 // XXX what's a good camera-independent value? 
     11 
     12#include "script.h" 
     13 
     14static lua_State *get_lua_thread(lua_State *L) 
     15{ 
     16  lua_State *Lt; 
     17 
     18  lua_getfield(L,LUA_REGISTRYINDEX,"Lt"); 
     19  Lt = lua_tothread(L,-1); 
     20  lua_pop(L,1); 
     21 
     22  return Lt; 
     23} 
    1224 
    1325static int handle_ptp( 
     
    7688 
    7789  return 1; 
    78 } 
    79  
    80 static lua_State *get_lua_thread(lua_State *L) 
    81 { 
    82   lua_State *Lt; 
    83  
    84   lua_getfield(L,LUA_REGISTRYINDEX,"Lt"); 
    85   Lt = lua_tothread(L,-1); 
    86   lua_pop(L,1); 
    87  
    88   return Lt; 
    8990} 
    9091 
     
    401402          { 
    402403            lua_State *Lt; 
    403             temp_data.lua_state = lua_get_result(); 
     404            temp_data.lua_state = lua_consume_result(); 
    404405            Lt = get_lua_thread(temp_data.lua_state); 
    405406            temp_data_kind = 2; 
  • trunk/core/script.c

    r979 r1020  
    88#include "script.h" 
    99#include "console.h" 
     10#include "action_stack.h" 
     11#include "luascript.h" 
     12#include "motion_detector.h" 
     13#include "shot_histogram.h" 
     14#include "lang.h" 
     15#include "gui_lang.h" 
     16#include "kbd.h" 
    1017 
    1118//------------------------------------------------------------------- 
     
    7178static char script_params_update[SCRIPT_NUM_PARAMS]; 
    7279static int script_loaded_params[SCRIPT_NUM_PARAMS]; 
     80static long running_script_stack_name = -1; 
     81static int state_lua_kbd_first_call_to_resume;  // AUJ 
    7382 
    7483//------------------------------------------------------------------- 
     
    439448    } 
    440449} 
     450 
     451static int is_lua() 
     452{ 
     453  int len; 
     454  char const* s; 
     455  s = conf.script_file; 
     456  len = strlen( s ); 
     457  return len >= 4 && ( s[len-1] == 'a' || s[len-1] == 'A' ) 
     458    && ( s[len-2] == 'u' || s[len-2] == 'U' ) 
     459    && ( s[len-3] == 'l' || s[len-3] == 'L' ) 
     460    && s[len-4] == '.'; 
     461} 
     462 
     463static void wait_and_end(void) 
     464{ 
     465        script_console_add_line("PRESS SHUTTER TO CLOSE"); 
     466 
     467        // We're not running any more, but we have scheduled stuff that 
     468        // needs to finish. So keep the script marked as running, but don't 
     469        // call any more scripting functions. 
     470        state_kbd_script_run = 3;        
     471} 
     472 
     473static void process_script() 
     474{   // Note: This function is called from an action stack for AS_SCRIPT_RUN. 
     475     
     476    long t; 
     477    int Lres; 
     478 
     479    if (state_kbd_script_run != 3) { 
     480        if( L ) { 
     481            int top; 
     482            if (state_lua_kbd_first_call_to_resume) { 
     483                state_lua_kbd_first_call_to_resume = 0; 
     484                top = 0; 
     485            } else { 
     486                top = lua_gettop(Lt); 
     487            } 
     488            Lres = lua_resume( Lt, top ); 
     489 
     490            if (Lres != LUA_YIELD && Lres != 0) { 
     491                script_console_add_line( lua_tostring( Lt, -1 ) ); 
     492                if(conf.debug_lua_restart_on_error){ 
     493                    lua_script_reset(); 
     494                    script_start_gui(0); 
     495                } else { 
     496                    wait_and_end(); 
     497                } 
     498                return; 
     499            } 
     500 
     501            if (Lres != LUA_YIELD) { 
     502                script_console_add_line(lang_str(LANG_CONSOLE_TEXT_FINISHED)); 
     503                action_pop(); 
     504                script_end(); 
     505            }     
     506        } else 
     507        { 
     508            ubasic_run(); 
     509            if (ubasic_finished()) { 
     510                script_console_add_line(lang_str(LANG_CONSOLE_TEXT_FINISHED)); 
     511                action_pop(); 
     512                script_end(); 
     513            }     
     514        } 
     515    } 
     516} 
     517 
     518static int script_action_stack(long p) 
     519{ 
     520    // process stack operations 
     521    switch (p) { 
     522        case AS_SCRIPT_RUN: 
     523            if (state_kbd_script_run) 
     524                process_script(); 
     525            else 
     526                action_pop(); 
     527            break; 
     528        case AS_MOTION_DETECTOR: 
     529            if(md_detect_motion()==0) 
     530            { 
     531                action_pop(); 
     532                if (L) 
     533                { 
     534                       // We need to recover the motion detector's 
     535                       // result and push 
     536                       // it onto the thread's stack. 
     537                       lua_pushnumber( Lt, md_get_result() ); 
     538                } else 
     539                { 
     540                    ubasic_set_md_ret(md_get_result()); 
     541                } 
     542            } 
     543            break; 
     544        default: 
     545            if (!action_stack_standard(p) && !state_kbd_script_run) 
     546            { 
     547                /*finished();*/ 
     548                action_pop(); 
     549                script_end(); 
     550            } 
     551            break; 
     552    } 
     553     
     554    return 1; 
     555} 
     556 
     557long script_stack_start() 
     558{ 
     559    running_script_stack_name = action_stack_create(&script_action_stack, AS_SCRIPT_RUN); 
     560    return running_script_stack_name; 
     561} 
     562 
     563int script_is_running() 
     564{ 
     565    return !action_stack_is_finished(running_script_stack_name); 
     566} 
     567 
     568void script_end() 
     569{ 
     570    script_print_screen_end(); 
     571    if( L ) { 
     572      lua_script_reset(); 
     573    } 
     574    else { 
     575      ubasic_end(); 
     576    } 
     577        md_close_motion_detector(); 
     578        shot_histogram_set(0); 
     579    kbd_key_release_all(); 
     580    state_kbd_script_run = 0; 
     581 
     582    conf_update_prevent_shutdown(); 
     583 
     584    vid_bitmap_refresh(); 
     585} 
     586 
     587long script_start_gui( int autostart ) 
     588{ 
     589    int i; 
     590 
     591    shot_histogram_set(0); 
     592    if (autostart) 
     593        auto_started = 1; 
     594    else 
     595        auto_started = 0; 
     596 
     597    kbd_last_clicked = 0; 
     598 
     599    /*if (!autostart)*/ kbd_key_release_all(); 
     600 
     601    console_clear(); 
     602    script_print_screen_init(); 
     603 
     604    if (conf.script_param_save) { 
     605        save_params_values(0); 
     606    } 
     607    if( autostart ) 
     608        script_console_add_line("***Autostart***"); 
     609    else 
     610        script_console_add_line(lang_str(LANG_CONSOLE_TEXT_STARTED)); 
     611 
     612    if( is_lua() ) { 
     613        if( !lua_script_start(script_source_str) ) { 
     614            script_print_screen_end(); 
     615            wait_and_end(); 
     616            return -1; 
     617        } 
     618        for (i=0; i<SCRIPT_NUM_PARAMS; ++i) { 
     619            if( script_params[i][0] ) { 
     620                char var = 'a'+i; 
     621                lua_pushlstring( L, &var, 1 ); 
     622                lua_pushnumber( L, conf.ubasic_vars[i] ); 
     623                lua_settable( L, LUA_GLOBALSINDEX ); 
     624            } 
     625        } 
     626        state_lua_kbd_first_call_to_resume = 1; 
     627    } else { // ubasic 
     628        ubasic_init(script_source_str); 
     629 
     630        for (i=0; i<SCRIPT_NUM_PARAMS; ++i) { 
     631            ubasic_set_variable(i, conf.ubasic_vars[i]); 
     632        } 
     633    } 
     634 
     635    state_kbd_script_run = 1; 
     636 
     637    conf_update_prevent_shutdown(); 
     638 
     639    return script_stack_start(); 
     640} 
     641 
     642long script_start_ptp( char *script , int keep_result ) 
     643{ 
     644  lua_script_start(script); 
     645  lua_keep_result = keep_result; 
     646  state_lua_kbd_first_call_to_resume = 1; 
     647  state_kbd_script_run = 1; 
     648  kbd_set_block(1); 
     649  auto_started = 0; 
     650  return script_stack_start(); 
     651} 
     652 
  • trunk/include/script.h

    r1000 r1020  
    66#define SCRIPT_NUM_PARAMS           26 
    77#define SCRIPT_DATA_PATH            "A/CHDK/DATA/" 
     8 
     9#include "ubasic.h" 
     10#include "../core/luascript.h" 
     11#include "lualib.h" 
     12#include "lauxlib.h" 
    813 
    914//------------------------------------------------------------------- 
     
    2530 
    2631extern long script_start_ptp(char *script, int keep_result); 
    27 extern void *lua_get_result(); 
     32long script_stack_start(); 
     33int script_is_running(); 
     34void script_end(); 
     35long script_start_gui( int autostart ); 
     36long script_start_ptp( char *script , int keep_result ); 
     37 
    2838#endif 
  • trunk/lib/ubasic/camera_functions.c

    r981 r1020  
    1010#define MODE_REC                0x0100 
    1111 
    12 void ubasic_camera_press(const char *s) 
     12void camera_press(const char *s) 
    1313{ 
    1414    printf("*** button press '%s' ***\n",s); 
    1515} 
    1616 
    17 void ubasic_camera_release(const char *s) 
     17void camera_release(const char *s) 
    1818{ 
    1919    printf("*** button release '%s' ***\n",s); 
    2020} 
    2121 
    22 void ubasic_camera_click(const char *s) 
     22void camera_click(const char *s) 
    2323{ 
    2424    printf("*** button click '%s' ***\n",s); 
    2525} 
    2626 
    27 void ubasic_camera_sleep(int v) 
     27void camera_sleep(int v) 
    2828{ 
    2929    printf("*** sleep %d ***\n",v); 
    3030} 
    3131 
    32 void ubasic_camera_shoot() 
     32void camera_shoot() 
    3333{ 
    3434    printf("*** shoot ***\n"); 
    3535} 
    3636 
    37 void ubasic_camera_wait_click(int t) 
     37void camera_wait_click(int t) 
    3838{ 
    3939    printf("*** wait_click %d ***\n", t); 
    4040} 
    4141 
    42 int ubasic_camera_is_clicked(const char *s) 
     42int camera_is_clicked(const char *s) 
    4343{ 
    4444    printf("*** is_key '%s' ***\n", s); 
     
    441441 
    442442 
    443 int ubasic_camera_is_pressed(const char *v)  
    444 { 
    445     printf("*** ubasic_camera_is_pressed %s ***\n", v); 
     443int camera_is_pressed(const char *v)  
     444{ 
     445    printf("*** camera_is_pressed %s ***\n", v); 
    446446        return 0; 
    447447} 
  • trunk/lib/ubasic/camera_functions.h

    r977 r1020  
    11 
    2 void ubasic_camera_press(const char *s); 
    3 void ubasic_camera_release(const char *s); 
    4 void ubasic_camera_wait_click(int timeout); 
    5 int ubasic_camera_is_pressed(const char *s); 
    6 int ubasic_camera_is_clicked(const char *s); 
    7 void ubasic_camera_click(const char *s); 
    8 void ubasic_camera_sleep(long v); 
    9 void ubasic_camera_shoot(); 
     2void camera_press(const char *s); 
     3void camera_release(const char *s); 
     4void camera_wait_click(int timeout); 
     5int camera_is_pressed(const char *s); 
     6int camera_is_clicked(const char *s); 
     7void camera_click(const char *s); 
     8void camera_sleep(long v); 
     9void camera_shoot(); 
    1010int md_detect_motion(void); 
    1111int md_get_cell_diff(int column, int row); 
  • trunk/lib/ubasic/ubasic.c

    r991 r1020  
    254254    tokenizer_string(string, sizeof(string)); 
    255255    tokenizer_next(); 
    256     r = ubasic_camera_is_clicked(string); 
     256    r = camera_is_clicked(string); 
    257257    break; 
    258258case TOKENIZER_SCRIPT_AUTOSTARTED: 
     
    280280    tokenizer_string(string, sizeof(string)); 
    281281    tokenizer_next(); 
    282     r = ubasic_camera_is_pressed(string); 
     282    r = camera_is_pressed(string); 
    283283    break; 
    284284  case TOKENIZER_RANDOM: 
     
    287287    int max = expr(); 
    288288    srand((int)shooting_get_bv96()+(unsigned short)stat_get_vbatt()+get_tick_count()); 
    289     ubasic_camera_sleep(rand()%10); 
     289    camera_sleep(rand()%10); 
    290290    r = min + rand()%(max-min+1); 
    291291  break; 
     
    14241424  accept(TOKENIZER_CLICK); 
    14251425  tokenizer_string(string, sizeof(string)); 
    1426   ubasic_camera_click(string); 
     1426  camera_click(string); 
    14271427  tokenizer_next(); 
    14281428  DEBUG_PRINTF("End of click\n"); 
     
    14351435  accept(TOKENIZER_PRESS); 
    14361436  tokenizer_string(string, sizeof(string)); 
    1437   ubasic_camera_press(string); 
     1437  camera_press(string); 
    14381438  tokenizer_next(); 
    14391439  DEBUG_PRINTF("End of press\n"); 
     
    14461446  accept(TOKENIZER_RELEASE); 
    14471447  tokenizer_string(string, sizeof(string)); 
    1448   ubasic_camera_release(string); 
     1448  camera_release(string); 
    14491449  tokenizer_next(); 
    14501450  DEBUG_PRINTF("End of release\n"); 
     
    14581458  accept(TOKENIZER_SLEEP); 
    14591459  val = expr(); 
    1460   ubasic_camera_sleep(val); 
     1460  camera_sleep(val); 
    14611461  DEBUG_PRINTF("End of sleep\n"); 
    14621462  accept_cr(); 
     
    14671467{ 
    14681468  accept(TOKENIZER_SHOOT); 
    1469   ubasic_camera_shoot(); 
     1469  camera_shoot(); 
    14701470  DEBUG_PRINTF("End of shoot\n"); 
    14711471  accept_cr(); 
     
    21152115        timeout = expr(); 
    21162116    } 
    2117     ubasic_camera_wait_click(timeout); 
     2117    camera_wait_click(timeout); 
    21182118    accept_cr(); 
    21192119} 
     
    21272127    tokenizer_string(string, sizeof(string)); 
    21282128    tokenizer_next(); 
    2129     ubasic_set_variable(var, ubasic_camera_is_clicked(string)); 
     2129    ubasic_set_variable(var, camera_is_clicked(string)); 
    21302130    DEBUG_PRINTF("End of is_key\n"); 
    21312131    accept_cr(); 
Note: See TracChangeset for help on using the changeset viewer.