source: trunk/core/kbd.c @ 1008

Revision 1008, 47.4 KB checked in by reyalP, 2 years ago (diff)

sx30 100e, 100h, 100l and g12 100c support from from philmoz in http://chdk.setepontos.com/index.php?topic=650.msg59036#msg59036
not added to autobuild yet

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