root/platform/ixus240_elph320hs/kbd.c

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

DEFINITIONS

This source file includes following definitions.
  1. get_usb_bit
  2. kbd_force_analog_av
  3. get_usb_bit_physw_mod
  4. set_tv_video
  5. set_av_video
  6. set_sv_video
  7. set_ev_video_avail
  8. ts_video_nd
  9. ts_video_ev
  10. ts_video_tv_dn
  11. ts_video_tv_up
  12. ts_video_av_dn
  13. ts_video_av_up
  14. ts_video_sv_dn
  15. ts_video_sv_up
  16. ts_pg_dn
  17. ts_pg_up
  18. is_button_displayed
  19. is_button_active
  20. show_virtual_buttons
  21. draw_test_pixel
  22. chdk_process_touch
  23. virtual_buttons
  24. ts_process_touch
  25. mykbd_task_proceed
  26. mykbd_task
  27. wrap_kbd_p1_f
  28. my_kbd_read_keys
  29. kbd_key_press
  30. kbd_key_release
  31. kbd_key_release_all
  32. kbd_is_key_pressed
  33. kbd_is_key_clicked
  34. kbd_get_pressed_key
  35. kbd_get_clicked_key

   1 #include "lolevel.h"
   2 #include "platform.h"
   3 #include "core.h"
   4 #include "conf.h"
   5 #include "keyboard.h"
   6 #include "touchscreen.h"
   7 #include "gui.h"
   8 #include "gui_draw.h"
   9 #include "gui_osd.h"
  10 #include "levent.h"
  11 
  12 
  13 typedef struct {
  14     short grp;
  15     short hackkey;
  16     long canonkey;
  17     short   x1, y1, x2, y2;
  18     short   redraw;
  19     char    *nm, *nm2;
  20     int     min_gui_mode, max_gui_mode, cam_mode_mask;
  21     int     *conf_val;
  22     const char* (*chg_val)(int,int);
  23     int     *conf_disable;
  24 } KeyMap;
  25 
  26 static long kbd_new_state[4] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
  27 static long kbd_prev_state[4] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
  28 static long kbd_mod_state[4] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
  29 static long touch_panel_state;
  30 
  31 extern void _GetKbdState(long*);
  32 
  33 //#define DELAY_TIMEOUT 10000
  34 // override key and feather bits to avoid feather osd messing up chdk display in ALT mode
  35 #define KEYS_MASK0         (0x00000000) //Logic OR of group 0 Keymap values
  36 #define KEYS_MASK1         (0x2F000000) //Logic OR of group 1 Keymap values
  37 #define KEYS_MASK2         (0x00000000) //Logic OR of group 2 Keymap values
  38 
  39 #define SD_READONLY_FLAG    0x00008000 // Found @0xff5ac30c, levent 0x20a
  40 #define SD_READONLY_IDX     0
  41 #define USB_MASK            0x40000000 // Found @0xff5ac38c, levent 0x202
  42 #define USB_IDX             2
  43 
  44 #define KBD_SIMULATE_VIDEO_KEY 1 // use logical event to simulate video key
  45 
  46 int get_usb_bit()
  47 {
  48         long usb_physw[3];
  49         usb_physw[USB_IDX] = 0;
  50         _kbd_read_keys_r2(usb_physw);
  51         return(( usb_physw[USB_IDX] & USB_MASK)==USB_MASK) ;
  52 }
  53 
  54 // required because this platform uses KBD_CUSTOM_ALL
  55 int kbd_force_analog_av(__attribute__ ((unused))int state)
  56 {
  57     return 0;
  58 }
  59 
  60 int get_usb_bit_physw_mod(void)
  61 {
  62     if((physw_status[USB_IDX] & USB_MASK) == USB_MASK) {
  63         return 1;
  64     }
  65     return 0;
  66 }
  67 
  68 #define TS_KEY_TOGGLE_RAW   200
  69 #define TS_KEY_TOGGLE_ZEBRA 201
  70 #define TS_KEY_TOGGLE_HISTO 202
  71 #define TS_KEY_TOGGLE_OSD   203
  72 #define TS_KEY_TOGGLE_OVRD  204
  73 #define TS_KEY_TOGGLE_EDGE  205
  74 #define TS_KEY_TOGGLE_ND    206
  75 #define TS_KEY_TOGGLE_EV    207
  76 #define TS_KEY_TOGGLE_TV_DN 208
  77 #define TS_KEY_TOGGLE_TV_UP 209
  78 #define TS_KEY_TOGGLE_AV_DN 210
  79 #define TS_KEY_TOGGLE_AV_UP 211
  80 #define TS_KEY_TOGGLE_SV_DN 212
  81 #define TS_KEY_TOGGLE_SV_UP 213
  82 #define TS_KEY_PLAYBACK     214
  83 #define TS_KEY_POWER        215
  84 
  85 #define TS_UP_DN_BUTTON     300
  86 #define TS_PG_DN            301
  87 #define TS_PG_UP            302
  88 
  89 #define TS_XL   2
  90 #define TS_W    55
  91 #define TS_YT   1
  92 #define TS_H    44
  93 #define TS_XR   (480-TS_W-2)
  94 #define LB(x,n) TS_XL+x*TS_W, TS_YT+n*TS_H, TS_XL+(x+1)*TS_W, TS_YT+n*TS_H+TS_H
  95 #define RB(x,n) TS_XR-x*TS_W, TS_YT+n*TS_H, TS_XR+TS_W-x*TS_W, TS_YT+n*TS_H+TS_H
  96 #define RBW(x,n) TS_XR-TS_W-x*TS_W, TS_YT+n*TS_H, TS_XR+TS_W-x*TS_W, TS_YT+n*TS_H+TS_H
  97 
  98 extern const char* gui_on_off_enum(int change, int arg);
  99 extern const char* gui_histo_show_enum(int change, int arg);
 100 extern const char* gui_nd_filter_state_enum(int change, int arg);
 101 extern const char* gui_override_disable_enum(int change, int arg);
 102 
 103 #define MODE_VID    0x400
 104 
 105 int video_ael;
 106 int tv_video;
 107 int av_video;
 108 int sv_video;
 109 int tv_min_video;
 110 extern short cds_gain_value;
 111 
 112 void set_tv_video(int x)
 113 {
 114     if (video_ael)
 115     {
 116         if (x < tv_min_video) x = tv_min_video;
 117         if (x > 1152) x = 1152;
 118         if (tv_video != x)
 119         {
 120             tv_video = x;
 121             tv_video = _SetAE_ShutterSpeed((short*)&tv_video);
 122         }
 123     }
 124 }
 125 
 126 void set_av_video(int x)
 127 {
 128     if (video_ael)
 129     {
 130         if (x < 200) x = 200;
 131         if (x > 576) x = 576;
 132         if (av_video != x)
 133         {
 134             av_video = x;
 135             shooting_set_av96_direct(av_video,1);
 136             extern int _MoveIrisWithAv(short*);
 137             _MoveIrisWithAv((short*)&av_video);
 138             _GetPropertyCase(PROPCASE_AV,&av_video,2);
 139         }
 140     }
 141 }
 142 
 143 void set_sv_video(int x)
 144 {
 145     if (video_ael)
 146     {
 147         if (x < 0) x = 0;
 148         if (x > 768) x = 768;
 149         sv_video = x;
 150 
 151         extern int _SetCDSGain(short*);
 152         _SetCDSGain((short*)&sv_video);
 153 
 154         extern int _GetCdsGainValue();
 155         sv_video = _GetCdsGainValue();
 156     }
 157 }
 158 
 159 void set_ev_video_avail(int x)
 160 {
 161     if (video_ael == x) return;
 162     video_ael = x;
 163     if (x)
 164     {
 165         av_video = tv_video = 0;
 166 
 167         _ExpCtrlTool_StopContiAE(0,0);
 168 
 169         _GetPropertyCase(PROPCASE_TV,&tv_video,2);
 170         _GetPropertyCase(PROPCASE_AV,&av_video,2);
 171         sv_video = cds_gain_value;
 172 
 173         if ((mode_get()&MODE_SHOOTING_MASK)==MODE_VIDEO_SPEED) tv_min_video=577;  // 1/60
 174         else tv_min_video=441;  //480; //1/30
 175     }
 176     else
 177         _ExpCtrlTool_StartContiAE(0,0);
 178 }
 179 
 180 const char* ts_video_nd(int change, int arg)
 181 {
 182     const char *rv = gui_nd_filter_state_enum(change, arg);
 183     if (change && video_ael)
 184     {
 185         shooting_set_nd_filter_state(*(int*)arg,1);
 186     }
 187     return rv;
 188 }
 189 
 190 const char* ts_video_ev(int change, int arg)
 191 {
 192     if (change)
 193     {
 194         set_ev_video_avail(!video_ael);
 195         // force ND off unless AEL enabled
 196         shooting_set_nd_filter_state((video_ael)?conf.nd_filter_state:2,1);
 197     }
 198     return gui_on_off_enum(0, arg);
 199 }
 200 
 201 static char ev_tv[15];
 202 
 203 const char* ts_video_tv_dn(int change, __attribute__ ((unused))int arg)
 204 {
 205     if (change)
 206     {
 207         set_tv_video(tv_video - 32);
 208     }
 209     sprintf(ev_tv,"%4d",tv_video);
 210     return ev_tv;
 211 }
 212 
 213 const char* ts_video_tv_up(int change, __attribute__ ((unused))int arg)
 214 {
 215     if (change)
 216     {
 217         set_tv_video(tv_video + 32);
 218     }
 219     sprintf(ev_tv,"%4d",tv_video);
 220     return ev_tv;
 221 }
 222 
 223 static char ev_av[15];
 224 
 225 const char* ts_video_av_dn(int change,__attribute__ ((unused)) int arg)
 226 {
 227     if (change)
 228     {
 229         set_av_video(av_video - 32);
 230     }
 231     sprintf(ev_av,"%4d",av_video);
 232     return ev_av;
 233 }
 234 
 235 const char* ts_video_av_up(int change, __attribute__ ((unused))int arg)
 236 {
 237     if (change)
 238     {
 239         set_av_video(av_video + 32);
 240     }
 241     sprintf(ev_av,"%4d",av_video);
 242     return ev_av;
 243 }
 244 
 245 static char ev_sv[15];
 246 
 247 const char* ts_video_sv_dn(int change, __attribute__ ((unused))int arg)
 248 {
 249     if (change)
 250     {
 251         set_sv_video(sv_video - 32);
 252     }
 253     sprintf(ev_sv,"%4d",sv_video);
 254     return ev_sv;
 255 }
 256 
 257 const char* ts_video_sv_up(int change, __attribute__ ((unused))int arg)
 258 {
 259     if (change)
 260     {
 261         set_sv_video(sv_video + 32);
 262     }
 263     sprintf(ev_sv,"%4d",sv_video);
 264     return ev_sv;
 265 }
 266 
 267 static char debug_pg[15];
 268 
 269 const char* ts_pg_dn(int change, int arg)
 270 {
 271     if (change)
 272     {
 273         if ((*(int*)arg) > 0) (*(int*)arg)--;
 274     }
 275     sprintf(debug_pg,"%4d",(*(int*)arg));
 276     return debug_pg;
 277 }
 278 
 279 const char* ts_pg_up(int change, int arg)
 280 {
 281     if (change)
 282     {
 283         (*(int*)arg)++;
 284     }
 285     sprintf(debug_pg,"%4d",(*(int*)arg));
 286     return debug_pg;
 287 }
 288 
 289 static KeyMap keymap[] = {
 290     // Order IS important. kbd_get_pressed_key will walk down this table
 291     // and take the first matching mask. Notice that KEY_SHOOT_HALF is
 292     // always pressed if KEY_SHOOT_FULL is. --MarcusSt
 293 //  { 1, TOUCH_SCREEN       , 0x00000008, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },  // Touch screen panel
 294 //  { 1, KEY_POWER           ,0x00800000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // Found @0xff5ac2f0, levent 0x100
 295     { 1, KEY_PLAYBACK        ,0x01000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // Found @0xff5ac2f8, levent 0x101
 296     { 1, KEY_SHOOT_FULL      ,0x06000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // Found @0xff5ac308, levent 0x01
 297     { 1, KEY_SHOOT_FULL_ONLY ,0x04000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // Found @0xff5ac308, levent 0x01
 298     { 1, KEY_SHOOT_HALF      ,0x02000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // Found @0xff5ac300, levent 0x00
 299     { 1, KEY_ZOOM_OUT        ,0x08000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // Found @0xff5ac310, levent 0x03
 300     { 1, KEY_ZOOM_IN         ,0x20000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // Found @0xff5ac318, levent 0x02
 301 
 302     { 3, KEY_PRINT          , 0x00000001, LB(0,1), 0, "CHDK",  0,    GUI_MODE_NONE,      100, MODE_REC|MODE_PLAY|MODE_VID, 0, 0, 0 }, // virtual touch screen key
 303 
 304     //{ 3, TS_PG_DN, 0x40000000, RB(2,0), 0, "Pg -", 2, GUI_MODE_NONE, GUI_MODE_ALT, MODE_REC|MODE_PLAY|MODE_VID, &conf.debug_propcase_page, ts_pg_dn },
 305     //{ 3, TS_PG_UP, 0x80000000, RB(1,0), 0, "Pg +", 2, GUI_MODE_NONE, GUI_MODE_ALT, MODE_REC|MODE_PLAY|MODE_VID, &conf.debug_propcase_page, ts_pg_up },
 306 
 307     { 3, TS_KEY_TOGGLE_EV   , 0x00008000, RB(0,2), 2, "AEL",       0,GUI_MODE_NONE, GUI_MODE_NONE, MODE_VID, &video_ael, ts_video_ev,   &conf.touchscreen_disable_video_controls },
 308     { 3, TS_UP_DN_BUTTON    , 0,         RBW(0,4), 2, " - Tv %s +",0,GUI_MODE_NONE, GUI_MODE_NONE, MODE_VID, &tv_video, ts_video_tv_dn, &conf.touchscreen_disable_video_controls },
 309     { 3, TS_KEY_TOGGLE_TV_DN, 0x00010000, RB(1,4), 2, 0,  0,         GUI_MODE_NONE, GUI_MODE_NONE, MODE_VID, &tv_video, ts_video_tv_dn, &conf.touchscreen_disable_video_controls },
 310     { 3, TS_KEY_TOGGLE_TV_UP, 0x00020000, RB(0,4), 2, 0,  0,         GUI_MODE_NONE, GUI_MODE_NONE, MODE_VID, &tv_video, ts_video_tv_up, &conf.touchscreen_disable_video_controls },
 311     { 3, TS_UP_DN_BUTTON    , 0,         RBW(2,4), 2, " - Av %s +",0,GUI_MODE_NONE, GUI_MODE_NONE, MODE_VID, &av_video, ts_video_av_dn, &conf.touchscreen_disable_video_controls },
 312     { 3, TS_KEY_TOGGLE_AV_DN, 0x00040000, RB(3,4), 2, 0,  0,         GUI_MODE_NONE, GUI_MODE_NONE, MODE_VID, &av_video, ts_video_av_dn, &conf.touchscreen_disable_video_controls },
 313     { 3, TS_KEY_TOGGLE_AV_UP, 0x00080000, RB(2,4), 2, 0,  0,         GUI_MODE_NONE, GUI_MODE_NONE, MODE_VID, &av_video, ts_video_av_up, &conf.touchscreen_disable_video_controls },
 314     { 3, TS_UP_DN_BUTTON    , 0,         RBW(4,4), 2, " - Sv %s +",0,GUI_MODE_NONE, GUI_MODE_NONE, MODE_VID, &sv_video, ts_video_sv_dn, &conf.touchscreen_disable_video_controls },
 315     { 3, TS_KEY_TOGGLE_SV_DN, 0x00100000, RB(5,4), 2, 0,  0,         GUI_MODE_NONE, GUI_MODE_NONE, MODE_VID, &sv_video, ts_video_sv_dn, &conf.touchscreen_disable_video_controls },
 316     { 3, TS_KEY_TOGGLE_SV_UP, 0x00200000, RB(4,4), 2, 0,  0,         GUI_MODE_NONE, GUI_MODE_NONE, MODE_VID, &sv_video, ts_video_sv_up, &conf.touchscreen_disable_video_controls },
 317     { 3, TS_KEY_TOGGLE_ND   , 0x00004000, LB(0,4), 2, "ND",    0,    GUI_MODE_NONE, GUI_MODE_NONE, MODE_VID, &conf.nd_filter_state, ts_video_nd, &conf.touchscreen_disable_video_controls },
 318 
 319     { 3, KEY_MENU           , 0x00000002, LB(0,2), 0, "Menu",  0, GUI_MODE_ALT, 100, MODE_REC|MODE_PLAY, 0, 0, 0 },
 320     { 3, KEY_SET            , 0x00000004, LB(0,3), 0, "Set",   0, GUI_MODE_ALT, 100, MODE_REC|MODE_PLAY, 0, 0, 0 },
 321 
 322     { 3, TS_KEY_TOGGLE_RAW  , 0x00000100, RB(1,1), 1, "RAW",   0, GUI_MODE_ALT, GUI_MODE_ALT, MODE_REC|MODE_PLAY, &conf.save_raw, gui_on_off_enum, &conf.touchscreen_disable_shortcut_controls },
 323     { 3, TS_KEY_TOGGLE_OSD  , 0x00000200, RB(1,2), 1, "OSD",   0, GUI_MODE_ALT, GUI_MODE_ALT, MODE_REC|MODE_PLAY, &conf.show_osd, gui_on_off_enum, &conf.touchscreen_disable_shortcut_controls },
 324     { 3, TS_KEY_TOGGLE_OVRD , 0x00000400, RB(1,3), 1, "OvrDis",0, GUI_MODE_ALT, GUI_MODE_ALT, MODE_REC|MODE_PLAY, &conf.override_disable, gui_override_disable_enum, &conf.touchscreen_disable_shortcut_controls },
 325     { 3, TS_KEY_TOGGLE_ZEBRA, 0x00000800, RB(2,1), 1, "Zebra", 0, GUI_MODE_ALT, GUI_MODE_ALT, MODE_REC|MODE_PLAY, &conf.zebra_draw, gui_on_off_enum, &conf.touchscreen_disable_shortcut_controls },
 326     { 3, TS_KEY_TOGGLE_HISTO, 0x00001000, RB(2,2), 1, "Hist",  0, GUI_MODE_ALT, GUI_MODE_ALT, MODE_REC|MODE_PLAY, &conf.show_histo, gui_histo_show_enum, &conf.touchscreen_disable_shortcut_controls },
 327     { 3, TS_KEY_TOGGLE_EDGE , 0x00002000, RB(2,3), 1, "Edge",  0, GUI_MODE_ALT, GUI_MODE_ALT, MODE_REC|MODE_PLAY, &conf.edge_overlay_enable, gui_on_off_enum, &conf.touchscreen_disable_shortcut_controls },
 328 
 329 #if defined(TS_PLAY_POWER_HACK)
 330     { 3, TS_KEY_PLAYBACK    , 0x00400000, LB(1,0), 0, "PLAY",  0,    GUI_MODE_ALT,       GUI_MODE_ALT,  MODE_REC|MODE_PLAY, &playbutton_hack, simulate_playback_press, 0 },
 331     { 3, TS_KEY_POWER       , 0x00800000, LB(3,0), 0, "OFF",   0,    GUI_MODE_ALT,       GUI_MODE_ALT,  MODE_REC|MODE_PLAY, &playbutton_hack, simulate_power_press, 0 },
 332 #endif
 333 #ifdef OPT_DEBUGGING
 334     { 3, KEY_DISPLAY        , 0x00000008, LB(0,4), 0, "Debug", 0,    GUI_MODE_ALT,       GUI_MODE_ALT,  MODE_REC|MODE_PLAY, 0, 0, 0 },
 335 #endif
 336     { 3, KEY_DISPLAY        , 0x00000008, LB(0,4), 0, "Back",  0,    GUI_MODE_MENU,      GUI_MODE_MENU, MODE_REC|MODE_PLAY, 0, 0, 0 },
 337     { 3, KEY_DISPLAY        , 0x00000008, LB(0,4), 0, "Disp",  0,    GUI_MODE_MENU+1,    100,           MODE_REC|MODE_PLAY, 0, 0, 0 },
 338     { 3, KEY_UP             , 0x00000010, RB(0,1), 0, "Up",    0,    GUI_MODE_MENU,      100,           MODE_REC|MODE_PLAY, 0, 0, 0 },
 339     { 3, KEY_LEFT           , 0x00000020, RB(0,2), 0, "Left",  0,    GUI_MODE_MENU,      100,           MODE_REC|MODE_PLAY, 0, 0, 0 },
 340     { 3, KEY_RIGHT          , 0x00000040, RB(0,3), 0, "Right", 0,    GUI_MODE_MENU,      100,           MODE_REC|MODE_PLAY, 0, 0, 0 },
 341     { 3, KEY_DOWN           , 0x00000080, RB(0,4), 0, "Down",  0,    GUI_MODE_MENU,      100,           MODE_REC|MODE_PLAY, 0, 0, 0 },
 342 
 343     { 3, KEY_UP             , 0x00000010, RB(0,1), 0, "Man",   "Focus",  GUI_MODE_ALT, GUI_MODE_ALT, MODE_REC, &conf.subj_dist_override_koef, 0, &conf.touchscreen_disable_shortcut_controls },
 344     { 3, KEY_DISPLAY        , 0x00000008, RB(0,2), 0, "Max",   "Dist",   GUI_MODE_ALT, GUI_MODE_ALT, MODE_REC, 0, 0, &conf.touchscreen_disable_shortcut_controls },
 345     { 3, KEY_DOWN           , 0x00000080, RB(0,3), 0, "Hyper", "Dist",   GUI_MODE_ALT, GUI_MODE_ALT, MODE_REC, 0, 0, &conf.touchscreen_disable_shortcut_controls },
 346     { 3, KEY_LEFT           , 0x00000020, RB(2,4), 0, "- Foc.","Factor", GUI_MODE_ALT, GUI_MODE_ALT, MODE_REC, 0, 0, &conf.touchscreen_disable_shortcut_controls },
 347     { 3, KEY_RIGHT          , 0x00000040, RB(1,4), 0, "+ Foc.","Factor", GUI_MODE_ALT, GUI_MODE_ALT, MODE_REC, 0, 0, &conf.touchscreen_disable_shortcut_controls },
 348 
 349     { 0 }
 350 };
 351 
 352 static int is_button_displayed(int b, int guiMode, int camMode)
 353 {
 354     return (
 355             (keymap[b].grp == 3) &&
 356             (guiMode >= keymap[b].min_gui_mode) &&
 357             (guiMode <= keymap[b].max_gui_mode) &&
 358             (camMode & keymap[b].cam_mode_mask) &&
 359             ((keymap[b].conf_disable == 0) || (*keymap[b].conf_disable == 0))
 360            );
 361 }
 362 
 363 static int is_button_active(int b, int guiMode, int camMode)
 364 {
 365     return (is_button_displayed(b, guiMode, camMode) && keymap[b].canonkey);
 366 }
 367 
 368 int show_virtual_buttons()
 369 {
 370     // The canon_playback_menu_active check prevents the CHDK button from being shown in rec mode
 371     // The variable does not appear to be equivalent to the variable used in ixus500_elph310hs
 372     /*
 373     extern char canon_play_menu_active;
 374     return (canon_menu_active==(int)&canon_menu_active-4) && (canon_shoot_menu_active==0) && (canon_play_menu_active == 0);
 375     */
 376     return (canon_menu_active==(int)&canon_menu_active-4) && (canon_shoot_menu_active==0);
 377 }
 378 
 379 
 380 // Test a pixel value of the CHDK on-screen button to see if it may have been erased
 381 static int draw_test_pixel(coord x, coord y, color c)
 382 {
 383     extern char* bitmap_buffer[];
 384     extern int active_bitmap_buffer;
 385     return (bitmap_buffer[active_bitmap_buffer][y * camera_screen.buffer_width + ASPECT_XCORRECTION(x)] == c);
 386 }
 387 //int ts_proc_cnt = 0;
 388 //int ts_redraw_cnt = 0;
 389 //int ts_check_cnt = 0;
 390 
 391 // Called from hooked touch panel task (boot.c)
 392 // Return 0 to allow touch event to pass onto firmware, 1 to block event from firmware.
 393 int chdk_process_touch()
 394 {
 395     //ts_check_cnt++;
 396 
 397     // If in canon menu, let the firmware have all the touch events.
 398     if (!show_virtual_buttons()) return 0;
 399 
 400     int guiMode = camera_info.state.gui_mode;
 401     int camMode = (get_movie_status()==VIDEO_RECORD_IN_PROGRESS) ? MODE_VID : (mode_get() & MODE_MASK);
 402 
 403     // Touch co-ordinate
 404     unsigned short tx, ty;
 405     tx = ((touch_screen_x & 0x7FFF) >> 2) ^ 0x3FF; //ixus240.101a @ loc_ff069d58
 406     ty = ((touch_screen_y & 0x7FFF) >> 2) ^ 0x3FF;
 407 
 408 
 409     // map touch coordinates to screen (try&error values)
 410     tx = (tx - 190) * 0.74;
 411     ty = (ty - 330) * 0.65;
 412 
 413     // Search for CHDK on screen buttons matching co-ordinate
 414     int i;
 415     for (i=0; keymap[i].hackkey; i++)
 416     {
 417         if ((tx >= keymap[i].x1) && (tx < keymap[i].x2) && (ty >= keymap[i].y1) && (ty < keymap[i].y2) && is_button_active(i,guiMode,camMode))
 418         {
 419             touch_panel_state &= ~keymap[i].canonkey;
 420         }
 421    }
 422     // If in alt mode (or about to enter alt mode) set the touch koords to 0x0 to block it from firmware
 423     if((guiMode != 0) || (((touch_panel_state & 1) == 0) && ((kbd_mod_state[3] & 1) != 0)))
 424     {
 425         touch_screen_x=touch_screen_y=0 ^ 0x3FF;
 426     }
 427     // let the firmware handle a touch press
 428     // otherwise it wont set touch_screen_active to 1
 429     return 0;
 430 
 431     // If in alt mode (or about to enter alt mode) block event from firmware
 432 //    return (guiMode != 0) || (((touch_panel_state & 1) == 0) && ((kbd_mod_state[3] & 1) != 0));
 433 }
 434 
 435 int redraw_buttons = 1;
 436 int print_key_index = -1;
 437 
 438 void virtual_buttons()
 439 {
 440     int guiMode = camera_info.state.gui_mode;
 441     char buf[30];
 442 
 443     // If shooting or in any Canon menus then don't display any CHDK buttons
 444     if (((guiMode == 0) && camera_info.state.is_shutter_half_press) || !show_virtual_buttons()) return;
 445 
 446 //    if(print_key_index == -1)
 447 //    {
 448 //        // need to find index of print key to check boarders in next step
 449 //        int i;
 450 //        for (i=0; keymap[i].hackkey != KEY_PRINT; i++);
 451 //        print_key_index = i;
 452 //    }
 453 
 454     // Check if border of CHDK button is corrupted, force redraw if so
 455 //    if(print_key_index != -1 && !draw_test_pixel(keymap[print_key_index].x1+1, keymap[print_key_index].y1+1, (guiMode)?COLOR_GREEN:COLOR_WHITE)) redraw_buttons = 1;
 456     if (!draw_test_pixel(0, 80, (guiMode)?COLOR_GREEN:COLOR_WHITE)) redraw_buttons = 1;
 457 
 458     if (redraw_buttons)
 459     {
 460         //ts_redraw_cnt++;
 461 
 462         int i, x1, y1, x2, y2, ofst;
 463         int camMode = (get_movie_status()==VIDEO_RECORD_IN_PROGRESS) ? MODE_VID : (mode_get() & MODE_MASK);
 464 
 465         //color c1 = MAKE_COLOR((camMode&MODE_VID)?COLOR_TRANSPARENT:COLOR_BLACK, COLOR_WHITE);
 466         //color c2 = MAKE_COLOR((camMode&MODE_VID)?COLOR_TRANSPARENT:COLOR_RED, (camMode&MODE_VID)?COLOR_RED:COLOR_WHITE);
 467         twoColors c1 = MAKE_COLOR((camMode&MODE_VID)?COLOR_TRANSPARENT:COLOR_BLACK, COLOR_WHITE);
 468         twoColors c2 = MAKE_COLOR((camMode&MODE_VID)?COLOR_TRANSPARENT:COLOR_BLACK, COLOR_GREEN);
 469 
 470         for (i=0; keymap[i].hackkey; i++)
 471         {
 472             if (is_button_displayed(i, guiMode, camMode) && keymap[i].nm)
 473             {
 474                 x1 = keymap[i].x1;
 475                 x2 = keymap[i].x2;
 476                 y1 = keymap[i].y1;
 477                 y2 = keymap[i].y2;
 478 
 479                 twoColors cl = c1;
 480                 if (guiMode && (keymap[i].hackkey == KEY_PRINT)) cl = c2;
 481                 if (keymap[i].conf_val && *keymap[i].conf_val) cl = c2;
 482 
 483                 draw_rectangle(x1, y1, x2, y2, cl, RECT_BORDER3|DRAW_FILLED|RECT_ROUND_CORNERS);
 484 
 485                 ofst = 16;
 486                 if (keymap[i].hackkey == TS_UP_DN_BUTTON)
 487                 {
 488                     // unclear what was supposed to be displayed here
 489                     // use hard coded string rather than uninitialized buffer
 490 //                    draw_string(x1+4, y1+ofst, buf, cl);
 491                     draw_string(x1+4, y1+ofst, "UD!", cl);
 492                 }
 493                 else
 494                 {
 495                     if (keymap[i].conf_val && keymap[i].chg_val)
 496                     {
 497                         ofst = 7;
 498                         strcpy(buf,(char*)keymap[i].chg_val(0,(int)keymap[i].conf_val));
 499                         buf[6] = 0;
 500                         draw_string(x1+4, y1+25, buf, cl);
 501                     }
 502                     else if (keymap[i].nm2)
 503                     {
 504                         ofst = 7;
 505                         draw_string(x1+4, y1+25, keymap[i].nm2, cl);
 506                     }
 507                     draw_string(x1+4, y1+ofst, keymap[i].nm, cl);
 508                 }
 509             }
 510         }
 511     }
 512 
 513     redraw_buttons = 0;
 514 }
 515 
 516 int ts_process_touch()
 517 {
 518     int rv = 0, i;
 519 
 520     if (touch_panel_state != (long)0xFFFFFFFF)
 521     {
 522         int guiMode = camera_info.state.gui_mode;
 523         int camMode = (get_movie_status()==VIDEO_RECORD_IN_PROGRESS) ? MODE_VID : (mode_get() & MODE_MASK);
 524 
 525         //ts_proc_cnt++;
 526 
 527         for (i=0; keymap[i].hackkey; i++)
 528         {
 529             if (is_button_active(i, guiMode, camMode))
 530             {
 531                 if (kbd_is_key_clicked(keymap[i].hackkey))
 532                 {
 533                     if (keymap[i].conf_val && keymap[i].chg_val)
 534                     {
 535                         keymap[i].chg_val(1,(int)keymap[i].conf_val);
 536                         rv = keymap[i].redraw & 1;
 537                     }
 538                     if (keymap[i].redraw & 2) redraw_buttons = 1;
 539                 }
 540             }
 541         }
 542     }
 543 
 544     return rv;
 545 }
 546 
 547 long __attribute__((naked)) wrap_kbd_p1_f() ;
 548 
 549 
 550 static void __attribute__((noinline)) mykbd_task_proceed()
 551 {
 552     while (physw_run) {
 553         _SleepTask(physw_sleep_delay);
 554 
 555         if (wrap_kbd_p1_f() == 1) {   // autorepeat ?
 556             _kbd_p2_f();
 557         }
 558     }
 559 }
 560 
 561 // no stack manipulation needed here, since we create the task directly
 562 void __attribute__((naked,noinline))
 563 mykbd_task()
 564 {
 565     mykbd_task_proceed();
 566 
 567     _ExitTask();
 568 }
 569 
 570 long __attribute__((naked,noinline)) wrap_kbd_p1_f()
 571 {
 572     asm volatile(
 573         "STMFD   SP!, {R1-R7,LR}\n"
 574         "MOV     R5, #0\n"
 575         //"BL      _kbd_read_keys \n"
 576         "BL        my_kbd_read_keys\n"
 577         "B       _kbd_p1_f_cont\n"
 578     );
 579     return 0; // shut up the compiler
 580 }
 581 
 582 void my_kbd_read_keys()
 583 {
 584     kbd_prev_state[0] = kbd_new_state[0];
 585     kbd_prev_state[1] = kbd_new_state[1];
 586     kbd_prev_state[2] = kbd_new_state[2];
 587     kbd_prev_state[3] = kbd_new_state[3];
 588 
 589     _GetKbdState(kbd_new_state);
 590     _kbd_read_keys_r2(kbd_new_state);
 591     if (touch_screen_active == 1)               // Touch screen activated?
 592     {
 593         kbd_new_state[3] = touch_panel_state;               // Yes, use virtual button state
 594     }
 595     else
 596     {
 597         kbd_new_state[3] = touch_panel_state = 0xFFFFFFFF;  // No, clear out virtual button state
 598     }
 599 
 600     if (kbd_process() == 0) {
 601         // leave it alone...
 602         // we read keyboard state with _kbd_read_keys()
 603         physw_status[0] = kbd_new_state[0];
 604         physw_status[1] = kbd_new_state[1];
 605         physw_status[2] = kbd_new_state[2];
 606     } else {
 607         // override keys
 608         physw_status[0] = (kbd_new_state[0] & (~KEYS_MASK0)) | (kbd_mod_state[0] & KEYS_MASK0);
 609         physw_status[1] = (kbd_new_state[1] & (~KEYS_MASK1)) | (kbd_mod_state[1] & KEYS_MASK1);
 610         physw_status[2] = (kbd_new_state[2] & (~KEYS_MASK2)) | (kbd_mod_state[2] & KEYS_MASK2);
 611     }
 612     physw_status[SD_READONLY_IDX] = physw_status[SD_READONLY_IDX] & ~SD_READONLY_FLAG;
 613 
 614     if (conf.remote_enable) {
 615         physw_status[USB_IDX] = physw_status[USB_IDX] & ~USB_MASK;
 616     }
 617 }
 618 
 619 
 620 /****************/
 621 #ifdef KBD_SIMULATE_VIDEO_KEY
 622 static int is_video_key_pressed = 0;
 623 #endif
 624 
 625 
 626 void kbd_key_press(long key)
 627 {
 628     int i;
 629 
 630 #ifdef KBD_SIMULATE_VIDEO_KEY
 631     if (key == KEY_VIDEO && !is_video_key_pressed)
 632     {
 633         // TODO define for ID would be more efficient
 634         PostLogicalEventToUI(levent_id_for_name("PressMovieButton"),0);
 635         is_video_key_pressed = 1;
 636         // TODO not clear if this should return, or set state too
 637         return;
 638     }
 639 #endif
 640 
 641     for (i=0;keymap[i].hackkey;i++) {
 642         if (keymap[i].hackkey == key)
 643         {
 644             kbd_mod_state[keymap[i].grp] &= ~keymap[i].canonkey;
 645             return;
 646         }
 647     }
 648 }
 649 
 650 void kbd_key_release(long key)
 651 {
 652 #ifdef KBD_SIMULATE_VIDEO_KEY
 653     if (key == KEY_VIDEO && is_video_key_pressed)
 654     {
 655         PostLogicalEventToUI(levent_id_for_name("UnpressMovieButton"),0);
 656         is_video_key_pressed = 0;
 657         return;
 658     }
 659 #endif
 660 
 661     int i;
 662     for (i=0;keymap[i].hackkey;i++) {
 663         if (keymap[i].hackkey == key) {
 664             kbd_mod_state[keymap[i].grp] |= keymap[i].canonkey;
 665             return;
 666         }
 667     }
 668 }
 669 
 670 void kbd_key_release_all()
 671 {
 672     kbd_mod_state[0] |= KEYS_MASK0;
 673     kbd_mod_state[1] |= KEYS_MASK1;
 674     kbd_mod_state[2] |= KEYS_MASK2;
 675     kbd_mod_state[3] = 0xFFFFFFFF;
 676 }
 677 
 678 long kbd_is_key_pressed(long key)
 679 {
 680     int i;
 681     for (i=0;keymap[i].hackkey;i++)
 682     {
 683         if ((keymap[i].hackkey == key) && keymap[i].canonkey)
 684         {
 685             return ((kbd_new_state[keymap[i].grp] & keymap[i].canonkey) == 0) ? 1:0;
 686         }
 687     }
 688     return 0;
 689 }
 690 
 691 long kbd_is_key_clicked(long key)
 692 {
 693     int i;
 694     for (i=0;keymap[i].hackkey;i++)
 695     {
 696         if ((keymap[i].hackkey == key) && keymap[i].canonkey)
 697         {
 698             return ((kbd_prev_state[keymap[i].grp] & keymap[i].canonkey) != 0) &&
 699             ((kbd_new_state[keymap[i].grp] & keymap[i].canonkey) == 0);
 700         }
 701     }
 702     return 0;
 703 }
 704 
 705 long kbd_get_pressed_key()
 706 {
 707     int i;
 708     for (i=0;keymap[i].hackkey;i++)
 709     {
 710         if (keymap[i].canonkey && ((kbd_new_state[keymap[i].grp] & keymap[i].canonkey) == 0))
 711         {
 712             return keymap[i].hackkey;
 713         }
 714     }
 715     return 0;
 716 }
 717 
 718 long kbd_get_clicked_key()
 719 {
 720     int i;
 721     for (i=0;keymap[i].hackkey;i++)
 722     {
 723         if (keymap[i].canonkey &&
 724             ((kbd_prev_state[keymap[i].grp] & keymap[i].canonkey) != 0) &&
 725             ((kbd_new_state[keymap[i].grp] & keymap[i].canonkey) == 0))
 726         {
 727             return keymap[i].hackkey;
 728         }
 729     }
 730     return 0;
 731 }

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