root/core/kbd_process.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. kbd_get_autoclicked_key
  2. kbd_is_blocked
  3. enter_alt
  4. exit_alt
  5. kbd_process

   1 #include "camera.h"
   2 #include "conf.h"
   3 #include "keyboard.h"
   4 #include "action_stack.h"
   5 #include "lang.h"
   6 #include "gui.h"
   7 #include "gui_lang.h"
   8 #include "console.h"
   9 #include "usb_remote.h"
  10 #include "clock.h"
  11 #include "debug_led.h"
  12 
  13 //-------------------------------------------------------------------
  14 // Keyboard auto repeat
  15 
  16 static long last_kbd_key = 0;
  17 static long last_kbd_time = 0;
  18 static long press_count = 0;
  19 
  20 long kbd_get_autoclicked_key()
  21 {
  22         register long key, t;
  23 
  24         key=kbd_get_clicked_key();
  25         if (key && (key != last_kbd_key))
  26     {
  27                 last_kbd_key = key;
  28                 press_count = 0;
  29                 last_kbd_time = get_tick_count();
  30                 return key;
  31         }
  32     else
  33     {
  34                 if (last_kbd_key && kbd_is_key_pressed(last_kbd_key))
  35         {
  36                         t = get_tick_count();
  37                         if (t-last_kbd_time > ((press_count) ? KBD_REPEAT_DELAY : KBD_INITIAL_DELAY))
  38             {
  39                                 ++press_count;
  40                                 last_kbd_time = t;
  41                                 return last_kbd_key;
  42                         }
  43             else
  44             {
  45                                 return 0;
  46                         }
  47                 }
  48         else
  49         {
  50                         last_kbd_key = 0;
  51                         return 0;
  52                 }
  53         }
  54 }
  55 
  56 //-------------------------------------------------------------------
  57 
  58 int kbd_blocked;
  59 
  60 int kbd_is_blocked()
  61 {
  62     return kbd_blocked;
  63 }
  64 
  65 void enter_alt()
  66 {
  67     clear_usb_power();         // Prevent previous USB remote pulse from starting script.
  68     kbd_blocked = 1;
  69     gui_set_alt_mode_state(ALT_MODE_ENTER);
  70 }
  71 
  72 void exit_alt()
  73 {
  74     kbd_blocked = 0;
  75     gui_set_alt_mode_state(ALT_MODE_LEAVE);
  76 }
  77 
  78 //-------------------------------------------------------------------
  79 // Core keyboard handler
  80 
  81 long kbd_process()
  82 {
  83     static int key_pressed;
  84 
  85     if( usb_HPtimer_handle==0) usb_remote_key();
  86 
  87     if (camera_info.perf.md_af_tuning)
  88     {
  89         switch (camera_info.perf.md_af_on_flag)
  90         {
  91         case 1:
  92             if (get_tick_count() >= (camera_info.perf.md_detect_tick + camera_info.perf.md_af_on_delay))
  93             {
  94                 camera_info.perf.md_af_on_flag = 2;
  95                 camera_set_led(camera_info.cam_af_led,1,200);
  96             }
  97             break;
  98         case 2:
  99             if (get_tick_count() >= (camera_info.perf.md_detect_tick + camera_info.perf.md_af_on_delay + camera_info.perf.md_af_on_time))
 100             {
 101                 camera_info.perf.md_af_on_flag = 0;
 102                 camera_set_led(camera_info.cam_af_led,0,0);
 103             }
 104             break;
 105         }
 106     }
 107 
 108     // check for & process non-keyboard script terminate
 109     script_check_terminate();
 110 
 111     // Reset keyboard auto repeat if no buttons pressed
 112     if (kbd_get_pressed_key() == 0)
 113         last_kbd_key = 0;
 114 
 115     // Set clicked key for scripts.
 116     if (kbd_get_clicked_key())
 117     {
 118         camera_info.state.kbd_last_clicked = kbd_get_clicked_key();
 119         camera_info.state.kbd_last_clicked_time = get_tick_count();
 120     }
 121 
 122     // Set Shutter Half Press state for GUI task.
 123     camera_info.state.is_shutter_half_press = kbd_is_key_pressed(KEY_SHOOT_HALF);
 124 
 125         // Alternative keyboard mode stated/exited by pressing print key.
 126         // While running Alt. mode shoot key will start a script execution.
 127 
 128         // alt-mode switch and delay emulation
 129  
 130         if ( key_pressed  && !usb_remote_active ) 
 131         {
 132         if (kbd_is_key_pressed(conf.alt_mode_button)
 133                 || ((key_pressed >= CAM_EMUL_KEYPRESS_DELAY)
 134                 && (key_pressed < CAM_EMUL_KEYPRESS_DELAY+CAM_EMUL_KEYPRESS_DURATION)))
 135         {
 136             if (key_pressed <= CAM_EMUL_KEYPRESS_DELAY+CAM_EMUL_KEYPRESS_DURATION) 
 137                 key_pressed++;
 138             if (key_pressed == CAM_EMUL_KEYPRESS_DELAY) 
 139                 kbd_key_press(conf.alt_mode_button);
 140             else if (key_pressed == CAM_EMUL_KEYPRESS_DELAY+CAM_EMUL_KEYPRESS_DURATION) 
 141                 kbd_key_release(conf.alt_mode_button);
 142             return 1;
 143         } 
 144         else if (kbd_get_pressed_key() == 0)
 145         {
 146             if (key_pressed < CAM_EMUL_KEYPRESS_DELAY)
 147             {
 148                 if (!kbd_blocked)
 149                 {
 150                     // if start script on alt set, flag to run it
 151                     if(conf.script_startup==SCRIPT_AUTOSTART_ALT) script_run_on_alt_flag = 1;
 152                     enter_alt();
 153                 }
 154                 else
 155                     exit_alt();
 156             }
 157             key_pressed = 0;
 158             return 1;
 159         }
 160         return 1;
 161     }
 162        
 163     // auto iso shift
 164     if (camera_info.state.is_shutter_half_press && kbd_is_key_pressed(conf.alt_mode_button)) 
 165         return 0;
 166 
 167     if (kbd_is_key_pressed(conf.alt_mode_button)) 
 168         {
 169         key_pressed = 1;
 170         kbd_key_release_all();          
 171         return 1;
 172     }
 173 
 174 #ifdef CAM_TOUCHSCREEN_UI
 175     extern int ts_process_touch();
 176     if (ts_process_touch())
 177     {
 178         gui_set_need_restore();
 179     }
 180 #endif
 181 
 182     // deals with the rest
 183 
 184     if ( !kbd_blocked || usb_remote_active ) 
 185         {
 186                 kbd_blocked = handle_usb_remote();
 187         }
 188 
 189     if (gui_kbd_process())
 190         return 1;
 191 
 192     action_stack_process_all();
 193 
 194     // Check if a PTP script needs to be started
 195     //  do this after action_stack_process_all so new script is not run until next timeslice
 196     extern void start_ptp_script();
 197     start_ptp_script();
 198 
 199     return kbd_blocked;
 200 }

/* [<][>][^][v][top][bottom][index][help] */