Changeset 1036
- Timestamp:
- 01/09/11 06:52:06 (2 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
-
core/kbd.c (modified) (1 diff)
-
core/luascript.c (modified) (7 diffs)
-
core/script.c (modified) (1 diff)
-
include/script.h (modified) (1 diff)
-
lib/ubasic/camera_functions.c (modified) (3 diffs)
-
lib/ubasic/camera_functions.h (modified) (1 diff)
-
lib/ubasic/ubasic.c (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/core/kbd.c
r1034 r1036 942 942 } 943 943 944 static const struct Keynames {945 int keyid;946 char *keyname;947 } keynames[] = {948 { KEY_UP, "up" },949 { KEY_DOWN, "down" },950 { KEY_LEFT, "left" },951 { KEY_RIGHT, "right" },952 { KEY_SET, "set" },953 { KEY_SHOOT_HALF, "shoot_half" },954 { KEY_SHOOT_FULL, "shoot_full" },955 { KEY_ZOOM_IN, "zoom_in" },956 { KEY_ZOOM_OUT, "zoom_out" },957 { KEY_MENU, "menu" },958 { KEY_DISPLAY, "display" },959 { KEY_PRINT, "print" },960 { KEY_ERASE, "erase" },961 { KEY_ISO, "iso" },962 { KEY_FLASH, "flash" },963 { KEY_MF, "mf" },964 { KEY_MACRO, "macro" },965 { KEY_VIDEO, "video" },966 { KEY_TIMER, "timer" },967 { KEY_EXPO_CORR, "expo_corr" },968 { KEY_MICROPHONE, "fe" },969 { KEY_ZOOM_ASSIST, "zoom_assist"},970 { KEY_AE_LOCK, "ae_lock" },971 { KEY_METERING, "metering_mode"},972 { 0xFF, "remote" },973 { 0xFFFF, "no_key" },974 };975 976 int keyid_by_name (const char *n)977 {978 int i;979 for (i=0;i<sizeof(keynames)/sizeof(keynames[0]);i++)980 if (strcmp(keynames[i].keyname,n) == 0)981 return keynames[i].keyid;982 return 0;983 }984 985 944 int kbd_is_blocked() { 986 945 return kbd_blocked; -
trunk/core/luascript.c
r1034 r1036 1 1 #include "luascript.h" 2 #include "../lib/ubasic/camera_functions.h"3 2 #include "kbd.h" 4 3 #include "platform.h" … … 15 14 #include "console.h" 16 15 #include "action_stack.h" 17 18 #include "../lib/lua/lstate.h" // for L->nCcalls, baseCcalls 16 #include "motion_detector.h" 17 18 #include "../lib/lua/lstate.h" // for L->nCcalls, baseCcalls 19 19 20 20 lua_State* L; … … 74 74 } 75 75 76 // get key ID of key name at arg, throw error if invalid 77 static int lua_get_key_arg( lua_State * L, int narg ) 78 { 79 int k = script_keyid_by_name( luaL_checkstring( L, narg ) ); 80 if(!k) 81 luaL_error( L, "unknown key" ); 82 return k; 83 } 84 76 85 #ifdef OPT_CURVES 77 86 #include "curves.h" … … 110 119 static int luaCB_keyfunc( lua_State* L ) 111 120 { 112 long k = keyid_by_name( luaL_checkstring( L, 1 ) ); 113 if (k > 0 ) { 114 void* func = lua_touserdata( L, lua_upvalueindex(1) ); 115 ((void(*)(long))func)( k ); 116 } 117 else 118 luaL_error( L, "unknown key" ); 121 void* func = lua_touserdata( L, lua_upvalueindex(1) ); 122 ((void(*)(long))func)( lua_get_key_arg( L, 1 ) ); 119 123 return lua_yield( L, 0 ); 120 124 } … … 515 519 static int luaCB_is_pressed( lua_State* L ) 516 520 { 517 lua_pushboolean( L, camera_is_pressed(luaL_checkstring( L, 1 )));521 lua_pushboolean( L, script_key_is_pressed(lua_get_key_arg( L, 1 ))); 518 522 return 1; 519 523 } … … 521 525 static int luaCB_is_key( lua_State* L ) 522 526 { 523 lua_pushboolean( L, camera_is_clicked(luaL_checkstring( L, 1 )));527 lua_pushboolean( L, script_key_is_clicked(lua_get_key_arg( L, 1 ))); 524 528 return 1; 525 529 } … … 567 571 if(md_init_motion_detector( 568 572 columns, rows, pixel_measure_mode, detection_timeout, 569 measure_interval, threshold, draw_grid, 0,573 measure_interval, threshold, draw_grid, 570 574 clipping_region_mode, 571 575 clipping_region_column1, clipping_region_row1, -
trunk/core/script.c
r1034 r1036 678 678 #endif 679 679 680 #ifndef UBASIC_TEST 681 int camera_is_pressed(const char *s) 682 { 683 long k = keyid_by_name(s); 684 if (k==0xFF) return get_usb_power(1); 685 if (k > 0) { 686 return (kbd_is_key_pressed(k)); 687 } else { 688 #ifdef OPT_LUA 689 if (is_lua()) { 690 luaL_error( L, "unknown key" ); 691 } else 692 #endif 693 { 694 #ifdef OPT_UBASIC 695 ubasic_error = UBASIC_E_UNK_KEY; 696 #endif 697 } 698 } 680 int script_key_is_pressed(int k) 681 { 682 if (k==0xFF) 683 return get_usb_power(1); 684 if (k > 0) 685 return kbd_is_key_pressed(k); 699 686 return 0; 700 687 } 701 688 702 int camera_is_clicked(const char *s)703 { 704 long k = keyid_by_name(s);705 if (k==0xFF)return get_usb_power(1);706 if (k > 0) {689 int script_key_is_clicked(int k) 690 { 691 if (k==0xFF) 692 return get_usb_power(1); 693 if (k > 0) 707 694 return (kbd_last_clicked == k); 708 } else {709 #ifdef OPT_LUA710 if (is_lua()) {711 luaL_error( L, "unknown key" );712 } else713 #endif714 {715 #ifdef OPT_UBASIC716 ubasic_error = UBASIC_E_UNK_KEY;717 #endif718 }719 }720 695 return 0; 721 696 } 722 697 723 #ifdef OPT_UBASIC 724 void camera_press(const char *s) 725 { 726 // For Lua, luaCB_keyfunc handles this command. 727 728 long k = keyid_by_name(s); 729 if (k > 0) { 730 action_push_press(k); 731 } else { 732 ubasic_error = UBASIC_E_UNK_KEY; 733 } 734 } 735 736 void camera_release(const char *s) 737 { 738 // For Lua, luaCB_keyfunc handles this command. 739 740 long k = keyid_by_name(s); 741 if (k > 0) { 742 action_push_release(k); 743 } else { 744 ubasic_error = UBASIC_E_UNK_KEY; 745 } 746 } 747 748 void camera_click(const char *s) 749 { 750 // For Lua, luaCB_keyfunc handles this command. 751 752 long k = keyid_by_name(s); 753 if (k > 0) { 754 action_push_click(k); 755 } else { 756 ubasic_error = UBASIC_E_UNK_KEY; 757 } 758 } 759 760 void camera_shoot() 761 { 762 action_push(AS_SHOOT); 763 } 764 765 void camera_sleep(long v) 766 { 767 action_push_delay(v); 768 } 769 770 void camera_wait_click(int t) 771 { 772 action_wait_for_click(t); 773 } 774 #endif 775 776 #endif 698 static const struct Keynames { 699 int keyid; 700 char *keyname; 701 } keynames[] = { 702 { KEY_UP, "up" }, 703 { KEY_DOWN, "down" }, 704 { KEY_LEFT, "left" }, 705 { KEY_RIGHT, "right" }, 706 { KEY_SET, "set" }, 707 { KEY_SHOOT_HALF, "shoot_half" }, 708 { KEY_SHOOT_FULL, "shoot_full" }, 709 { KEY_ZOOM_IN, "zoom_in" }, 710 { KEY_ZOOM_OUT, "zoom_out" }, 711 { KEY_MENU, "menu" }, 712 { KEY_DISPLAY, "display" }, 713 { KEY_PRINT, "print" }, 714 { KEY_ERASE, "erase" }, 715 { KEY_ISO, "iso" }, 716 { KEY_FLASH, "flash" }, 717 { KEY_MF, "mf" }, 718 { KEY_MACRO, "macro" }, 719 { KEY_VIDEO, "video" }, 720 { KEY_TIMER, "timer" }, 721 { KEY_EXPO_CORR, "expo_corr" }, 722 { KEY_MICROPHONE, "fe" }, 723 { KEY_ZOOM_ASSIST, "zoom_assist"}, 724 { KEY_AE_LOCK, "ae_lock" }, 725 { KEY_METERING, "metering_mode"}, 726 { 0xFF, "remote" }, 727 { 0xFFFF, "no_key" }, 728 }; 729 730 int script_keyid_by_name (const char *n) 731 { 732 int i; 733 for (i=0;i<sizeof(keynames)/sizeof(keynames[0]);i++) 734 if (strcmp(keynames[i].keyname,n) == 0) 735 return keynames[i].keyid; 736 return 0; 737 } 738 -
trunk/include/script.h
r1034 r1036 38 38 long script_start_gui( int autostart ); 39 39 40 int script_key_is_pressed( int keyid ); 41 int script_key_is_clicked( int keyid ); 42 int script_keyid_by_name( const char *name ); 40 43 #ifdef OPT_LUA 41 44 long script_start_ptp( char *script , int keep_result ); -
trunk/lib/ubasic/camera_functions.c
r1020 r1036 9 9 int zoom_points = 3; 10 10 #define MODE_REC 0x0100 11 12 void camera_press(const char *s) 13 { 14 printf("*** button press '%s' ***\n",s); 15 } 16 17 void camera_release(const char *s) 18 { 19 printf("*** button release '%s' ***\n",s); 20 } 21 22 void camera_click(const char *s) 23 { 24 printf("*** button click '%s' ***\n",s); 25 } 26 27 void camera_sleep(int v) 11 #define AS_SHOOT 1 12 int script_keyid_by_name(const char *s) { 13 return 1; 14 } 15 16 void console_set_autoredraw(int n) { 17 printf("*** console_set_auto_redraw %d ***\n",n); 18 } 19 20 void action_push_press(int k) 21 { 22 printf("*** button press %d ***\n",k); 23 } 24 25 void action_push_release(int k) 26 { 27 printf("*** button release %d ***\n",k); 28 } 29 30 void action_push_click(int k) 31 { 32 printf("*** button click %d ***\n",k); 33 } 34 35 void action_push_delay(int v) 28 36 { 29 37 printf("*** sleep %d ***\n",v); 30 38 } 31 39 32 void camera_shoot() 33 { 34 printf("*** shoot ***\n"); 35 } 36 37 void camera_wait_click(int t) 40 void action_push(int id) 41 { 42 if(id == AS_SHOOT) 43 printf("*** shoot ***\n"); 44 else 45 printf("*** action_push(%d) ***\n",id); 46 } 47 48 void action_wait_for_click(int t) 38 49 { 39 50 printf("*** wait_click %d ***\n", t); 40 51 } 41 52 42 int camera_is_clicked(const char *s)43 { 44 printf("*** is_ key '%s' ***\n", s);53 int script_key_is_clicked(int k) 54 { 55 printf("*** is_clicked %d ***\n", k); 45 56 return 1; 46 57 } … … 137 148 } 138 149 139 /*140 150 void script_console_set_autoredraw(int value) { 141 151 printf(">>> set console auto_redraw to %d\n", value); 142 152 } 143 */144 153 145 154 void console_redraw() { … … 441 450 442 451 443 int camera_is_pressed(const char *v)444 { 445 printf("*** camera_is_pressed %s ***\n", v);452 int script_key_is_pressed(const char *v) 453 { 454 printf("*** script_key_is_pressed %s ***\n", v); 446 455 return 0; 447 456 } -
trunk/lib/ubasic/camera_functions.h
r1020 r1036 1 /* 2 header for building ubasic_test.exe, 3 contains prototypes for functions that would be 4 inconvenient to get from real header files 5 see dummy functions in camera_functions.c 6 */ 7 int script_key_is_clicked(int keyid); 8 int script_key_is_pressed(int keyid); 1 9 2 void camera_press(const char *s); 3 void camera_release(const char *s); 4 void camera_wait_click(int timeout); 5 int camera_is_pressed(const char *s); 6 int camera_is_clicked(const char *s); 7 void camera_click(const char *s); 10 int camera_is_pressed(int i); 11 int camera_is_clicked(int i); 8 12 void camera_sleep(long v); 9 13 void camera_shoot(); -
trunk/lib/ubasic/ubasic.c
r1020 r1036 47 47 #include <io.h> 48 48 #include <stdlib.h> /* rand,srand */ 49 #include "camera_functions.h" 49 50 #else 50 51 #include "ubasic.h" … … 56 57 #include "levent.h" 57 58 #include "console.h" 59 #include "../../core/motion_detector.h" 58 60 #endif 61 #include "../../core/action_stack.h" 59 62 #include "tokenizer.h" 60 63 … … 62 65 #include "../../include/conf.h" 63 66 64 #include "camera_functions.h"65 67 66 68 … … 162 164 } 163 165 /*---------------------------------------------------------------------------*/ 166 // read a key name and return key id, 167 // set error and return 0 if key invalid 168 static int ubasic_get_key_arg() { 169 int k; 170 tokenizer_string(string, sizeof(string)); 171 tokenizer_next(); 172 k = script_keyid_by_name(string); 173 if (k <= 0) 174 ubasic_error = UBASIC_E_UNK_KEY; 175 return k; 176 } 177 /*---------------------------------------------------------------------------*/ 164 178 static void 165 179 accept(int token) … … 252 266 case TOKENIZER_IS_KEY: 253 267 accept(TOKENIZER_IS_KEY); 254 tokenizer_string(string, sizeof(string)); 255 tokenizer_next(); 256 r = camera_is_clicked(string); 268 r = script_key_is_clicked(ubasic_get_key_arg()); 257 269 break; 258 270 case TOKENIZER_SCRIPT_AUTOSTARTED: … … 278 290 case TOKENIZER_IS_PRESSED: 279 291 accept(TOKENIZER_IS_PRESSED); 280 tokenizer_string(string, sizeof(string)); 281 tokenizer_next(); 282 r = camera_is_pressed(string); 292 r = script_key_is_pressed(ubasic_get_key_arg()); 283 293 break; 284 294 case TOKENIZER_RANDOM: … … 286 296 int min = expr(); 287 297 int max = expr(); 298 // shouldn't srand every time... 288 299 srand((int)shooting_get_bv96()+(unsigned short)stat_get_vbatt()+get_tick_count()); 289 camera_sleep(rand()%10); 300 // wtf 301 action_push_delay(rand()%10); 290 302 r = min + rand()%(max-min+1); 291 303 break; … … 1422 1434 click_statement(void) 1423 1435 { 1424 accept(TOKENIZER_CLICK);1425 tokenizer_string(string, sizeof(string));1426 camera_click(string);1427 tokenizer_next(); 1436 int k = ubasic_get_key_arg(); 1437 if (k > 0) 1438 action_push_click(k); 1439 1428 1440 DEBUG_PRINTF("End of click\n"); 1429 1441 accept_cr(); … … 1433 1445 press_statement(void) 1434 1446 { 1435 accept(TOKENIZER_PRESS); 1436 tokenizer_string(string, sizeof(string)); 1437 camera_press(string); 1438 tokenizer_next(); 1447 int k = ubasic_get_key_arg(); 1448 if (k > 0) 1449 action_push_press(k); 1439 1450 DEBUG_PRINTF("End of press\n"); 1440 1451 accept_cr(); … … 1444 1455 release_statement(void) 1445 1456 { 1446 accept(TOKENIZER_RELEASE); 1447 tokenizer_string(string, sizeof(string)); 1448 camera_release(string); 1449 tokenizer_next(); 1457 int k = ubasic_get_key_arg(); 1458 if (k > 0) 1459 action_push_release(k); 1450 1460 DEBUG_PRINTF("End of release\n"); 1451 1461 accept_cr(); … … 1458 1468 accept(TOKENIZER_SLEEP); 1459 1469 val = expr(); 1460 camera_sleep(val);1470 action_push_delay(val); 1461 1471 DEBUG_PRINTF("End of sleep\n"); 1462 1472 accept_cr(); … … 1467 1477 { 1468 1478 accept(TOKENIZER_SHOOT); 1469 camera_shoot();1479 action_push(AS_SHOOT); 1470 1480 DEBUG_PRINTF("End of shoot\n"); 1471 1481 accept_cr(); … … 2115 2125 timeout = expr(); 2116 2126 } 2117 camera_wait_click(timeout);2127 action_wait_for_click(timeout); 2118 2128 accept_cr(); 2119 2129 } … … 2125 2135 var = tokenizer_variable_num(); 2126 2136 accept(TOKENIZER_VARIABLE); 2127 tokenizer_string(string, sizeof(string)); 2128 tokenizer_next(); 2129 ubasic_set_variable(var, camera_is_clicked(string)); 2137 ubasic_set_variable(var, script_key_is_clicked(ubasic_get_key_arg())); 2130 2138 DEBUG_PRINTF("End of is_key\n"); 2131 2139 accept_cr(); … … 2711 2719 return; 2712 2720 } 2721 2713 2722 /*---------------------------------------------------------------------------*/ 2714 2723 void
Note: See TracChangeset
for help on using the changeset viewer.