Changeset 1000


Ignore:
Timestamp:
12/06/10 03:11:05 (2 years ago)
Author:
reyalp
Message:

more preparation for making script optional - split scriptable actions out of kbd.c from ultimA in http://chdk.setepontos.com/index.php?topic=5793.msg57539#msg57539

Location:
trunk
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/buildconf.inc

    r957 r1000  
    1212OPT_EDGEOVERLAY=1 
    1313OPT_LUA_STRLIB=1 
     14 
    1415# experimental PTP/USB interface 
    1516#OPT_PTP=1 
     
    2728# If enabled (and firmware binaries are present) compiler will update "stubs_entry.S" 
    2829OPT_GEN_STUBS=1 
    29 # Shall ubasic be compiled into build? not done yet 
    30 #!OPT_UBASIC=1 
    31 # Shall lua support be compiled into build? not done yet 
    32 #!OPT_LUA=1 
    3330# the symbols / not done yet 
    3431#!OPT_SYMBOLS=1 
    3532# for people who won't use lang files at all / not done yet 
    3633#!OPT_LANGUAGEINTERFACE=1 
     34 
     35# Not yet working, but need to be defined for a build right now 
     36OPT_UBASIC=1 
     37OPT_LUA=1 
  • trunk/core/Makefile

    r979 r1000  
    6363 
    6464OBJS=entry.o nothumb.o main.o gui_draw.o gui_menu.o gui_palette.o gui_mbox.o \ 
    65      gui_fselect.o gui.o kbd.o conf.o \ 
     65     gui_fselect.o gui.o kbd.o action_stack.o conf.o \ 
    6666     histogram.o gui_batt.o gui_space.o gui_osd.o script.o raw.o \ 
    6767     gui_lang.o gui_mpopup.o gui_grid.o motion_detector.o raw_merge.o \ 
  • trunk/core/kbd.c

    r986 r1000  
    55#include "keyboard.h" 
    66#include "conf.h" 
     7#include "action_stack.h" 
    78#include "camera.h" 
    89#include "lang.h" 
     
    2021#include "shot_histogram.h" 
    2122 
    22 #define SCRIPT_END              0 
    23 #define SCRIPT_CLICK            1 
    24 #define SCRIPT_SHOOT            2 
    25 #define SCRIPT_SLEEP            3 
    26 #define SCRIPT_PRESS            4 
    27 #define SCRIPT_RELEASE          5 
    28 #define SCRIPT_PR_WAIT_SAVE     6 
    29 #define SCRIPT_WAIT_SAVE        7 
    30 #define SCRIPT_WAIT_FLASH       8 
    31 #define SCRIPT_WAIT_EXPHIST     9 
    32 #define SCRIPT_PR_WAIT_EXPHIST  10 
    33 #define SCRIPT_WAIT_CLICK       11 
    34 #define SCRIPT_MOTION_DETECTOR  12 
    35  
    36 #define KBD_STACK_SIZE 24 
    37  
    38 static long kbd_int_stack[KBD_STACK_SIZE]; 
    39 static int kbd_int_stack_ptr; 
    40  
    41 #define KBD_STACK_PUSH(v) kbd_int_stack[kbd_int_stack_ptr++] = (v); 
    42 #define KBD_STACK_PREV(p) (kbd_int_stack[kbd_int_stack_ptr-(p)]) 
     23static int script_action_stack(long p); 
    4324 
    4425static int soft_half_press = 0; 
     
    4829int state_lua_kbd_first_call_to_resume; // AUJ 
    4930static long delay_target_ticks; 
    50 static long kbd_last_clicked; 
     31static long running_script_stack_name = -1; 
     32long kbd_last_clicked; 
     33 
    5134 
    5235// ------ add by Masuji SUTO (start) -------------- 
     
    132115#endif 
    133116 
    134 void kbd_sched_delay(long msec) 
    135 { 
    136     KBD_STACK_PUSH(msec); 
    137     KBD_STACK_PUSH(SCRIPT_SLEEP); 
    138 } 
    139  
    140  
    141 void kbd_sched_motion_detector(){ 
    142     KBD_STACK_PUSH(SCRIPT_MOTION_DETECTOR); 
    143 } 
    144  
    145 void kbd_sched_press(long key) 
    146 { 
    147 // WARNING stack program flow is reversed 
    148     kbd_sched_delay(20); 
    149  
    150     KBD_STACK_PUSH(key); 
    151     KBD_STACK_PUSH(SCRIPT_PRESS); 
    152 } 
    153  
    154 void kbd_sched_release(long key) 
    155 { 
    156 // WARNING stack program flow is reversed 
    157     kbd_sched_delay(20); 
    158  
    159     KBD_STACK_PUSH(key); 
    160     KBD_STACK_PUSH(SCRIPT_RELEASE); 
    161 } 
    162  
    163117void md_kbd_sched_immediate_shoot(int no_release) 
    164118{ 
    165     kbd_int_stack_ptr-=1;// REMOVE MD ITEM 
     119    action_pop();// REMOVE MD ITEM 
    166120   
    167121    // stack operations are reversed! 
    168122    if (!no_release)  // only release shutter if allowed 
    169123    { 
    170       kbd_sched_release(KEY_SHOOT_FULL); 
    171       kbd_sched_delay(20); 
    172     } 
    173     KBD_STACK_PUSH(SCRIPT_MOTION_DETECTOR); // it will removed right after exit from this function 
     124      action_push_release(KEY_SHOOT_FULL); 
     125      action_push_delay(20); 
     126    } 
     127    action_push(AS_MOTION_DETECTOR); // it will removed right after exit from this function 
    174128    kbd_key_press(KEY_SHOOT_FULL); // not a stack operation... pressing right now 
    175 } 
    176  
    177  
    178 void kbd_sched_click(long key) 
    179 { 
    180 // WARNING stack program flow is reversed 
    181     kbd_sched_release(key); 
    182     kbd_sched_press(key); 
    183 } 
    184  
    185 static void kbd_sched_wait_click(int timeout) 
    186 { 
    187 // WARNING stack program flow is reversed 
    188     KBD_STACK_PUSH(timeout); 
    189     KBD_STACK_PUSH(SCRIPT_WAIT_CLICK); 
    190 } 
    191  
    192 void kbd_sched_shoot() 
    193 { 
    194 // WARNING stack program flow is reversed 
    195  
    196     kbd_sched_delay(conf.script_shoot_delay*100);// XXX FIXME find out how to wait to jpeg save finished 
    197  
    198     KBD_STACK_PUSH(SCRIPT_WAIT_SAVE); 
    199  
    200     KBD_STACK_PUSH(KEY_SHOOT_FULL); 
    201     KBD_STACK_PUSH(SCRIPT_RELEASE); 
    202  
    203     kbd_sched_delay(20); 
    204  
    205     KBD_STACK_PUSH(KEY_SHOOT_FULL); 
    206     KBD_STACK_PUSH(SCRIPT_PRESS); 
    207  
    208     KBD_STACK_PUSH(SCRIPT_WAIT_FLASH); 
    209     KBD_STACK_PUSH(SCRIPT_WAIT_EXPHIST); 
    210     KBD_STACK_PUSH(SCRIPT_PR_WAIT_EXPHIST); 
    211  
    212     kbd_sched_delay(10); 
    213  
    214     KBD_STACK_PUSH(KEY_SHOOT_HALF); 
    215     KBD_STACK_PUSH(SCRIPT_PRESS); 
    216  
    217     KBD_STACK_PUSH(SCRIPT_PR_WAIT_SAVE); 
    218  
    219129} 
    220130 
     
    268178} 
    269179 
    270 void lua_script_exec( char *script , int keep_result ) 
     180int script_is_running() 
     181{ 
     182    return !action_stack_is_finished(running_script_stack_name); 
     183} 
     184 
     185static long script_stack_start() 
     186{ 
     187    running_script_stack_name = action_stack_create(&script_action_stack, AS_SCRIPT_RUN); 
     188    return running_script_stack_name; 
     189} 
     190 
     191long script_start_ptp( char *script , int keep_result ) 
    271192{ 
    272193  lua_script_start(script); 
     
    276197  kbd_blocked = 1; 
    277198  auto_started = 0; 
    278 } 
    279  
    280 void lua_script_wait() 
    281 { 
    282   while ( state_kbd_script_run ) 
    283   { 
    284     msleep(100); 
    285   } 
     199  return script_stack_start(); 
    286200} 
    287201 
     
    304218} 
    305219 
    306 void script_start( int autostart ) 
     220long script_start_gui( int autostart ) 
    307221{ 
    308222    int i; 
     
    314228        auto_started = 0; 
    315229 
    316     delay_target_ticks = 0; 
    317     kbd_int_stack_ptr = 0; 
    318230    kbd_last_clicked = 0; 
    319231 
     
    335247            script_print_screen_end(); 
    336248            wait_and_end(); 
    337             return; 
     249            return -1; 
    338250        } 
    339251        for (i=0; i<SCRIPT_NUM_PARAMS; ++i) { 
     
    358270    conf_update_prevent_shutdown(); 
    359271 
     272    return script_stack_start(); 
    360273} 
    361274 
     
    379292} 
    380293 
    381 void process_script() 
    382 { 
     294static void process_script() 
     295{   // Note: This function is called from an action stack for AS_SCRIPT_RUN. 
     296     
    383297    long t; 
    384298    int Lres; 
    385  
    386     // process stack operations 
    387     if (kbd_int_stack_ptr){ 
    388         switch (KBD_STACK_PREV(1)) { 
    389             case SCRIPT_MOTION_DETECTOR: 
    390                 if(md_detect_motion()==0) { 
    391                     kbd_int_stack_ptr-=1; 
    392                     if (L) 
    393                     { 
    394                            // We need to recover the motion detector's 
    395                            // result from ubasic variable 0 and push 
    396                            // it onto the thread's stack. -- AUJ 
    397                            lua_pushnumber( Lt, md_get_result() ); 
    398                     } 
    399                     else 
    400                     { 
    401                            ubasic_set_md_ret(md_get_result()); 
    402                     } 
    403                 } 
    404                 return; 
    405             case SCRIPT_PRESS: 
    406                 kbd_key_press(KBD_STACK_PREV(2)); 
    407                 kbd_int_stack_ptr-=2; // pop op. 
    408                 return; 
    409             case SCRIPT_RELEASE: 
    410                 kbd_key_release(KBD_STACK_PREV(2)); 
    411                 kbd_int_stack_ptr-=2; // pop op. 
    412                 return; 
    413             case SCRIPT_SLEEP: 
    414                 t = get_tick_count(); 
    415                 // FIXME take care if overflow occurs 
    416                 if (delay_target_ticks == 0){ 
    417                     /* setup timer */ 
    418                     delay_target_ticks = t+KBD_STACK_PREV(2); 
    419                 } else { 
    420                     if (delay_target_ticks <= t){ 
    421                         delay_target_ticks = 0; 
    422                         kbd_int_stack_ptr-=2; // pop sleep op. 
    423                     } 
    424                 } 
    425                 return; 
    426             case SCRIPT_PR_WAIT_SAVE: 
    427                 state_shooting_progress = SHOOTING_PROGRESS_NONE; 
    428                 state_expos_recalculated = 0; 
    429                 histogram_stop(); 
    430  
    431                 kbd_int_stack_ptr-=1; // pop op. 
    432                 return; 
    433             case SCRIPT_WAIT_SAVE:{ 
    434                 if (state_shooting_progress == SHOOTING_PROGRESS_DONE) 
    435                     kbd_int_stack_ptr-=1; // pop op. 
    436                 return; 
    437             } 
    438             case SCRIPT_WAIT_FLASH:{ 
    439                 if (shooting_is_flash_ready()) 
    440                     kbd_int_stack_ptr-=1; // pop op. 
    441                 return; 
    442             } 
    443             case SCRIPT_WAIT_EXPHIST:{ 
    444                 if (state_expos_recalculated) { 
    445                     kbd_int_stack_ptr-=1; // pop op. 
    446                     state_expos_under = under_exposed; 
    447                     state_expos_over = over_exposed; 
    448                 } 
    449                 return; 
    450             } 
    451             case SCRIPT_PR_WAIT_EXPHIST: { 
    452                 if (shooting_in_progress() || mvideo) { 
    453                     state_expos_recalculated = 0; 
    454                     histogram_restart(); 
    455                     kbd_int_stack_ptr-=1; // pop op. 
    456                 } 
    457                 return; 
    458             } 
    459             case SCRIPT_WAIT_CLICK: { 
    460                 t = get_tick_count(); 
    461                 if (delay_target_ticks == 0){ 
    462                     /* setup timer */ 
    463                     delay_target_ticks = t+((KBD_STACK_PREV(2))?KBD_STACK_PREV(2):86400000); 
    464                 } else { 
    465                     kbd_last_clicked = kbd_get_clicked_key(); 
    466                     if (kbd_last_clicked || delay_target_ticks <= t) { 
    467                         if (!kbd_last_clicked)  
    468                             kbd_last_clicked=0xFFFF; 
    469                         delay_target_ticks = 0; 
    470                         kbd_int_stack_ptr-=2; // pop op. 
    471                     } 
    472                 } 
    473                 return; 
    474             } 
    475             default: 
    476                 /*finished();*/ 
    477                 script_end(); 
    478         } 
    479     } 
    480299 
    481300    if (state_kbd_script_run != 3) { 
     
    494313                if(conf.debug_lua_restart_on_error){ 
    495314                    lua_script_reset(); 
    496                     script_start(0); 
     315                    script_start_gui(0); 
    497316                } else { 
    498317                    wait_and_end(); 
     
    503322            if (Lres != LUA_YIELD) { 
    504323                script_console_add_line(lang_str(LANG_CONSOLE_TEXT_FINISHED)); 
     324                action_pop(); 
    505325                script_end(); 
    506326            }     
    507         } else { 
     327        } else 
     328        { 
    508329            ubasic_run(); 
    509330            if (ubasic_finished()) { 
    510331                script_console_add_line(lang_str(LANG_CONSOLE_TEXT_FINISHED)); 
     332                action_pop(); 
    511333                script_end(); 
    512334            }     
     
    515337} 
    516338 
     339static int script_action_stack(long p) 
     340{ 
     341    // process stack operations 
     342    switch (p) { 
     343        case AS_SCRIPT_RUN: 
     344            if (state_kbd_script_run) 
     345                process_script(); 
     346            else 
     347                action_pop(); 
     348            break; 
     349        case AS_MOTION_DETECTOR: 
     350            if(md_detect_motion()==0) 
     351            { 
     352                action_pop(); 
     353                if (L) 
     354                { 
     355                       // We need to recover the motion detector's 
     356                       // result and push 
     357                       // it onto the thread's stack. 
     358                       lua_pushnumber( Lt, md_get_result() ); 
     359                } else 
     360                { 
     361                    ubasic_set_md_ret(md_get_result()); 
     362                } 
     363            } 
     364            break; 
     365        default: 
     366            if (!action_stack_standard(p) && !state_kbd_script_run) 
     367            { 
     368                /*finished();*/ 
     369                action_pop(); 
     370                script_end(); 
     371            } 
     372            break; 
     373    } 
     374     
     375    return 1; 
     376} 
     377 
    517378void ubasic_camera_press(const char *s) 
    518379{ 
    519380    long k = keyid_by_name(s); 
    520381    if (k > 0) { 
    521         kbd_sched_press(k); 
     382        action_push_press(k); 
    522383    } else { 
    523384        ubasic_error = 3; 
     
    529390    long k = keyid_by_name(s); 
    530391    if (k > 0) { 
    531         kbd_sched_release(k); 
     392        action_push_release(k); 
    532393    } else { 
    533394        ubasic_error = 3; 
     
    539400    long k = keyid_by_name(s); 
    540401    if (k > 0) { 
    541         kbd_sched_click(k); 
     402        action_push_click(k); 
    542403    } else { 
    543404        ubasic_error = 3; 
     
    547408void ubasic_camera_wait_click(int timeout) 
    548409{ 
    549     kbd_sched_wait_click(timeout); 
     410    action_push(timeout); 
     411    action_push(AS_WAIT_CLICK); 
    550412} 
    551413 
     
    576438void ubasic_camera_sleep(long v) 
    577439{ 
    578     kbd_sched_delay(v); 
     440    action_push_delay(v); 
    579441} 
    580442 
    581443void ubasic_camera_shoot() 
    582444{ 
    583     kbd_sched_shoot(); 
     445    action_push(AS_SHOOT); 
    584446} 
    585447// remote autostart 
     
    590452    console_clear();  
    591453    script_console_add_line("***Autostart***"); //lang_str(LANG_CONSOLE_TEXT_STARTED)); 
    592     script_start( 1 ); 
     454    script_start_gui( 1 ); 
    593455} 
    594456void exit_alt() 
     
    713575            key_pressed = 100; 
    714576            if (!state_kbd_script_run) { 
    715                 script_start(0); 
     577                script_start_gui(0); 
    716578            } else if (state_kbd_script_run == 2 || state_kbd_script_run == 3) { 
    717579                script_console_add_line(lang_str(LANG_CONSOLE_TEXT_INTERRUPTED)); 
     
    736598        } 
    737599 
    738         if (state_kbd_script_run) 
    739             process_script(); 
    740         else 
     600        action_stack_process_all(); 
     601        if (!state_kbd_script_run) 
    741602            gui_kbd_process(); 
    742603    } else { 
  • trunk/core/kbd.h

    r515 r1000  
    22#define KBD_H 
    33 
    4 //------------------------------------------------------------------- 
    5 void kbd_sched_shoot(); 
    6 void kbd_sched_click(long key); 
    7 void kbd_sched_press(long key); 
    8 void kbd_sched_release(long key); 
    9 void kbd_sched_delay(long msec); 
    104int keyid_by_name (const char *n); 
     5int script_is_running(); 
    116 
    12 //------------------------------------------------------------------- 
     7extern long kbd_last_clicked; 
     8 
    139#endif 
  • trunk/core/luascript.c

    r991 r1000  
    1515#include "levent.h" 
    1616#include "console.h" 
     17#include "action_stack.h" 
    1718 
    1819#ifdef OPT_CURVES 
     
    3940static int luaCB_shoot( lua_State* L ) 
    4041{ 
    41   kbd_sched_shoot(); 
     42  action_push(AS_SHOOT); 
    4243  return lua_yield( L, 0 ); 
    4344} 
     
    4546static int luaCB_sleep( lua_State* L ) 
    4647{ 
    47   kbd_sched_delay( luaL_checknumber( L, 1 ) ); 
     48  action_push_delay( luaL_checknumber( L, 1 ) ); 
    4849  return lua_yield( L, 0 ); 
    4950} 
     
    13411342  FUNC(console_redraw); 
    13421343 
    1343   lua_pushlightuserdata( L, kbd_sched_click ); 
     1344  lua_pushlightuserdata( L, action_push_click ); 
    13441345  lua_pushcclosure( L, luaCB_keyfunc, 1 ); 
    13451346  lua_setglobal( L, "click" ); 
    13461347 
    1347   lua_pushlightuserdata( L, kbd_sched_press ); 
     1348  lua_pushlightuserdata( L, action_push_press ); 
    13481349  lua_pushcclosure( L, luaCB_keyfunc, 1 ); 
    13491350  lua_setglobal( L, "press" ); 
    13501351 
    1351   lua_pushlightuserdata( L, kbd_sched_release ); 
     1352  lua_pushlightuserdata( L, action_push_release ); 
    13521353  lua_pushcclosure( L, luaCB_keyfunc, 1 ); 
    13531354  lua_setglobal( L, "release" ); 
  • trunk/core/motion_detector.c

    r979 r1000  
    3030 
    3131#include "motion_detector.h" 
     32#include "action_stack.h" 
    3233#include "console.h" 
    3334 
     
    3839#define MD_XY2IDX(x,y) ((y)*motion_detector->columns+x) 
    3940 
    40 void kbd_sched_shoot(); 
    4141void md_kbd_sched_immediate_shoot(int no_release); 
    4242 
     
    246246        motion_detector->running=1; 
    247247 
    248         kbd_sched_motion_detector(); 
     248        action_push(AS_MOTION_DETECTOR); 
    249249        draw_clear(); 
    250250 
  • trunk/core/motion_detector.h

    r978 r1000  
    101101#define MOTION_DETECTOR_CELLS 1024 
    102102 
    103 void kbd_sched_motion_detector(); 
    104  
    105  
    106103void md_close_motion_detector(); 
    107104int md_init_motion_detector( 
  • trunk/core/ptp.c

    r957 r1000  
    11#include "camera.h" 
    22#ifdef CAM_CHDK_PTP 
    3  
    43#include "platform.h" 
    54#include "stdlib.h" 
    65#include "ptp.h" 
    76#include "script.h" 
     7#include "action_stack.h" 
    88#include "lua.h" 
     9#include "kbd.h" 
    910 
    1011#define BUF_SIZE 0x20000 // XXX what's a good camera-independent value? 
     
    380381        recv_ptp_data(data,buf,s); 
    381382 
    382         lua_script_exec(buf, param3&PTP_CHDK_ES_RESULT); 
     383        long script_action_stack = script_start_ptp(buf, param3&PTP_CHDK_ES_RESULT); 
    383384 
    384385        free(buf); 
     
    386387        if ( param3 & PTP_CHDK_ES_WAIT ) 
    387388        { 
    388           lua_script_wait(); 
     389 
     390          while ( script_is_running() ) 
     391            msleep(100); 
     392 
    389393          if ( param3 & PTP_CHDK_ES_RESULT ) 
    390394          { 
  • trunk/include/script.h

    r979 r1000  
    2424//------------------------------------------------------------------- 
    2525 
    26 extern void lua_script_exec(char *script, int keep_result); 
    27 extern void lua_script_wait(); 
     26extern long script_start_ptp(char *script, int keep_result); 
    2827extern void *lua_get_result(); 
    2928#endif 
Note: See TracChangeset for help on using the changeset viewer.