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