| 1 | #include "kbd.h" |
|---|
| 2 | #include "stdlib.h" |
|---|
| 3 | #include "platform.h" |
|---|
| 4 | #include "core.h" |
|---|
| 5 | #include "keyboard.h" |
|---|
| 6 | #include "conf.h" |
|---|
| 7 | #include "camera.h" |
|---|
| 8 | #include "lang.h" |
|---|
| 9 | #include "ubasic.h" |
|---|
| 10 | #include "histogram.h" |
|---|
| 11 | #include "script.h" |
|---|
| 12 | #include "gui_lang.h" |
|---|
| 13 | #include "motion_detector.h" |
|---|
| 14 | #include "lua.h" |
|---|
| 15 | #include "lualib.h" |
|---|
| 16 | #include "lauxlib.h" |
|---|
| 17 | #include "luascript.h" |
|---|
| 18 | #include "../lib/lua/lstate.h" // for L->nCcalls, baseCcalls |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | #define SCRIPT_END 0 |
|---|
| 22 | #define SCRIPT_CLICK 1 |
|---|
| 23 | #define SCRIPT_SHOOT 2 |
|---|
| 24 | #define SCRIPT_SLEEP 3 |
|---|
| 25 | #define SCRIPT_PRESS 4 |
|---|
| 26 | #define SCRIPT_RELEASE 5 |
|---|
| 27 | #define SCRIPT_PR_WAIT_SAVE 6 |
|---|
| 28 | #define SCRIPT_WAIT_SAVE 7 |
|---|
| 29 | #define SCRIPT_WAIT_FLASH 8 |
|---|
| 30 | #define SCRIPT_WAIT_EXPHIST 9 |
|---|
| 31 | #define SCRIPT_PR_WAIT_EXPHIST 10 |
|---|
| 32 | #define SCRIPT_WAIT_CLICK 11 |
|---|
| 33 | #define SCRIPT_MOTION_DETECTOR 12 |
|---|
| 34 | |
|---|
| 35 | #define KBD_STACK_SIZE 24 |
|---|
| 36 | |
|---|
| 37 | static long kbd_int_stack[KBD_STACK_SIZE]; |
|---|
| 38 | static int kbd_int_stack_ptr; |
|---|
| 39 | |
|---|
| 40 | #define KBD_STACK_PUSH(v) kbd_int_stack[kbd_int_stack_ptr++] = (v); |
|---|
| 41 | #define KBD_STACK_PREV(p) (kbd_int_stack[kbd_int_stack_ptr-(p)]) |
|---|
| 42 | |
|---|
| 43 | static int kbd_blocked; |
|---|
| 44 | static int key_pressed; |
|---|
| 45 | int state_kbd_script_run; |
|---|
| 46 | static long delay_target_ticks; |
|---|
| 47 | static long kbd_last_clicked; |
|---|
| 48 | |
|---|
| 49 | // ------ add by Masuji SUTO (start) -------------- |
|---|
| 50 | static int mvideo,mplay; |
|---|
| 51 | static int nSW=0; |
|---|
| 52 | static int nRmt=0; |
|---|
| 53 | static int nWt=0; |
|---|
| 54 | static int nCount=0; |
|---|
| 55 | static int nCa=0; |
|---|
| 56 | static int nCount2=0; |
|---|
| 57 | static int nTxvideo=0; |
|---|
| 58 | static int nTxzoom=0; |
|---|
| 59 | static int nTxzname=KEY_ZOOM_IN; |
|---|
| 60 | static int nPlyname=KEY_LEFT; |
|---|
| 61 | static int nIntzpos; |
|---|
| 62 | static int nReczoom=0; |
|---|
| 63 | static int nTxtblcr=0; |
|---|
| 64 | int shutter_int=0; |
|---|
| 65 | |
|---|
| 66 | #if defined(CAMERA_a450) || defined(CAMERA_ixus50_sd400) || defined(CAMERA_ixus55_sd450) || defined(CAMERA_ixus60_sd600) || defined(CAMERA_ixus65_sd630) || defined(CAMERA_ixus70_sd1000) || defined(CAMERA_ixus700_sd500) || defined(CAMERA_ixus750_sd550) || defined(CAMERA_ixus850_sd800) |
|---|
| 67 | #define ZSTEP_TABLE_SIZE 7 |
|---|
| 68 | static int nTxtbl[]={0,1,2,3,4,5,6}; |
|---|
| 69 | #endif |
|---|
| 70 | |
|---|
| 71 | #if defined(CAMERA_s2is) || defined(CAMERA_s3is) || defined(CAMERA_s5is) |
|---|
| 72 | #define ZSTEP_TABLE_SIZE 8 |
|---|
| 73 | static int nTxtbl[]={0,11,25,41,64,86,105,128}; |
|---|
| 74 | #endif |
|---|
| 75 | |
|---|
| 76 | #if defined(CAMERA_tx1) |
|---|
| 77 | #define ZSTEP_TABLE_SIZE 8 |
|---|
| 78 | static int nTxtbl[]={0,18,43,55,76,93,113,124}; |
|---|
| 79 | #endif |
|---|
| 80 | |
|---|
| 81 | #if defined(CAMERA_a460) || defined(CAMERA_a530) || defined (CAMERA_a540) || defined(CAMERA_a550) || defined(CAMERA_a560) || defined(CAMERA_a570) || defined(CAMERA_ixus860_sd870) |
|---|
| 82 | #define ZSTEP_TABLE_SIZE 8 |
|---|
| 83 | static int nTxtbl[]={0,1,2,3,4,5,6,7}; |
|---|
| 84 | #endif |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | #if defined(CAMERA_a610) || defined(CAMERA_a620) || defined(CAMERA_a630) || defined(CAMERA_a640) || defined(CAMERA_ixus800_sd700) || defined(CAMERA_ixus950_sd850) |
|---|
| 88 | #define ZSTEP_TABLE_SIZE 9 |
|---|
| 89 | static int nTxtbl[]={0,1,2,3,4,5,6,7,8}; |
|---|
| 90 | #endif |
|---|
| 91 | |
|---|
| 92 | #if defined (CAMERA_a700) || defined(CAMERA_a710) || defined (CAMERA_a720) |
|---|
| 93 | #define ZSTEP_TABLE_SIZE 8 |
|---|
| 94 | static int nTxtbl[]={0,2,4,6,8,10,12,14}; |
|---|
| 95 | #endif |
|---|
| 96 | |
|---|
| 97 | #if defined(CAMERA_a650) || defined(CAMERA_g7) |
|---|
| 98 | #define ZSTEP_TABLE_SIZE 8 |
|---|
| 99 | static int nTxtbl[]={0,2,4,6,8,10,12,13}; |
|---|
| 100 | #endif |
|---|
| 101 | // ------ add by Masuji SUTO (end) -------------- |
|---|
| 102 | #if defined(CAMERA_sx100is) |
|---|
| 103 | #define ZSTEP_TABLE_SIZE 8 |
|---|
| 104 | static int nTxtbl[]={0,3,6,9,13,16,20,23}; |
|---|
| 105 | #endif |
|---|
| 106 | |
|---|
| 107 | void kbd_sched_delay(long msec) |
|---|
| 108 | { |
|---|
| 109 | KBD_STACK_PUSH(msec); |
|---|
| 110 | KBD_STACK_PUSH(SCRIPT_SLEEP); |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | void kbd_sched_motion_detector(){ |
|---|
| 115 | KBD_STACK_PUSH(SCRIPT_MOTION_DETECTOR); |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | void kbd_sched_press(long key) |
|---|
| 119 | { |
|---|
| 120 | // WARNING stack program flow is reversed |
|---|
| 121 | kbd_sched_delay(20); |
|---|
| 122 | |
|---|
| 123 | KBD_STACK_PUSH(key); |
|---|
| 124 | KBD_STACK_PUSH(SCRIPT_PRESS); |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | void kbd_sched_release(long key) |
|---|
| 128 | { |
|---|
| 129 | // WARNING stack program flow is reversed |
|---|
| 130 | kbd_sched_delay(20); |
|---|
| 131 | |
|---|
| 132 | KBD_STACK_PUSH(key); |
|---|
| 133 | KBD_STACK_PUSH(SCRIPT_RELEASE); |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | void md_kbd_sched_immediate_shoot(int no_release) |
|---|
| 137 | { |
|---|
| 138 | kbd_int_stack_ptr-=1;// REMOVE MD ITEM |
|---|
| 139 | |
|---|
| 140 | // stack operations are reversed! |
|---|
| 141 | if (!no_release) // only release shutter if allowed |
|---|
| 142 | { |
|---|
| 143 | kbd_sched_release(KEY_SHOOT_FULL); |
|---|
| 144 | kbd_sched_delay(20); |
|---|
| 145 | } |
|---|
| 146 | KBD_STACK_PUSH(SCRIPT_MOTION_DETECTOR); // it will removed right after exit from this function |
|---|
| 147 | kbd_key_press(KEY_SHOOT_FULL); // not a stack operation... pressing right now |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | void kbd_sched_click(long key) |
|---|
| 152 | { |
|---|
| 153 | // WARNING stack program flow is reversed |
|---|
| 154 | kbd_sched_release(key); |
|---|
| 155 | kbd_sched_press(key); |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | static void kbd_sched_wait_click(int timeout) |
|---|
| 159 | { |
|---|
| 160 | // WARNING stack program flow is reversed |
|---|
| 161 | KBD_STACK_PUSH(timeout); |
|---|
| 162 | KBD_STACK_PUSH(SCRIPT_WAIT_CLICK); |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | void kbd_sched_shoot() |
|---|
| 166 | { |
|---|
| 167 | // WARNING stack program flow is reversed |
|---|
| 168 | |
|---|
| 169 | kbd_sched_delay(conf.script_shoot_delay*100);// XXX FIXME find out how to wait to jpeg save finished |
|---|
| 170 | |
|---|
| 171 | KBD_STACK_PUSH(SCRIPT_WAIT_SAVE); |
|---|
| 172 | |
|---|
| 173 | KBD_STACK_PUSH(KEY_SHOOT_FULL); |
|---|
| 174 | KBD_STACK_PUSH(SCRIPT_RELEASE); |
|---|
| 175 | |
|---|
| 176 | kbd_sched_delay(20); |
|---|
| 177 | |
|---|
| 178 | KBD_STACK_PUSH(KEY_SHOOT_FULL); |
|---|
| 179 | KBD_STACK_PUSH(SCRIPT_PRESS); |
|---|
| 180 | |
|---|
| 181 | KBD_STACK_PUSH(SCRIPT_WAIT_FLASH); |
|---|
| 182 | KBD_STACK_PUSH(SCRIPT_WAIT_EXPHIST); |
|---|
| 183 | KBD_STACK_PUSH(SCRIPT_PR_WAIT_EXPHIST); |
|---|
| 184 | |
|---|
| 185 | kbd_sched_delay(10); |
|---|
| 186 | |
|---|
| 187 | KBD_STACK_PUSH(KEY_SHOOT_HALF); |
|---|
| 188 | KBD_STACK_PUSH(SCRIPT_PRESS); |
|---|
| 189 | |
|---|
| 190 | KBD_STACK_PUSH(SCRIPT_PR_WAIT_SAVE); |
|---|
| 191 | |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | static lua_State* L, *Lt; |
|---|
| 195 | |
|---|
| 196 | static int is_lua() |
|---|
| 197 | { |
|---|
| 198 | int len; |
|---|
| 199 | char const* s; |
|---|
| 200 | s = conf.script_file; |
|---|
| 201 | len = strlen( s ); |
|---|
| 202 | return len >= 4 && ( s[len-1] == 'a' || s[len-1] == 'A' ) |
|---|
| 203 | && ( s[len-2] == 'u' || s[len-2] == 'U' ) |
|---|
| 204 | && ( s[len-3] == 'l' || s[len-3] == 'L' ) |
|---|
| 205 | && s[len-4] == '.'; |
|---|
| 206 | } |
|---|
| 207 | |
|---|
| 208 | static void lua_count_hook(lua_State *L, lua_Debug *ar) |
|---|
| 209 | { |
|---|
| 210 | if( L->nCcalls <= L->baseCcalls ) |
|---|
| 211 | lua_yield( L, 0 ); |
|---|
| 212 | } |
|---|
| 213 | |
|---|
| 214 | static int lua_script_start( char const* script ) |
|---|
| 215 | { |
|---|
| 216 | L = lua_open(); |
|---|
| 217 | luaL_openlibs( L ); |
|---|
| 218 | register_lua_funcs( L ); |
|---|
| 219 | |
|---|
| 220 | Lt = lua_newthread( L ); |
|---|
| 221 | lua_setfield( L, LUA_REGISTRYINDEX, "Lt" ); |
|---|
| 222 | if( luaL_loadstring( Lt, script ) != 0 ) { |
|---|
| 223 | script_console_add_line( lua_tostring( Lt, -1 ) ); |
|---|
| 224 | lua_close( L ); |
|---|
| 225 | L = 0; |
|---|
| 226 | Lt = 0; |
|---|
| 227 | return 0; |
|---|
| 228 | } |
|---|
| 229 | lua_sethook(Lt, lua_count_hook, LUA_MASKCOUNT, 1000 ); |
|---|
| 230 | return 1; |
|---|
| 231 | } |
|---|
| 232 | |
|---|
| 233 | |
|---|
| 234 | static void script_start( int autostart ) |
|---|
| 235 | { |
|---|
| 236 | int i; |
|---|
| 237 | |
|---|
| 238 | shot_histogram_enabled = 0; |
|---|
| 239 | if (autostart) auto_started = 1; else auto_started = 0; |
|---|
| 240 | delay_target_ticks = 0; |
|---|
| 241 | kbd_int_stack_ptr = 0; |
|---|
| 242 | kbd_last_clicked = 0; |
|---|
| 243 | /*if (!autostart)*/ kbd_key_release_all(); |
|---|
| 244 | |
|---|
| 245 | script_console_clear(); |
|---|
| 246 | script_print_screen_init(); |
|---|
| 247 | |
|---|
| 248 | save_params_values(0); |
|---|
| 249 | |
|---|
| 250 | if( autostart ) |
|---|
| 251 | script_console_add_line("***Autostart***"); |
|---|
| 252 | else |
|---|
| 253 | script_console_add_line(lang_str(LANG_CONSOLE_TEXT_STARTED)); |
|---|
| 254 | |
|---|
| 255 | if( is_lua() ) { |
|---|
| 256 | |
|---|
| 257 | if( !lua_script_start(state_ubasic_script) ) { |
|---|
| 258 | script_print_screen_end(); |
|---|
| 259 | return; |
|---|
| 260 | } |
|---|
| 261 | for (i=0; i<SCRIPT_NUM_PARAMS; ++i) { |
|---|
| 262 | if( script_params[i][0] ) { |
|---|
| 263 | char var = 'a'+i; |
|---|
| 264 | lua_pushlstring( L, &var, 1 ); |
|---|
| 265 | lua_pushnumber( L, conf.ubasic_vars[i] ); |
|---|
| 266 | lua_settable( L, LUA_GLOBALSINDEX ); |
|---|
| 267 | } |
|---|
| 268 | } |
|---|
| 269 | } |
|---|
| 270 | else { |
|---|
| 271 | ubasic_init(state_ubasic_script); |
|---|
| 272 | |
|---|
| 273 | for (i=0; i<SCRIPT_NUM_PARAMS; ++i) { |
|---|
| 274 | ubasic_set_variable(i, conf.ubasic_vars[i]); |
|---|
| 275 | } |
|---|
| 276 | } |
|---|
| 277 | |
|---|
| 278 | state_kbd_script_run = 1; |
|---|
| 279 | |
|---|
| 280 | if (conf.alt_prevent_shutdown != ALT_PREVENT_SHUTDOWN_ALT_SCRIPT) { |
|---|
| 281 | enable_shutdown(); |
|---|
| 282 | } |
|---|
| 283 | } |
|---|
| 284 | |
|---|
| 285 | void script_end() |
|---|
| 286 | { |
|---|
| 287 | script_print_screen_end(); |
|---|
| 288 | if( L ) { |
|---|
| 289 | lua_close( L ); |
|---|
| 290 | L = 0; |
|---|
| 291 | Lt = 0; |
|---|
| 292 | } |
|---|
| 293 | else { |
|---|
| 294 | ubasic_end(); |
|---|
| 295 | } |
|---|
| 296 | |
|---|
| 297 | if (conf.alt_prevent_shutdown != ALT_PREVENT_SHUTDOWN_NO) { |
|---|
| 298 | disable_shutdown(); |
|---|
| 299 | } |
|---|
| 300 | kbd_key_release_all(); |
|---|
| 301 | state_kbd_script_run = 0; |
|---|
| 302 | vid_bitmap_refresh(); |
|---|
| 303 | } |
|---|
| 304 | |
|---|
| 305 | void process_script() |
|---|
| 306 | { |
|---|
| 307 | long t; |
|---|
| 308 | int Lres; |
|---|
| 309 | |
|---|
| 310 | // process stack operations |
|---|
| 311 | if (kbd_int_stack_ptr){ |
|---|
| 312 | switch (KBD_STACK_PREV(1)){ |
|---|
| 313 | |
|---|
| 314 | case SCRIPT_MOTION_DETECTOR: |
|---|
| 315 | if(md_detect_motion()==0){ |
|---|
| 316 | kbd_int_stack_ptr-=1; |
|---|
| 317 | } |
|---|
| 318 | return; |
|---|
| 319 | |
|---|
| 320 | case SCRIPT_PRESS: |
|---|
| 321 | kbd_key_press(KBD_STACK_PREV(2)); |
|---|
| 322 | kbd_int_stack_ptr-=2; // pop op. |
|---|
| 323 | return; |
|---|
| 324 | case SCRIPT_RELEASE: |
|---|
| 325 | kbd_key_release(KBD_STACK_PREV(2)); |
|---|
| 326 | kbd_int_stack_ptr-=2; // pop op. |
|---|
| 327 | return; |
|---|
| 328 | case SCRIPT_SLEEP: |
|---|
| 329 | t = get_tick_count(); |
|---|
| 330 | // FIXME take care if overflow occurs |
|---|
| 331 | if (delay_target_ticks == 0){ |
|---|
| 332 | /* setup timer */ |
|---|
| 333 | delay_target_ticks = t+KBD_STACK_PREV(2); |
|---|
| 334 | } else { |
|---|
| 335 | if (delay_target_ticks <= t){ |
|---|
| 336 | delay_target_ticks = 0; |
|---|
| 337 | kbd_int_stack_ptr-=2; // pop sleep op. |
|---|
| 338 | } |
|---|
| 339 | } |
|---|
| 340 | return; |
|---|
| 341 | case SCRIPT_PR_WAIT_SAVE: |
|---|
| 342 | state_shooting_progress = SHOOTING_PROGRESS_NONE; |
|---|
| 343 | state_expos_recalculated = 0; |
|---|
| 344 | histogram_stop(); |
|---|
| 345 | |
|---|
| 346 | kbd_int_stack_ptr-=1; // pop op. |
|---|
| 347 | return; |
|---|
| 348 | case SCRIPT_WAIT_SAVE:{ |
|---|
| 349 | if (state_shooting_progress == SHOOTING_PROGRESS_DONE) |
|---|
| 350 | kbd_int_stack_ptr-=1; // pop op. |
|---|
| 351 | return; |
|---|
| 352 | } |
|---|
| 353 | case SCRIPT_WAIT_FLASH:{ |
|---|
| 354 | if (shooting_is_flash_ready()) |
|---|
| 355 | kbd_int_stack_ptr-=1; // pop op. |
|---|
| 356 | return; |
|---|
| 357 | } |
|---|
| 358 | case SCRIPT_WAIT_EXPHIST:{ |
|---|
| 359 | if (state_expos_recalculated) { |
|---|
| 360 | kbd_int_stack_ptr-=1; // pop op. |
|---|
| 361 | state_expos_under = under_exposed; |
|---|
| 362 | state_expos_over = over_exposed; |
|---|
| 363 | } |
|---|
| 364 | return; |
|---|
| 365 | } |
|---|
| 366 | case SCRIPT_PR_WAIT_EXPHIST: { |
|---|
| 367 | if (shooting_in_progress() || mvideo) { |
|---|
| 368 | state_expos_recalculated = 0; |
|---|
| 369 | histogram_restart(); |
|---|
| 370 | kbd_int_stack_ptr-=1; // pop op. |
|---|
| 371 | } |
|---|
| 372 | return; |
|---|
| 373 | } |
|---|
| 374 | case SCRIPT_WAIT_CLICK: { |
|---|
| 375 | t = get_tick_count(); |
|---|
| 376 | if (delay_target_ticks == 0){ |
|---|
| 377 | /* setup timer */ |
|---|
| 378 | delay_target_ticks = t+((KBD_STACK_PREV(2))?KBD_STACK_PREV(2):86400000); |
|---|
| 379 | } else { |
|---|
| 380 | kbd_last_clicked = kbd_get_clicked_key(); |
|---|
| 381 | if (kbd_last_clicked || delay_target_ticks <= t) { |
|---|
| 382 | if (!kbd_last_clicked) |
|---|
| 383 | kbd_last_clicked=0xFFFF; |
|---|
| 384 | delay_target_ticks = 0; |
|---|
| 385 | kbd_int_stack_ptr-=2; // pop op. |
|---|
| 386 | } |
|---|
| 387 | } |
|---|
| 388 | return; |
|---|
| 389 | } |
|---|
| 390 | default: |
|---|
| 391 | /*finished();*/ |
|---|
| 392 | script_end(); |
|---|
| 393 | } |
|---|
| 394 | } |
|---|
| 395 | |
|---|
| 396 | if( L ) { |
|---|
| 397 | Lres = lua_resume( Lt, 0 ); |
|---|
| 398 | |
|---|
| 399 | if (Lres != LUA_YIELD && Lres != 0) { |
|---|
| 400 | script_console_add_line( lua_tostring( Lt, -1 ) ); |
|---|
| 401 | } |
|---|
| 402 | |
|---|
| 403 | if (Lres != LUA_YIELD) { |
|---|
| 404 | script_console_add_line(lang_str(LANG_CONSOLE_TEXT_FINISHED)); |
|---|
| 405 | script_end(); |
|---|
| 406 | } |
|---|
| 407 | } |
|---|
| 408 | else { |
|---|
| 409 | ubasic_run(); |
|---|
| 410 | if (ubasic_finished()) { |
|---|
| 411 | script_console_add_line(lang_str(LANG_CONSOLE_TEXT_FINISHED)); |
|---|
| 412 | script_end(); |
|---|
| 413 | } |
|---|
| 414 | } |
|---|
| 415 | } |
|---|
| 416 | |
|---|
| 417 | void ubasic_camera_press(const char *s) |
|---|
| 418 | { |
|---|
| 419 | long k = keyid_by_name(s); |
|---|
| 420 | if (k > 0) { |
|---|
| 421 | kbd_sched_press(k); |
|---|
| 422 | } else { |
|---|
| 423 | ubasic_error = 3; |
|---|
| 424 | } |
|---|
| 425 | } |
|---|
| 426 | |
|---|
| 427 | void ubasic_camera_release(const char *s) |
|---|
| 428 | { |
|---|
| 429 | long k = keyid_by_name(s); |
|---|
| 430 | if (k > 0) { |
|---|
| 431 | kbd_sched_release(k); |
|---|
| 432 | } else { |
|---|
| 433 | ubasic_error = 3; |
|---|
| 434 | } |
|---|
| 435 | } |
|---|
| 436 | |
|---|
| 437 | void ubasic_camera_click(const char *s) |
|---|
| 438 | { |
|---|
| 439 | long k = keyid_by_name(s); |
|---|
| 440 | if (k > 0) { |
|---|
| 441 | kbd_sched_click(k); |
|---|
| 442 | } else { |
|---|
| 443 | ubasic_error = 3; |
|---|
| 444 | } |
|---|
| 445 | } |
|---|
| 446 | |
|---|
| 447 | void ubasic_camera_wait_click(int timeout) |
|---|
| 448 | { |
|---|
| 449 | kbd_sched_wait_click(timeout); |
|---|
| 450 | } |
|---|
| 451 | |
|---|
| 452 | int ubasic_camera_is_pressed(const char *s) |
|---|
| 453 | { |
|---|
| 454 | long k = keyid_by_name(s); |
|---|
| 455 | if (k==0xFF) return get_usb_power(1); |
|---|
| 456 | if (k > 0) { |
|---|
| 457 | return (kbd_is_key_pressed(k)); |
|---|
| 458 | } else { |
|---|
| 459 | ubasic_error = 3; |
|---|
| 460 | } |
|---|
| 461 | return 0; |
|---|
| 462 | } |
|---|
| 463 | |
|---|
| 464 | int ubasic_camera_is_clicked(const char *s) |
|---|
| 465 | { |
|---|
| 466 | long k = keyid_by_name(s); |
|---|
| 467 | if (k==0xFF) return get_usb_power(1); |
|---|
| 468 | if (k > 0) { |
|---|
| 469 | return (kbd_last_clicked == k); |
|---|
| 470 | } else { |
|---|
| 471 | ubasic_error = 3; |
|---|
| 472 | } |
|---|
| 473 | return 0; |
|---|
| 474 | } |
|---|
| 475 | |
|---|
| 476 | void ubasic_camera_sleep(long v) |
|---|
| 477 | { |
|---|
| 478 | kbd_sched_delay(v); |
|---|
| 479 | } |
|---|
| 480 | |
|---|
| 481 | void ubasic_camera_shoot() |
|---|
| 482 | { |
|---|
| 483 | kbd_sched_shoot(); |
|---|
| 484 | } |
|---|
| 485 | // remote autostart |
|---|
| 486 | void script_autostart() |
|---|
| 487 | { |
|---|
| 488 | kbd_blocked = 1; |
|---|
| 489 | gui_kbd_enter(); |
|---|
| 490 | script_console_clear(); |
|---|
| 491 | script_console_add_line("***Autostart***"); //lang_str(LANG_CONSOLE_TEXT_STARTED)); |
|---|
| 492 | script_start( 1 ); |
|---|
| 493 | } |
|---|
| 494 | void exit_alt() |
|---|
| 495 | { |
|---|
| 496 | kbd_blocked = 0; |
|---|
| 497 | gui_kbd_leave(); |
|---|
| 498 | } |
|---|
| 499 | |
|---|
| 500 | // ------ add by Masuji SUTO (start) -------------- |
|---|
| 501 | void set_key_press(int nSet) |
|---|
| 502 | { |
|---|
| 503 | key_pressed = nSet; |
|---|
| 504 | kbd_blocked = nSet; |
|---|
| 505 | nRmt = nSet; |
|---|
| 506 | } |
|---|
| 507 | // ------ add by Masuji SUTO (end) -------------- |
|---|
| 508 | |
|---|
| 509 | long kbd_process() |
|---|
| 510 | { |
|---|
| 511 | /* Alternative keyboard mode stated/exited by pressing print key. |
|---|
| 512 | * While running Alt. mode shoot key will start a script execution. |
|---|
| 513 | */ |
|---|
| 514 | static int nCER=0; |
|---|
| 515 | // ------ modif by Masuji SUTO (start) -------------- |
|---|
| 516 | |
|---|
| 517 | unsigned int mmode; |
|---|
| 518 | unsigned int nCrzpos,i; |
|---|
| 519 | unsigned int drmode; |
|---|
| 520 | |
|---|
| 521 | if(conf.ricoh_ca1_mode) |
|---|
| 522 | { |
|---|
| 523 | drmode = shooting_get_drive_mode(); |
|---|
| 524 | mmode = mode_get(); |
|---|
| 525 | mplay = (mmode&MODE_MASK)==MODE_PLAY; |
|---|
| 526 | mvideo= ((mmode&MODE_SHOOTING_MASK)==MODE_VIDEO_STD || (mmode&MODE_SHOOTING_MASK)==MODE_VIDEO_SPEED || (mmode&MODE_SHOOTING_MASK)==MODE_VIDEO_COMPACT ||(mmode&MODE_SHOOTING_MASK)==MODE_VIDEO_MY_COLORS || (mmode&MODE_SHOOTING_MASK)==MODE_VIDEO_COLOR_ACCENT); |
|---|
| 527 | } |
|---|
| 528 | // deals with alt-mode switch and delay emulation |
|---|
| 529 | if (key_pressed) |
|---|
| 530 | { |
|---|
| 531 | if (kbd_is_key_pressed(conf.alt_mode_button) || |
|---|
| 532 | ((key_pressed >= CAM_EMUL_KEYPRESS_DELAY) && |
|---|
| 533 | (key_pressed < CAM_EMUL_KEYPRESS_DELAY+CAM_EMUL_KEYPRESS_DURATION))) |
|---|
| 534 | { |
|---|
| 535 | if (key_pressed <= CAM_EMUL_KEYPRESS_DELAY+CAM_EMUL_KEYPRESS_DURATION) |
|---|
| 536 | key_pressed++; |
|---|
| 537 | if (key_pressed == CAM_EMUL_KEYPRESS_DELAY) |
|---|
| 538 | kbd_key_press(conf.alt_mode_button); |
|---|
| 539 | else if (key_pressed == +CAM_EMUL_KEYPRESS_DELAY+CAM_EMUL_KEYPRESS_DURATION) |
|---|
| 540 | kbd_key_release(conf.alt_mode_button); |
|---|
| 541 | return 1; |
|---|
| 542 | } else |
|---|
| 543 | if (kbd_get_pressed_key() == 0) |
|---|
| 544 | { |
|---|
| 545 | if (key_pressed != 100 && (key_pressed < CAM_EMUL_KEYPRESS_DELAY)) |
|---|
| 546 | { |
|---|
| 547 | kbd_blocked = 1-kbd_blocked; |
|---|
| 548 | if (kbd_blocked) gui_kbd_enter(); else gui_kbd_leave(); |
|---|
| 549 | } |
|---|
| 550 | key_pressed = 0; |
|---|
| 551 | return 1; |
|---|
| 552 | } |
|---|
| 553 | return 1; |
|---|
| 554 | } |
|---|
| 555 | |
|---|
| 556 | // auto iso shift |
|---|
| 557 | if (kbd_is_key_pressed(KEY_SHOOT_HALF) && kbd_is_key_pressed(conf.alt_mode_button)) return 0; |
|---|
| 558 | |
|---|
| 559 | if (kbd_is_key_pressed(conf.alt_mode_button)) |
|---|
| 560 | { |
|---|
| 561 | if (conf.ricoh_ca1_mode) conf.synch_enable=1; |
|---|
| 562 | key_pressed = 1; |
|---|
| 563 | kbd_key_release_all(); |
|---|
| 564 | return 1; |
|---|
| 565 | } |
|---|
| 566 | |
|---|
| 567 | // deals with the rest |
|---|
| 568 | if (kbd_blocked && nRmt==0) |
|---|
| 569 | { |
|---|
| 570 | if (kbd_is_key_pressed(KEY_SHOOT_FULL)) |
|---|
| 571 | { |
|---|
| 572 | key_pressed = 100; |
|---|
| 573 | if (!state_kbd_script_run) |
|---|
| 574 | { |
|---|
| 575 | script_start(0); |
|---|
| 576 | } else if (L || state_kbd_script_run == 2) |
|---|
| 577 | { |
|---|
| 578 | script_console_add_line(lang_str(LANG_CONSOLE_TEXT_INTERRUPTED)); |
|---|
| 579 | script_end(); |
|---|
| 580 | } else |
|---|
| 581 | { |
|---|
| 582 | state_kbd_script_run = 2; |
|---|
| 583 | if (jump_label("restore") == 0) |
|---|
| 584 | { |
|---|
| 585 | script_console_add_line(lang_str(LANG_CONSOLE_TEXT_INTERRUPTED)); |
|---|
| 586 | script_end(); |
|---|
| 587 | } |
|---|
| 588 | } |
|---|
| 589 | } |
|---|
| 590 | |
|---|
| 591 | if (state_kbd_script_run) |
|---|
| 592 | process_script(); else |
|---|
| 593 | gui_kbd_process(); |
|---|
| 594 | } else |
|---|
| 595 | { |
|---|
| 596 | |
|---|
| 597 | #ifndef SCRIPTLESS_REMOTE_NOT_ENABLED |
|---|
| 598 | if(conf.ricoh_ca1_mode) |
|---|
| 599 | { |
|---|
| 600 | |
|---|
| 601 | // ------ add by Masuji SUTO (start) -------------- |
|---|
| 602 | if(nWt>0) {nWt--;return 1;} |
|---|
| 603 | if (kbd_is_key_pressed(KEY_SHOOT_FULL)) conf.synch_enable=0; |
|---|
| 604 | if (kbd_is_key_pressed(KEY_SHOOT_HALF) && nTxzoom>0) { |
|---|
| 605 | nCount2=0; |
|---|
| 606 | nTxzoom=0; |
|---|
| 607 | nReczoom=0; |
|---|
| 608 | nTxvideo=0; |
|---|
| 609 | debug_led(0); |
|---|
| 610 | } |
|---|
| 611 | if (mplay && (kbd_is_key_pressed(KEY_LEFT) || kbd_is_key_pressed(KEY_RIGHT))){ |
|---|
| 612 | nPlyname=KEY_LEFT; |
|---|
| 613 | if(kbd_is_key_pressed(KEY_RIGHT)) nPlyname=KEY_RIGHT; |
|---|
| 614 | } |
|---|
| 615 | if (kbd_is_key_pressed(KEY_VIDEO)){ |
|---|
| 616 | nCount2=0; |
|---|
| 617 | nTxzoom=0; |
|---|
| 618 | nReczoom=0; |
|---|
| 619 | nTxvideo++; |
|---|
| 620 | if(nTxvideo<50){ |
|---|
| 621 | kbd_key_release_all(); |
|---|
| 622 | debug_led(1); |
|---|
| 623 | } |
|---|
| 624 | else { |
|---|
| 625 | debug_led(0); |
|---|
| 626 | return 0; |
|---|
| 627 | } |
|---|
| 628 | return 1; |
|---|
| 629 | } |
|---|
| 630 | else if(nTxvideo>49) nTxvideo=0; |
|---|
| 631 | if (kbd_is_key_pressed(KEY_ZOOM_IN) || kbd_is_key_pressed(KEY_ZOOM_OUT)){ |
|---|
| 632 | nCount2=0; |
|---|
| 633 | nTxvideo=0; |
|---|
| 634 | if(kbd_is_key_pressed(KEY_ZOOM_IN)) { |
|---|
| 635 | if(nTxzname==KEY_ZOOM_IN) nTxzoom++; |
|---|
| 636 | else nTxzoom=1; |
|---|
| 637 | nTxzname=KEY_ZOOM_IN; |
|---|
| 638 | } |
|---|
| 639 | else { |
|---|
| 640 | if(nTxzname==KEY_ZOOM_OUT) nTxzoom++; |
|---|
| 641 | else nTxzoom=1; |
|---|
| 642 | nTxzname=KEY_ZOOM_OUT; |
|---|
| 643 | } |
|---|
| 644 | if(nTxzoom<50){ |
|---|
| 645 | kbd_key_release_all(); |
|---|
| 646 | debug_led(1); |
|---|
| 647 | } |
|---|
| 648 | else { |
|---|
| 649 | debug_led(0); |
|---|
| 650 | return 0; |
|---|
| 651 | } |
|---|
| 652 | return 1; |
|---|
| 653 | } |
|---|
| 654 | if(!get_usb_power(1) && nSW<100 && nCount==0 && nTxzoom>0) { |
|---|
| 655 | nCount2++; |
|---|
| 656 | if(nCount2>1000){ |
|---|
| 657 | if(nTxzoom>0){ |
|---|
| 658 | nTxzoom=0; |
|---|
| 659 | nReczoom=0; |
|---|
| 660 | debug_led(0); |
|---|
| 661 | } |
|---|
| 662 | nCount2=0; |
|---|
| 663 | } |
|---|
| 664 | return 1; |
|---|
| 665 | } |
|---|
| 666 | if(get_usb_power(1) && nSW<100 && nCount==0) {nCount2=0;kbd_key_release_all();conf.synch_enable=1;} |
|---|
| 667 | |
|---|
| 668 | |
|---|
| 669 | if(get_usb_power(1) && nSW<100 && nCount==0) {kbd_key_release_all();conf.synch_enable=1;} |
|---|
| 670 | if(get_usb_power(1) && nSW<100 && nCount<6){ |
|---|
| 671 | nCount++; |
|---|
| 672 | return 1; |
|---|
| 673 | } |
|---|
| 674 | if(nCount>0 && nSW<100){ |
|---|
| 675 | if(mplay) { |
|---|
| 676 | if(get_usb_power(1)) return 1; |
|---|
| 677 | kbd_key_release_all(); |
|---|
| 678 | kbd_key_press(nPlyname); |
|---|
| 679 | set_key_press(1); |
|---|
| 680 | nCount=0; |
|---|
| 681 | nCa=2; |
|---|
| 682 | nSW=101; |
|---|
| 683 | nWt=5; |
|---|
| 684 | return 1; |
|---|
| 685 | } |
|---|
| 686 | if(nTxvideo>49) nTxvideo=0; |
|---|
| 687 | if(nCount<5) nCa=1; //for Richo remote switch CA-1 |
|---|
| 688 | else nCa=2; //for hand made remote switch |
|---|
| 689 | nCount=0; |
|---|
| 690 | // debug_led(1); |
|---|
| 691 | nSW=109; |
|---|
| 692 | } |
|---|
| 693 | |
|---|
| 694 | // ------------------------------------------------------------- hand made switch -------------- |
|---|
| 695 | |
|---|
| 696 | if(nCa==2){ |
|---|
| 697 | if(nSW==101){ |
|---|
| 698 | kbd_key_release_all(); |
|---|
| 699 | set_key_press(0); |
|---|
| 700 | nWt=50; |
|---|
| 701 | nSW=0; |
|---|
| 702 | nCa=0; |
|---|
| 703 | return 1; |
|---|
| 704 | } |
|---|
| 705 | if(nSW==109){ |
|---|
| 706 | // nSW=110; |
|---|
| 707 | nCER=0; |
|---|
| 708 | if(nTxzoom>0){ |
|---|
| 709 | if(nTxzoom<100){ |
|---|
| 710 | nIntzpos=lens_get_zoom_point(); |
|---|
| 711 | for(i=0;i<ZSTEP_TABLE_SIZE;i++){ |
|---|
| 712 | if(nIntzpos<=nTxtbl[i]){ |
|---|
| 713 | if(i>0){ |
|---|
| 714 | if(abs(nTxtbl[i]-nIntzpos)<=abs(nTxtbl[i-1]-nIntzpos)) nTxtblcr=i; |
|---|
| 715 | else nTxtblcr=i-1; |
|---|
| 716 | } |
|---|
| 717 | else nTxtblcr=i; |
|---|
| 718 | i=ZSTEP_TABLE_SIZE; |
|---|
| 719 | } |
|---|
| 720 | } |
|---|
| 721 | if(nTxzname==KEY_ZOOM_IN){ |
|---|
| 722 | nTxtblcr++; |
|---|
| 723 | if(nTxtblcr>(ZSTEP_TABLE_SIZE-1)) nTxtblcr=(ZSTEP_TABLE_SIZE-1); |
|---|
| 724 | } |
|---|
| 725 | else{ |
|---|
| 726 | nTxtblcr--; |
|---|
| 727 | if(nTxtblcr<0) nTxtblcr=0; |
|---|
| 728 | } |
|---|
| 729 | nSW=108; |
|---|
| 730 | return 1; |
|---|
| 731 | } |
|---|
| 732 | nTxzoom=0; |
|---|
| 733 | nReczoom=0; |
|---|
| 734 | } |
|---|
| 735 | if(nTxvideo>0) {nSW=121;return 1;} |
|---|
| 736 | nSW=110; |
|---|
| 737 | nWt=2; |
|---|
| 738 | kbd_key_release_all(); |
|---|
| 739 | kbd_key_press(KEY_SHOOT_HALF); |
|---|
| 740 | // key_pressed = 1; |
|---|
| 741 | // kbd_blocked = 1; |
|---|
| 742 | // nRmt=1; |
|---|
| 743 | set_key_press(1); |
|---|
| 744 | return 1; |
|---|
| 745 | } |
|---|
| 746 | if(nTxzoom>0 && nSW==108){ |
|---|
| 747 | nCrzpos=lens_get_zoom_point(); |
|---|
| 748 | if(nIntzpos!=nCrzpos) {nReczoom=0;} |
|---|
| 749 | if(nIntzpos==nCrzpos && nCER>50){ |
|---|
| 750 | if(!get_usb_power(1)){ |
|---|
| 751 | kbd_key_release_all(); |
|---|
| 752 | set_key_press(0); |
|---|
| 753 | nTxzoom=1; |
|---|
| 754 | nSW=0; |
|---|
| 755 | nCount=0; |
|---|
| 756 | nWt=10; |
|---|
| 757 | nReczoom=1; |
|---|
| 758 | return 1; |
|---|
| 759 | } |
|---|
| 760 | } |
|---|
| 761 | if(nReczoom==0 && ((nTxzname==KEY_ZOOM_IN && nCrzpos>=nTxtbl[nTxtblcr]) || (nTxzname==KEY_ZOOM_OUT && nCrzpos<=nTxtbl[nTxtblcr]))){ |
|---|
| 762 | if(get_usb_power(1)){ |
|---|
| 763 | i=1; |
|---|
| 764 | if(nTxzname==KEY_ZOOM_IN){ |
|---|
| 765 | nTxtblcr++; |
|---|
| 766 | if(nTxtblcr>(ZSTEP_TABLE_SIZE-1)) {nTxtblcr=(ZSTEP_TABLE_SIZE-1);i=0;} |
|---|
| 767 | } |
|---|
| 768 | else{ |
|---|
| 769 | nTxtblcr--; |
|---|
| 770 | if(nTxtblcr<0) {nTxtblcr=0;i=0;} |
|---|
| 771 | } |
|---|
| 772 | if(i==1) return 1; |
|---|
| 773 | } |
|---|
| 774 | kbd_key_release_all(); |
|---|
| 775 | set_key_press(0); |
|---|
| 776 | nTxzoom=1; |
|---|
| 777 | // lens_set_zoom_speed(25); |
|---|
| 778 | nSW=120; |
|---|
| 779 | nWt=5; |
|---|
| 780 | return 1; |
|---|
| 781 | } |
|---|
| 782 | kbd_key_release_all(); |
|---|
| 783 | kbd_key_press(nTxzname); |
|---|
| 784 | set_key_press(1); |
|---|
| 785 | nCER++; |
|---|
| 786 | return 1; |
|---|
| 787 | } |
|---|
| 788 | |
|---|
| 789 | if(nTxvideo>0 && nSW==121){ |
|---|
| 790 | if(!get_usb_power(1)) { |
|---|
| 791 | nWt=10; |
|---|
| 792 | kbd_key_press(KEY_VIDEO); |
|---|
| 793 | set_key_press(1); |
|---|
| 794 | nSW=122; |
|---|
| 795 | } |
|---|
| 796 | return 1; |
|---|
| 797 | } |
|---|
| 798 | if(nTxvideo>0 && nSW==122){ |
|---|
| 799 | nWt=10; |
|---|
| 800 | kbd_key_release(KEY_VIDEO); |
|---|
| 801 | set_key_press(1); |
|---|
| 802 | nSW=123; |
|---|
| 803 | return 1; |
|---|
| 804 | } |
|---|
| 805 | if(nTxvideo>0 && nSW==123){ |
|---|
| 806 | set_key_press(0); |
|---|
| 807 | nWt=50; |
|---|
| 808 | nSW=0; |
|---|
| 809 | nCa=0; |
|---|
| 810 | nTxvideo=0; |
|---|
| 811 | debug_led(0); |
|---|
| 812 | return 1; |
|---|
| 813 | } |
|---|
| 814 | |
|---|
| 815 | if(nSW==110){ |
|---|
| 816 | if (shooting_in_progress() || mvideo || nCER>100) { |
|---|
| 817 | state_expos_recalculated = 0; |
|---|
| 818 | histogram_restart(); |
|---|
| 819 | nCER=0; |
|---|
| 820 | nSW=111; |
|---|
| 821 | } |
|---|
| 822 | else {nCER++;return 1;} |
|---|
| 823 | } |
|---|
| 824 | if(nSW==111){ |
|---|
| 825 | if (state_expos_recalculated || nCER>100) { |
|---|
| 826 | state_expos_under = under_exposed; |
|---|
| 827 | state_expos_over = over_exposed; |
|---|
| 828 | nCER=0; |
|---|
| 829 | nSW=112; |
|---|
| 830 | //presynch(); |
|---|
| 831 | } |
|---|
| 832 | else {nCER++;return 1;} |
|---|
| 833 | } |
|---|
| 834 | if(nSW==112){ |
|---|
| 835 | if (shooting_is_flash_ready() || nCER>10){ |
|---|
| 836 | nCER=0; |
|---|
| 837 | nSW=113; |
|---|
| 838 | } |
|---|
| 839 | else {nCER++;return 1;} |
|---|
| 840 | } |
|---|
| 841 | if(nSW==113){ |
|---|
| 842 | if(get_usb_power(1) && !mvideo) nSW=114; |
|---|
| 843 | else if(!get_usb_power(1) && mvideo) nSW=114; |
|---|
| 844 | else return 1; |
|---|
| 845 | } |
|---|
| 846 | if(nTxzoom>0 && nSW==120){ |
|---|
| 847 | nCrzpos=lens_get_zoom_point(); |
|---|
| 848 | if((nTxzname==KEY_ZOOM_IN && nCrzpos<=nTxtbl[nTxtblcr]) || (nTxzname==KEY_ZOOM_OUT && nCrzpos>=nTxtbl[nTxtblcr])){ |
|---|
| 849 | kbd_key_release_all(); |
|---|
| 850 | set_key_press(0); |
|---|
| 851 | nTxzoom=1; |
|---|
| 852 | lens_set_zoom_speed(100); |
|---|
| 853 | nSW=0; |
|---|
| 854 | nCount=0; |
|---|
| 855 | nWt=10; |
|---|
| 856 | return 1; |
|---|
| 857 | } |
|---|
| 858 | lens_set_zoom_speed(5); |
|---|
| 859 | kbd_key_release_all(); |
|---|
| 860 | if(nTxzname==KEY_ZOOM_IN) kbd_key_press(KEY_ZOOM_OUT); |
|---|
| 861 | else kbd_key_press(KEY_ZOOM_IN); |
|---|
| 862 | set_key_press(1); |
|---|
| 863 | return 1; |
|---|
| 864 | } |
|---|
| 865 | |
|---|
| 866 | if(nSW==114){ |
|---|
| 867 | nSW=115; |
|---|
| 868 | nWt=2; |
|---|
| 869 | shutter_int=0; |
|---|
| 870 | kbd_key_press(KEY_SHOOT_FULL); |
|---|
| 871 | set_key_press(1); |
|---|
| 872 | // kbd_blocked = 1; |
|---|
| 873 | // nRmt=1; |
|---|
| 874 | nCount=0; |
|---|
| 875 | return 1; |
|---|
| 876 | } |
|---|
| 877 | if(nSW==115){ |
|---|
| 878 | // debug_led(0); |
|---|
| 879 | if(drmode==1 && shutter_int==0){ |
|---|
| 880 | return 1; |
|---|
| 881 | } |
|---|
| 882 | nSW=116; |
|---|
| 883 | nWt=2; |
|---|
| 884 | kbd_key_release(KEY_SHOOT_FULL); |
|---|
| 885 | set_key_press(1); |
|---|
| 886 | // kbd_blocked = 1; |
|---|
| 887 | // nRmt=1; |
|---|
| 888 | return 1; |
|---|
| 889 | } |
|---|
| 890 | if(!get_usb_power(1) && nSW==116) { |
|---|
| 891 | set_key_press(0); |
|---|
| 892 | // kbd_blocked = 0; |
|---|
| 893 | // key_pressed = 0; |
|---|
| 894 | nWt=50; |
|---|
| 895 | nSW=0; |
|---|
| 896 | // nRmt=0; |
|---|
| 897 | nCa=0; |
|---|
| 898 | //postsynch(); |
|---|
| 899 | return 1; |
|---|
| 900 | } |
|---|
| 901 | } |
|---|
| 902 | |
|---|
| 903 | // ------------------------------------------------------------- Ricoh remote switch CA-1 -------------- |
|---|
| 904 | if(nCa==1){ |
|---|
| 905 | if(get_usb_power(1) && nSW>108 && nSW<120){ |
|---|
| 906 | nCount++; |
|---|
| 907 | } |
|---|
| 908 | if(nSW==109){ |
|---|
| 909 | // nSW=110; |
|---|
| 910 | nCER=0; |
|---|
| 911 | if(nTxzoom>0){ |
|---|
| 912 | if(nTxzoom<100){ |
|---|
| 913 | nIntzpos=lens_get_zoom_point(); |
|---|
| 914 | for(i=0;i<ZSTEP_TABLE_SIZE;i++){ |
|---|
| 915 | if(nIntzpos<=nTxtbl[i]){ |
|---|
| 916 | if(i>0){ |
|---|
| 917 | if(abs(nTxtbl[i]-nIntzpos)<=abs(nTxtbl[i-1]-nIntzpos)) nTxtblcr=i; |
|---|
| 918 | else nTxtblcr=i-1; |
|---|
| 919 | } |
|---|
| 920 | else nTxtblcr=i; |
|---|
| 921 | i=ZSTEP_TABLE_SIZE; |
|---|
| 922 | } |
|---|
| 923 | } |
|---|
| 924 | if(nTxzname==KEY_ZOOM_IN){ |
|---|
| 925 | nTxtblcr++; |
|---|
| 926 | if(nTxtblcr>(ZSTEP_TABLE_SIZE-1)) nTxtblcr=(ZSTEP_TABLE_SIZE-1); |
|---|
| 927 | } |
|---|
| 928 | else{ |
|---|
| 929 | nTxtblcr--; |
|---|
| 930 | if(nTxtblcr<0) nTxtblcr=0; |
|---|
| 931 | } |
|---|
| 932 | nSW=113; |
|---|
| 933 | return 1; |
|---|
| 934 | } |
|---|
| 935 | nTxzoom=0; |
|---|
| 936 | nReczoom=0; |
|---|
| 937 | } |
|---|
| 938 | if(nTxvideo>0) {nSW=121;return 1;} |
|---|
| 939 | nSW=110; |
|---|
| 940 | nWt=2; |
|---|
| 941 | kbd_key_release_all(); |
|---|
| 942 | kbd_key_press(KEY_SHOOT_HALF); |
|---|
| 943 | // debug_led(1); |
|---|
| 944 | set_key_press(1); |
|---|
| 945 | // key_pressed = 1; |
|---|
| 946 | // kbd_blocked = 1; |
|---|
| 947 | // nRmt=1; |
|---|
| 948 | return 1; |
|---|
| 949 | } |
|---|
| 950 | if(nTxvideo>0 && nSW==121){ |
|---|
| 951 | if(get_usb_power(1)) { |
|---|
| 952 | nWt=10; |
|---|
| 953 | kbd_key_press(KEY_VIDEO); |
|---|
| 954 | set_key_press(1); |
|---|
| 955 | nSW=122; |
|---|
| 956 | } |
|---|
| 957 | return 1; |
|---|
| 958 | } |
|---|
| 959 | if(nTxvideo>0 && nSW==122){ |
|---|
| 960 | nWt=10; |
|---|
| 961 | kbd_key_release(KEY_VIDEO); |
|---|
| 962 | set_key_press(1); |
|---|
| 963 | nSW=123; |
|---|
| 964 | return 1; |
|---|
| 965 | } |
|---|
| 966 | if(nTxvideo>0 && nSW==123){ |
|---|
| 967 | set_key_press(0); |
|---|
| 968 | nWt=100; |
|---|
| 969 | nCount=0; |
|---|
| 970 | nSW=0; |
|---|
| 971 | nCa=0; |
|---|
| 972 | nTxvideo=0; |
|---|
| 973 | debug_led(0); |
|---|
| 974 | return 1; |
|---|
| 975 | } |
|---|
| 976 | |
|---|
| 977 | if(nSW==110){ |
|---|
| 978 | if (shooting_in_progress() || mvideo || nCER>100) { |
|---|
| 979 | // debug_led(0); |
|---|
| 980 | state_expos_recalculated = 0; |
|---|
| 981 | histogram_restart(); |
|---|
| 982 | nCER=0; |
|---|
| 983 | nSW=111; |
|---|
| 984 | } |
|---|
| 985 | else {nCER++;return 1;} |
|---|
| 986 | } |
|---|
| 987 | if(nSW==111){ |
|---|
| 988 | if (state_expos_recalculated || nCER>100) { |
|---|
| 989 | state_expos_under = under_exposed; |
|---|
| 990 | state_expos_over = over_exposed; |
|---|
| 991 | nCER=0; |
|---|
| 992 | nSW=112; |
|---|
| 993 | //presynch(); |
|---|
| 994 | } |
|---|
| 995 | else {nCER++;return 1;} |
|---|
| 996 | } |
|---|
| 997 | if(nSW==112){ |
|---|
| 998 | if (shooting_is_flash_ready() || nCER>10){ |
|---|
| 999 | nCER=0; |
|---|
| 1000 | nSW=113; |
|---|
| 1001 | } |
|---|
| 1002 | else {nCER++;return 1;} |
|---|
| 1003 | } |
|---|
| 1004 | if(nTxzoom>0 && nSW==114){ |
|---|
| 1005 | nCrzpos=lens_get_zoom_point(); |
|---|
| 1006 | if(nIntzpos!=nCrzpos) {nReczoom=0;} |
|---|
| 1007 | if(nIntzpos==nCrzpos && nCER>50){ |
|---|
| 1008 | if(nCount>0){ |
|---|
| 1009 | kbd_key_release_all(); |
|---|
| 1010 | set_key_press(0); |
|---|
| 1011 | nTxzoom=1; |
|---|
| 1012 | nSW=0; |
|---|
| 1013 | nCount=0; |
|---|
| 1014 | nWt=10; |
|---|
| 1015 | nReczoom=1; |
|---|
| 1016 | return 1; |
|---|
| 1017 | } |
|---|
| 1018 | } |
|---|
| 1019 | if(nReczoom==0 && ((nTxzname==KEY_ZOOM_IN && nCrzpos>=nTxtbl[nTxtblcr]) || (nTxzname==KEY_ZOOM_OUT && nCrzpos<=nTxtbl[nTxtblcr]))){ |
|---|
| 1020 | if(nCount==0){ |
|---|
| 1021 | i=1; |
|---|
| 1022 | if(nTxzname==KEY_ZOOM_IN){ |
|---|
| 1023 | nTxtblcr++; |
|---|
| 1024 | if(nTxtblcr>(ZSTEP_TABLE_SIZE-1)) {nTxtblcr=(ZSTEP_TABLE_SIZE-1);i=0;} |
|---|
| 1025 | } |
|---|
| 1026 | else{ |
|---|
| 1027 | nTxtblcr--; |
|---|
| 1028 | if(nTxtblcr<0) {nTxtblcr=0;i=0;} |
|---|
| 1029 | } |
|---|
| 1030 | if(i==1) return 1; |
|---|
| 1031 | } |
|---|
| 1032 | kbd_key_release_all(); |
|---|
| 1033 | set_key_press(0); |
|---|
| 1034 | nTxzoom=1; |
|---|
| 1035 | // lens_set_zoom_speed(25); |
|---|
| 1036 | nSW=115; |
|---|
| 1037 | nWt=5; |
|---|
| 1038 | return 1; |
|---|
| 1039 | } |
|---|
| 1040 | kbd_key_release_all(); |
|---|
| 1041 | kbd_key_press(nTxzname); |
|---|
| 1042 | set_key_press(1); |
|---|
| 1043 | nCER++; |
|---|
| 1044 | return 1; |
|---|
| 1045 | } |
|---|
| 1046 | if(nTxzoom>0 && nSW==115){ |
|---|
| 1047 | if(nCount==0) return 1; |
|---|
| 1048 | nCrzpos=lens_get_zoom_point(); |
|---|
| 1049 | if((nTxzname==KEY_ZOOM_IN && nCrzpos<=nTxtbl[nTxtblcr]) || (nTxzname==KEY_ZOOM_OUT && nCrzpos>=nTxtbl[nTxtblcr])){ |
|---|
| 1050 | kbd_key_release_all(); |
|---|
| 1051 | set_key_press(0); |
|---|
| 1052 | nTxzoom=1; |
|---|
| 1053 | lens_set_zoom_speed(100); |
|---|
| 1054 | nSW=0; |
|---|
| 1055 | nCount=0; |
|---|
| 1056 | nWt=10; |
|---|
| 1057 | return 1; |
|---|
| 1058 | } |
|---|
| 1059 | lens_set_zoom_speed(5); |
|---|
| 1060 | kbd_key_release_all(); |
|---|
| 1061 | if(nTxzname==KEY_ZOOM_IN) kbd_key_press(KEY_ZOOM_OUT); |
|---|
| 1062 | else kbd_key_press(KEY_ZOOM_IN); |
|---|
| 1063 | set_key_press(1); |
|---|
| 1064 | return 1; |
|---|
| 1065 | } |
|---|
| 1066 | |
|---|
| 1067 | |
|---|
| 1068 | if(get_usb_power(1)){ |
|---|
| 1069 | return 1; |
|---|
| 1070 | } |
|---|
| 1071 | if(nCount>0 && nSW==113){ |
|---|
| 1072 | if(nCount<9){ |
|---|
| 1073 | if(nTxzoom>0){ |
|---|
| 1074 | kbd_key_release_all(); |
|---|
| 1075 | set_key_press(0); |
|---|
| 1076 | nTxzoom=0; |
|---|
| 1077 | nReczoom=0; |
|---|
| 1078 | nSW=0; |
|---|
| 1079 | nCa=0; |
|---|
| 1080 | nCount=0; |
|---|
| 1081 | nWt=10; |
|---|
| 1082 | // lens_set_zoom_speed(100); |
|---|
| 1083 | debug_led(0); |
|---|
| 1084 | return 1; |
|---|
| 1085 | } |
|---|
| 1086 | nSW=125; |
|---|
| 1087 | nWt=10; |
|---|
| 1088 | kbd_key_release(KEY_SHOOT_HALF); |
|---|
| 1089 | set_key_press(1); |
|---|
| 1090 | // kbd_blocked = 1; |
|---|
| 1091 | // nRmt=1; |
|---|
| 1092 | nCount=0; |
|---|
| 1093 | return 1; |
|---|
| 1094 | } |
|---|
| 1095 | else{ |
|---|
| 1096 | if(nTxzoom>0){ |
|---|
| 1097 | nCount=0; |
|---|
| 1098 | nSW=114; |
|---|
| 1099 | return 1; |
|---|
| 1100 | } |
|---|
| 1101 | nSW=124; |
|---|
| 1102 | nWt=2; |
|---|
| 1103 | shutter_int=0; |
|---|
| 1104 | // debug_led(0); |
|---|
| 1105 | kbd_key_press(KEY_SHOOT_FULL); |
|---|
| 1106 | set_key_press(1); |
|---|
| 1107 | // kbd_blocked = 1; |
|---|
| 1108 | // nRmt=1; |
|---|
| 1109 | nCount=0; |
|---|
| 1110 | return 1; |
|---|
| 1111 | } |
|---|
| 1112 | } |
|---|
| 1113 | if(nSW==124){ |
|---|
| 1114 | // debug_led(0); |
|---|
| 1115 | if(drmode==1 && shutter_int==0){ |
|---|
| 1116 | return 1; |
|---|
| 1117 | } |
|---|
| 1118 | nSW=125; |
|---|
| 1119 | nWt=2; |
|---|
| 1120 | kbd_key_release(KEY_SHOOT_FULL); |
|---|
| 1121 | set_key_press(1); |
|---|
| 1122 | // kbd_blocked = 1; |
|---|
| 1123 | // nRmt=1; |
|---|
| 1124 | return 1; |
|---|
| 1125 | } |
|---|
| 1126 | if(!get_usb_power(1) && nSW==125) { |
|---|
| 1127 | set_key_press(0); |
|---|
| 1128 | // kbd_blocked = 0; |
|---|
| 1129 | // key_pressed = 0; |
|---|
| 1130 | nWt=50; |
|---|
| 1131 | nSW=0; |
|---|
| 1132 | // nRmt=0; |
|---|
| 1133 | nCa=0; |
|---|
| 1134 | //postsynch(); |
|---|
| 1135 | return 1; |
|---|
| 1136 | } |
|---|
| 1137 | } |
|---|
| 1138 | |
|---|
| 1139 | // ------ add by Masuji SUTO (end) -------------- |
|---|
| 1140 | |
|---|
| 1141 | } // ricoh_ca1_mode |
|---|
| 1142 | #endif |
|---|
| 1143 | |
|---|
| 1144 | if (conf.use_zoom_mf && kbd_use_zoom_as_mf()) { |
|---|
| 1145 | return 1; |
|---|
| 1146 | } |
|---|
| 1147 | if ((conf.fast_ev || conf.fast_movie_control || conf.fast_movie_quality_control) && kbd_use_up_down_left_right_as_fast_switch()) { |
|---|
| 1148 | return 1; |
|---|
| 1149 | } |
|---|
| 1150 | other_kbd_process(); // processed other keys in not <alt> mode |
|---|
| 1151 | } |
|---|
| 1152 | |
|---|
| 1153 | return kbd_blocked; |
|---|
| 1154 | } |
|---|
| 1155 | |
|---|
| 1156 | static const struct Keynames { |
|---|
| 1157 | int keyid; |
|---|
| 1158 | char *keyname; |
|---|
| 1159 | } keynames[] = { |
|---|
| 1160 | { KEY_UP, "up" }, |
|---|
| 1161 | { KEY_DOWN, "down" }, |
|---|
| 1162 | { KEY_LEFT, "left" }, |
|---|
| 1163 | { KEY_RIGHT, "right" }, |
|---|
| 1164 | { KEY_SET, "set" }, |
|---|
| 1165 | { KEY_SHOOT_HALF, "shoot_half" }, |
|---|
| 1166 | { KEY_SHOOT_FULL, "shoot_full" }, |
|---|
| 1167 | { KEY_ZOOM_IN, "zoom_in" }, |
|---|
| 1168 | { KEY_ZOOM_OUT, "zoom_out" }, |
|---|
| 1169 | { KEY_MENU, "menu" }, |
|---|
| 1170 | { KEY_DISPLAY, "display" }, |
|---|
| 1171 | { KEY_PRINT, "print" }, |
|---|
| 1172 | { KEY_ERASE, "erase" }, |
|---|
| 1173 | { KEY_ISO, "iso" }, |
|---|
| 1174 | { KEY_FLASH, "flash" }, |
|---|
| 1175 | { KEY_MF, "mf" }, |
|---|
| 1176 | { KEY_MACRO, "macro" }, |
|---|
| 1177 | { KEY_VIDEO, "video" }, |
|---|
| 1178 | { KEY_TIMER, "timer" }, |
|---|
| 1179 | { KEY_EXPO_CORR, "expo_corr" }, |
|---|
| 1180 | { KEY_MICROPHONE, "fe" }, |
|---|
| 1181 | { 0xFF, "remote" }, |
|---|
| 1182 | { 0xFFFF, "no_key" }, |
|---|
| 1183 | }; |
|---|
| 1184 | |
|---|
| 1185 | int keyid_by_name (const char *n) |
|---|
| 1186 | { |
|---|
| 1187 | int i; |
|---|
| 1188 | for (i=0;i<sizeof(keynames)/sizeof(keynames[0]);i++) |
|---|
| 1189 | if (strcmp(keynames[i].keyname,n) == 0) |
|---|
| 1190 | return keynames[i].keyid; |
|---|
| 1191 | return 0; |
|---|
| 1192 | } |
|---|
| 1193 | |
|---|
| 1194 | int kbd_is_blocked() { |
|---|
| 1195 | return kbd_blocked; |
|---|
| 1196 | } |
|---|
| 1197 | |
|---|
| 1198 | long kbd_use_up_down_left_right_as_fast_switch() { |
|---|
| 1199 | static const char* modes[]={ "0.25x", "0.5x","0.75x", "1x", "1.25x", "1.5x", "1.75x", "2x", "2.5x", "3x"}; |
|---|
| 1200 | static long key_pressed = 0; |
|---|
| 1201 | if (!(kbd_is_key_pressed(KEY_UP)) && !(kbd_is_key_pressed(KEY_DOWN))) key_pressed = 0; |
|---|
| 1202 | if (kbd_is_key_pressed(KEY_UP) && (mode_get()&MODE_MASK) == MODE_REC && ((mode_get()&MODE_SHOOTING_MASK) != MODE_M) && ((mode_get()&MODE_SHOOTING_MASK) != MODE_VIDEO_STD) && movie_status<4 && (canon_shoot_menu_active==0)) { |
|---|
| 1203 | |
|---|
| 1204 | if (conf.fast_ev && key_pressed == 0) { |
|---|
| 1205 | #if (CAM_PROPSET == 1) |
|---|
| 1206 | shooting_set_prop(25,shooting_get_prop(25)+(conf.fast_ev_step+1)*16); |
|---|
| 1207 | shooting_set_prop(26,shooting_get_prop(26)+(conf.fast_ev_step+1)*16); |
|---|
| 1208 | #elif (CAM_PROPSET == 2) |
|---|
| 1209 | shooting_set_prop(107,shooting_get_prop(107)+(conf.fast_ev_step+1)*16); |
|---|
| 1210 | shooting_set_prop(207,shooting_get_prop(207)+(conf.fast_ev_step+1)*16); |
|---|
| 1211 | #endif |
|---|
| 1212 | key_pressed = KEY_UP; |
|---|
| 1213 | |
|---|
| 1214 | return 1; |
|---|
| 1215 | } |
|---|
| 1216 | |
|---|
| 1217 | } |
|---|
| 1218 | if (kbd_is_key_pressed(KEY_UP) && (mode_get()&MODE_MASK) == MODE_REC && movie_status == 4 && (canon_shoot_menu_active==0)) { |
|---|
| 1219 | |
|---|
| 1220 | if (conf.fast_movie_quality_control && key_pressed == 0) { |
|---|
| 1221 | |
|---|
| 1222 | |
|---|
| 1223 | if (conf.video_mode==0) |
|---|
| 1224 | { |
|---|
| 1225 | conf.video_bitrate+=1; |
|---|
| 1226 | if (conf.video_bitrate<0) |
|---|
| 1227 | conf.video_bitrate=sizeof(modes)/sizeof(modes[0])-1; |
|---|
| 1228 | else if (conf.video_bitrate>=(sizeof(modes)/sizeof(modes[0]))) |
|---|
| 1229 | conf.video_bitrate=sizeof(modes)/sizeof(modes[0])-1; |
|---|
| 1230 | shooting_video_bitrate_change(conf.video_bitrate); |
|---|
| 1231 | movie_reset = 1; |
|---|
| 1232 | } |
|---|
| 1233 | |
|---|
| 1234 | if (conf.video_mode==1) |
|---|
| 1235 | { |
|---|
| 1236 | conf.video_quality+=1; |
|---|
| 1237 | if (conf.video_quality<1) |
|---|
| 1238 | conf.video_quality=1; |
|---|
| 1239 | else if (conf.video_quality>99) |
|---|
| 1240 | conf.video_quality=99; |
|---|
| 1241 | movie_reset = 1; |
|---|
| 1242 | } |
|---|
| 1243 | key_pressed = KEY_UP; |
|---|
| 1244 | return 1; |
|---|
| 1245 | } |
|---|
| 1246 | |
|---|
| 1247 | } |
|---|
| 1248 | if (kbd_is_key_pressed(KEY_DOWN) && (mode_get()&MODE_MASK) == MODE_REC && ((mode_get()&MODE_SHOOTING_MASK) != MODE_M) && ((mode_get()&MODE_SHOOTING_MASK) != MODE_VIDEO_STD) && movie_status<4 && (canon_shoot_menu_active==0)) { |
|---|
| 1249 | |
|---|
| 1250 | |
|---|
| 1251 | if (conf.fast_ev && key_pressed == 0) { |
|---|
| 1252 | kbd_key_release_all(); |
|---|
| 1253 | #if (CAM_PROPSET == 1) |
|---|
| 1254 | shooting_set_prop(25,shooting_get_prop(25)-(conf.fast_ev_step+1)*16); |
|---|
| 1255 | shooting_set_prop(26,shooting_get_prop(26)-(conf.fast_ev_step+1)*16); |
|---|
| 1256 | #elif (CAM_PROPSET == 2) |
|---|
| 1257 | shooting_set_prop(107,shooting_get_prop(107)-(conf.fast_ev_step+1)*16); |
|---|
| 1258 | shooting_set_prop(207,shooting_get_prop(207)-(conf.fast_ev_step+1)*16); |
|---|
| 1259 | #endif |
|---|
| 1260 | key_pressed = KEY_DOWN; |
|---|
| 1261 | return 1; |
|---|
| 1262 | } |
|---|
| 1263 | |
|---|
| 1264 | } |
|---|
| 1265 | |
|---|
| 1266 | if (kbd_is_key_pressed(KEY_DOWN) && (mode_get()&MODE_MASK) == MODE_REC && movie_status == 4 && (canon_shoot_menu_active==0)) { |
|---|
| 1267 | |
|---|
| 1268 | |
|---|
| 1269 | if (conf.fast_movie_quality_control && key_pressed == 0) { |
|---|
| 1270 | |
|---|
| 1271 | if (conf.video_mode==0) |
|---|
| 1272 | { |
|---|
| 1273 | conf.video_bitrate+=-1; |
|---|
| 1274 | if (conf.video_bitrate<0) |
|---|
| 1275 | conf.video_bitrate=0; |
|---|
| 1276 | |
|---|
| 1277 | |
|---|
| 1278 | shooting_video_bitrate_change(conf.video_bitrate); |
|---|
| 1279 | movie_reset = 1; |
|---|
| 1280 | } |
|---|
| 1281 | if (conf.video_mode==1) |
|---|
| 1282 | { |
|---|
| 1283 | conf.video_quality-=1; |
|---|
| 1284 | if (conf.video_quality<1) |
|---|
| 1285 | conf.video_quality=1; |
|---|
| 1286 | else if (conf.video_quality>99) |
|---|
| 1287 | conf.video_quality=99; |
|---|
| 1288 | movie_reset = 1; |
|---|
| 1289 | } |
|---|
| 1290 | |
|---|
| 1291 | |
|---|
| 1292 | |
|---|
| 1293 | key_pressed = KEY_DOWN; |
|---|
| 1294 | return 1; |
|---|
| 1295 | } |
|---|
| 1296 | |
|---|
| 1297 | } |
|---|
| 1298 | |
|---|
| 1299 | if (kbd_is_key_pressed(KEY_LEFT) && (mode_get()&MODE_MASK) == MODE_REC && movie_status == 4 && (canon_shoot_menu_active==0)) { |
|---|
| 1300 | |
|---|
| 1301 | |
|---|
| 1302 | if (conf.fast_movie_control && key_pressed == 0) { |
|---|
| 1303 | |
|---|
| 1304 | movie_status = 1; |
|---|
| 1305 | |
|---|
| 1306 | |
|---|
| 1307 | key_pressed = KEY_LEFT; |
|---|
| 1308 | return 1; |
|---|
| 1309 | } |
|---|
| 1310 | |
|---|
| 1311 | } |
|---|
| 1312 | |
|---|
| 1313 | if (kbd_is_key_pressed(KEY_RIGHT) && (mode_get()&MODE_MASK) == MODE_REC && movie_status == 1 && (canon_shoot_menu_active==0)) { |
|---|
| 1314 | |
|---|
| 1315 | |
|---|
| 1316 | if (conf.fast_movie_control && key_pressed == 0) { |
|---|
| 1317 | |
|---|
| 1318 | movie_status = 4; |
|---|
| 1319 | movie_reset = 1; |
|---|
| 1320 | |
|---|
| 1321 | |
|---|
| 1322 | key_pressed = KEY_RIGHT; |
|---|
| 1323 | return 1; |
|---|
| 1324 | } |
|---|
| 1325 | |
|---|
| 1326 | } |
|---|
| 1327 | |
|---|
| 1328 | return 0; |
|---|
| 1329 | } |
|---|