Changeset 1000
- Timestamp:
- 12/06/10 03:11:05 (2 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 9 edited
-
buildconf.inc (modified) (2 diffs)
-
core/Makefile (modified) (1 diff)
-
core/action_stack.c (added)
-
core/action_stack.h (added)
-
core/kbd.c (modified) (21 diffs)
-
core/kbd.h (modified) (1 diff)
-
core/luascript.c (modified) (4 diffs)
-
core/motion_detector.c (modified) (3 diffs)
-
core/motion_detector.h (modified) (1 diff)
-
core/ptp.c (modified) (3 diffs)
-
include/script.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/buildconf.inc
r957 r1000 12 12 OPT_EDGEOVERLAY=1 13 13 OPT_LUA_STRLIB=1 14 14 15 # experimental PTP/USB interface 15 16 #OPT_PTP=1 … … 27 28 # If enabled (and firmware binaries are present) compiler will update "stubs_entry.S" 28 29 OPT_GEN_STUBS=1 29 # Shall ubasic be compiled into build? not done yet30 #!OPT_UBASIC=131 # Shall lua support be compiled into build? not done yet32 #!OPT_LUA=133 30 # the symbols / not done yet 34 31 #!OPT_SYMBOLS=1 35 32 # for people who won't use lang files at all / not done yet 36 33 #!OPT_LANGUAGEINTERFACE=1 34 35 # Not yet working, but need to be defined for a build right now 36 OPT_UBASIC=1 37 OPT_LUA=1 -
trunk/core/Makefile
r979 r1000 63 63 64 64 OBJS=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 \ 66 66 histogram.o gui_batt.o gui_space.o gui_osd.o script.o raw.o \ 67 67 gui_lang.o gui_mpopup.o gui_grid.o motion_detector.o raw_merge.o \ -
trunk/core/kbd.c
r986 r1000 5 5 #include "keyboard.h" 6 6 #include "conf.h" 7 #include "action_stack.h" 7 8 #include "camera.h" 8 9 #include "lang.h" … … 20 21 #include "shot_histogram.h" 21 22 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)]) 23 static int script_action_stack(long p); 43 24 44 25 static int soft_half_press = 0; … … 48 29 int state_lua_kbd_first_call_to_resume; // AUJ 49 30 static long delay_target_ticks; 50 static long kbd_last_clicked; 31 static long running_script_stack_name = -1; 32 long kbd_last_clicked; 33 51 34 52 35 // ------ add by Masuji SUTO (start) -------------- … … 132 115 #endif 133 116 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 reversed148 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 reversed157 kbd_sched_delay(20);158 159 KBD_STACK_PUSH(key);160 KBD_STACK_PUSH(SCRIPT_RELEASE);161 }162 163 117 void md_kbd_sched_immediate_shoot(int no_release) 164 118 { 165 kbd_int_stack_ptr-=1;// REMOVE MD ITEM119 action_pop();// REMOVE MD ITEM 166 120 167 121 // stack operations are reversed! 168 122 if (!no_release) // only release shutter if allowed 169 123 { 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 function124 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 174 128 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 reversed181 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 reversed188 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 reversed195 196 kbd_sched_delay(conf.script_shoot_delay*100);// XXX FIXME find out how to wait to jpeg save finished197 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 219 129 } 220 130 … … 268 178 } 269 179 270 void lua_script_exec( char *script , int keep_result ) 180 int script_is_running() 181 { 182 return !action_stack_is_finished(running_script_stack_name); 183 } 184 185 static 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 191 long script_start_ptp( char *script , int keep_result ) 271 192 { 272 193 lua_script_start(script); … … 276 197 kbd_blocked = 1; 277 198 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(); 286 200 } 287 201 … … 304 218 } 305 219 306 void script_start( int autostart )220 long script_start_gui( int autostart ) 307 221 { 308 222 int i; … … 314 228 auto_started = 0; 315 229 316 delay_target_ticks = 0;317 kbd_int_stack_ptr = 0;318 230 kbd_last_clicked = 0; 319 231 … … 335 247 script_print_screen_end(); 336 248 wait_and_end(); 337 return ;249 return -1; 338 250 } 339 251 for (i=0; i<SCRIPT_NUM_PARAMS; ++i) { … … 358 270 conf_update_prevent_shutdown(); 359 271 272 return script_stack_start(); 360 273 } 361 274 … … 379 292 } 380 293 381 void process_script() 382 { 294 static void process_script() 295 { // Note: This function is called from an action stack for AS_SCRIPT_RUN. 296 383 297 long t; 384 298 int Lres; 385 386 // process stack operations387 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's395 // result from ubasic variable 0 and push396 // it onto the thread's stack. -- AUJ397 lua_pushnumber( Lt, md_get_result() );398 }399 else400 {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 occurs416 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 }480 299 481 300 if (state_kbd_script_run != 3) { … … 494 313 if(conf.debug_lua_restart_on_error){ 495 314 lua_script_reset(); 496 script_start (0);315 script_start_gui(0); 497 316 } else { 498 317 wait_and_end(); … … 503 322 if (Lres != LUA_YIELD) { 504 323 script_console_add_line(lang_str(LANG_CONSOLE_TEXT_FINISHED)); 324 action_pop(); 505 325 script_end(); 506 326 } 507 } else { 327 } else 328 { 508 329 ubasic_run(); 509 330 if (ubasic_finished()) { 510 331 script_console_add_line(lang_str(LANG_CONSOLE_TEXT_FINISHED)); 332 action_pop(); 511 333 script_end(); 512 334 } … … 515 337 } 516 338 339 static 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 517 378 void ubasic_camera_press(const char *s) 518 379 { 519 380 long k = keyid_by_name(s); 520 381 if (k > 0) { 521 kbd_sched_press(k);382 action_push_press(k); 522 383 } else { 523 384 ubasic_error = 3; … … 529 390 long k = keyid_by_name(s); 530 391 if (k > 0) { 531 kbd_sched_release(k);392 action_push_release(k); 532 393 } else { 533 394 ubasic_error = 3; … … 539 400 long k = keyid_by_name(s); 540 401 if (k > 0) { 541 kbd_sched_click(k);402 action_push_click(k); 542 403 } else { 543 404 ubasic_error = 3; … … 547 408 void ubasic_camera_wait_click(int timeout) 548 409 { 549 kbd_sched_wait_click(timeout); 410 action_push(timeout); 411 action_push(AS_WAIT_CLICK); 550 412 } 551 413 … … 576 438 void ubasic_camera_sleep(long v) 577 439 { 578 kbd_sched_delay(v);440 action_push_delay(v); 579 441 } 580 442 581 443 void ubasic_camera_shoot() 582 444 { 583 kbd_sched_shoot();445 action_push(AS_SHOOT); 584 446 } 585 447 // remote autostart … … 590 452 console_clear(); 591 453 script_console_add_line("***Autostart***"); //lang_str(LANG_CONSOLE_TEXT_STARTED)); 592 script_start ( 1 );454 script_start_gui( 1 ); 593 455 } 594 456 void exit_alt() … … 713 575 key_pressed = 100; 714 576 if (!state_kbd_script_run) { 715 script_start (0);577 script_start_gui(0); 716 578 } else if (state_kbd_script_run == 2 || state_kbd_script_run == 3) { 717 579 script_console_add_line(lang_str(LANG_CONSOLE_TEXT_INTERRUPTED)); … … 736 598 } 737 599 738 if (state_kbd_script_run) 739 process_script(); 740 else 600 action_stack_process_all(); 601 if (!state_kbd_script_run) 741 602 gui_kbd_process(); 742 603 } else { -
trunk/core/kbd.h
r515 r1000 2 2 #define KBD_H 3 3 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);10 4 int keyid_by_name (const char *n); 5 int script_is_running(); 11 6 12 //------------------------------------------------------------------- 7 extern long kbd_last_clicked; 8 13 9 #endif -
trunk/core/luascript.c
r991 r1000 15 15 #include "levent.h" 16 16 #include "console.h" 17 #include "action_stack.h" 17 18 18 19 #ifdef OPT_CURVES … … 39 40 static int luaCB_shoot( lua_State* L ) 40 41 { 41 kbd_sched_shoot();42 action_push(AS_SHOOT); 42 43 return lua_yield( L, 0 ); 43 44 } … … 45 46 static int luaCB_sleep( lua_State* L ) 46 47 { 47 kbd_sched_delay( luaL_checknumber( L, 1 ) );48 action_push_delay( luaL_checknumber( L, 1 ) ); 48 49 return lua_yield( L, 0 ); 49 50 } … … 1341 1342 FUNC(console_redraw); 1342 1343 1343 lua_pushlightuserdata( L, kbd_sched_click );1344 lua_pushlightuserdata( L, action_push_click ); 1344 1345 lua_pushcclosure( L, luaCB_keyfunc, 1 ); 1345 1346 lua_setglobal( L, "click" ); 1346 1347 1347 lua_pushlightuserdata( L, kbd_sched_press );1348 lua_pushlightuserdata( L, action_push_press ); 1348 1349 lua_pushcclosure( L, luaCB_keyfunc, 1 ); 1349 1350 lua_setglobal( L, "press" ); 1350 1351 1351 lua_pushlightuserdata( L, kbd_sched_release );1352 lua_pushlightuserdata( L, action_push_release ); 1352 1353 lua_pushcclosure( L, luaCB_keyfunc, 1 ); 1353 1354 lua_setglobal( L, "release" ); -
trunk/core/motion_detector.c
r979 r1000 30 30 31 31 #include "motion_detector.h" 32 #include "action_stack.h" 32 33 #include "console.h" 33 34 … … 38 39 #define MD_XY2IDX(x,y) ((y)*motion_detector->columns+x) 39 40 40 void kbd_sched_shoot();41 41 void md_kbd_sched_immediate_shoot(int no_release); 42 42 … … 246 246 motion_detector->running=1; 247 247 248 kbd_sched_motion_detector();248 action_push(AS_MOTION_DETECTOR); 249 249 draw_clear(); 250 250 -
trunk/core/motion_detector.h
r978 r1000 101 101 #define MOTION_DETECTOR_CELLS 1024 102 102 103 void kbd_sched_motion_detector();104 105 106 103 void md_close_motion_detector(); 107 104 int md_init_motion_detector( -
trunk/core/ptp.c
r957 r1000 1 1 #include "camera.h" 2 2 #ifdef CAM_CHDK_PTP 3 4 3 #include "platform.h" 5 4 #include "stdlib.h" 6 5 #include "ptp.h" 7 6 #include "script.h" 7 #include "action_stack.h" 8 8 #include "lua.h" 9 #include "kbd.h" 9 10 10 11 #define BUF_SIZE 0x20000 // XXX what's a good camera-independent value? … … 380 381 recv_ptp_data(data,buf,s); 381 382 382 l ua_script_exec(buf, param3&PTP_CHDK_ES_RESULT);383 long script_action_stack = script_start_ptp(buf, param3&PTP_CHDK_ES_RESULT); 383 384 384 385 free(buf); … … 386 387 if ( param3 & PTP_CHDK_ES_WAIT ) 387 388 { 388 lua_script_wait(); 389 390 while ( script_is_running() ) 391 msleep(100); 392 389 393 if ( param3 & PTP_CHDK_ES_RESULT ) 390 394 { -
trunk/include/script.h
r979 r1000 24 24 //------------------------------------------------------------------- 25 25 26 extern void lua_script_exec(char *script, int keep_result); 27 extern void lua_script_wait(); 26 extern long script_start_ptp(char *script, int keep_result); 28 27 extern void *lua_get_result(); 29 28 #endif
Note: See TracChangeset
for help on using the changeset viewer.