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     // update any state that needs to be updated regularly in shooting
 126     extern void shooting_update_state(void);
 127     shooting_update_state();
 128 
 129         // Alternative keyboard mode stated/exited by pressing print key.
 130         // While running Alt. mode shoot key will start a script execution.
 131 
 132         // alt-mode switch and delay emulation
 133  
 134         if ( key_pressed  && !usb_remote_active ) 
 135         {
 136         if (kbd_is_key_pressed(conf.alt_mode_button)
 137                 || ((key_pressed >= CAM_EMUL_KEYPRESS_DELAY)
 138                 && (key_pressed < CAM_EMUL_KEYPRESS_DELAY+CAM_EMUL_KEYPRESS_DURATION)))
 139         {
 140             if (key_pressed <= CAM_EMUL_KEYPRESS_DELAY+CAM_EMUL_KEYPRESS_DURATION) 
 141                 key_pressed++;
 142             if (key_pressed == CAM_EMUL_KEYPRESS_DELAY) 
 143                 kbd_key_press(conf.alt_mode_button);
 144             else if (key_pressed == CAM_EMUL_KEYPRESS_DELAY+CAM_EMUL_KEYPRESS_DURATION) 
 145                 kbd_key_release(conf.alt_mode_button);
 146             return 1;
 147         } 
 148         else if (kbd_get_pressed_key() == 0)
 149         {
 150             if (key_pressed < CAM_EMUL_KEYPRESS_DELAY)
 151             {
 152                 if (!kbd_blocked)
 153                 {
 154                     // if start script on alt set, flag to run it
 155                     if(conf.script_startup==SCRIPT_AUTOSTART_ALT) script_run_on_alt_flag = 1;
 156                     enter_alt();
 157                 }
 158                 else
 159                     exit_alt();
 160             }
 161             key_pressed = 0;
 162             return 1;
 163         }
 164         return 1;
 165     }
 166        
 167     // auto iso shift
 168     if (camera_info.state.is_shutter_half_press && kbd_is_key_pressed(conf.alt_mode_button)) 
 169         return 0;
 170 
 171     if (kbd_is_key_pressed(conf.alt_mode_button)) 
 172         {
 173         key_pressed = 1;
 174         kbd_key_release_all();          
 175         return 1;
 176     }
 177 
 178 #ifdef CAM_TOUCHSCREEN_UI
 179     extern int ts_process_touch();
 180     if (ts_process_touch())
 181     {
 182         gui_set_need_restore();
 183     }
 184 #endif
 185 
 186     // deals with the rest
 187 
 188     if ( !kbd_blocked || usb_remote_active ) 
 189         {
 190                 kbd_blocked = handle_usb_remote();
 191         }
 192 
 193     if (gui_kbd_process())
 194         return 1;
 195 
 196     action_stack_process_all();
 197 
 198     // Check if a PTP script needs to be started
 199     //  do this after action_stack_process_all so new script is not run until next timeslice
 200     extern void start_ptp_script();
 201     start_ptp_script();
 202 
 203     return kbd_blocked;
 204 }

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