]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/common/command.c
Got ps2avrGB to work with the V-USB protocol
[qmk_firmware.git] / tmk_core / common / command.c
1 /*
2 Copyright 2011 Jun Wako <wakojun@gmail.com>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17 #include <stdint.h>
18 #include <stdbool.h>
19 #include "wait.h"
20 #include "keycode.h"
21 #include "host.h"
22 #include "keymap.h"
23 #include "print.h"
24 #include "debug.h"
25 #include "util.h"
26 #include "timer.h"
27 #include "keyboard.h"
28 #include "bootloader.h"
29 #include "action_layer.h"
30 #include "action_util.h"
31 #include "eeconfig.h"
32 #include "sleep_led.h"
33 #include "led.h"
34 #include "command.h"
35 #include "backlight.h"
36 #include "quantum.h"
37 #include "version.h"
38
39 #ifdef MOUSEKEY_ENABLE
40 #include "mousekey.h"
41 #endif
42
43 #ifdef PROTOCOL_PJRC
44         #include "usb_keyboard.h"
45                 #ifdef EXTRAKEY_ENABLE
46                 #include "usb_extra.h"
47         #endif
48 #endif
49
50 #ifdef PROTOCOL_VUSB
51         #include "usbdrv.h"
52 #endif
53
54 #ifdef AUDIO_ENABLE
55     #include "audio.h"
56 #endif /* AUDIO_ENABLE */
57
58
59 static bool command_common(uint8_t code);
60 static void command_common_help(void);
61 static void print_version(void);
62 static void print_status(void);
63 static bool command_console(uint8_t code);
64 static void command_console_help(void);
65 #ifdef MOUSEKEY_ENABLE
66 static bool mousekey_console(uint8_t code);
67 static void mousekey_console_help(void);
68 #endif
69
70 static void switch_default_layer(uint8_t layer);
71
72
73 command_state_t command_state = ONESHOT;
74
75
76 bool command_proc(uint8_t code)
77 {
78     switch (command_state) {
79         case ONESHOT:
80             if (!IS_COMMAND())
81                 return false;
82             return (command_extra(code) || command_common(code));
83             break;
84         case CONSOLE:
85             if (IS_COMMAND())
86                 return (command_extra(code) || command_common(code));
87             else
88                 return (command_console_extra(code) || command_console(code));
89             break;
90 #ifdef MOUSEKEY_ENABLE
91         case MOUSEKEY:
92             mousekey_console(code);
93             break;
94 #endif
95         default:
96             command_state = ONESHOT;
97             return false;
98     }
99     return true;
100 }
101
102 /* TODO: Refactoring is needed. */
103 /* This allows to define extra commands. return false when not processed. */
104 bool command_extra(uint8_t code) __attribute__ ((weak));
105 bool command_extra(uint8_t code)
106 {
107     (void)code;
108     return false;
109 }
110
111 bool command_console_extra(uint8_t code) __attribute__ ((weak));
112 bool command_console_extra(uint8_t code)
113 {
114     (void)code;
115     return false;
116 }
117
118
119 /***********************************************************
120  * Command common
121  ***********************************************************/
122 static void command_common_help(void)
123 {
124         print(                            "\n\t- Magic -\n"
125                 STR(MAGIC_KEY_DEBUG       ) ":  Debug Message Toggle\n"
126                 STR(MAGIC_KEY_DEBUG_MATRIX) ":  Matrix Debug Mode Toggle - Show keypresses in matrix grid\n"
127                 STR(MAGIC_KEY_DEBUG_KBD   ) ":  Keyboard Debug Toggle - Show keypress report\n"
128                 STR(MAGIC_KEY_DEBUG_MOUSE ) ":  Debug Mouse Toggle\n"
129                 STR(MAGIC_KEY_VERSION     ) ":  Version\n"
130                 STR(MAGIC_KEY_STATUS      ) ":  Status\n"
131                 STR(MAGIC_KEY_CONSOLE     ) ":  Activate Console Mode\n"
132
133 #if MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM
134                 STR(MAGIC_KEY_LAYER0      ) ":  Switch to Layer 0\n"
135                 STR(MAGIC_KEY_LAYER1      ) ":  Switch to Layer 1\n"
136                 STR(MAGIC_KEY_LAYER2      ) ":  Switch to Layer 2\n"
137                 STR(MAGIC_KEY_LAYER3      ) ":  Switch to Layer 3\n"
138                 STR(MAGIC_KEY_LAYER4      ) ":  Switch to Layer 4\n"
139                 STR(MAGIC_KEY_LAYER5      ) ":  Switch to Layer 5\n"
140                 STR(MAGIC_KEY_LAYER6      ) ":  Switch to Layer 6\n"
141                 STR(MAGIC_KEY_LAYER7      ) ":  Switch to Layer 7\n"
142                 STR(MAGIC_KEY_LAYER8      ) ":  Switch to Layer 8\n"
143                 STR(MAGIC_KEY_LAYER9      ) ":  Switch to Layer 9\n"
144 #endif
145
146 #if MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS
147                                             "F1-F10:    Switch to Layer 0-9 (F10 = L0)\n"
148 #endif
149
150 #if MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS
151                                             "0-9:       Switch to Layer 0-9\n"
152 #endif
153
154                 STR(MAGIC_KEY_LAYER0_ALT1 ) ":  Switch to Layer 0 (alternate key 1)\n"
155                 STR(MAGIC_KEY_LAYER0_ALT2 ) ":  Switch to Layer 0 (alternate key 2)\n"
156                 STR(MAGIC_KEY_BOOTLOADER  ) ":  Jump to Bootloader (Reset)\n"
157
158 #ifdef KEYBOARD_LOCK_ENABLE
159                 STR(MAGIC_KEY_LOCK        ) ":  Lock\n"
160 #endif
161
162 #ifdef BOOTMAGIC_ENABLE
163                 STR(MAGIC_KEY_EEPROM      ) ":  Print EEPROM Settings\n"
164 #endif
165
166 #ifdef NKRO_ENABLE
167                 STR(MAGIC_KEY_NKRO        ) ":  NKRO Toggle\n"
168 #endif
169
170 #ifdef SLEEP_LED_ENABLE
171                 STR(MAGIC_KEY_SLEEP_LED   ) ":  Sleep LED Test\n"
172 #endif
173     );
174 }
175
176 static void print_version(void)
177 {
178         // print version & information
179     print("\n\t- Version -\n");
180     print("DESC: " STR(DESCRIPTION) "\n");
181     print("VID: " STR(VENDOR_ID) "(" STR(MANUFACTURER) ") "
182           "PID: " STR(PRODUCT_ID) "(" STR(PRODUCT) ") "
183           "VER: " STR(DEVICE_VER) "\n");
184     print("BUILD: " STR(QMK_VERSION) " (" __TIME__ " " __DATE__ ")\n");
185
186     /* build options */
187     print("OPTIONS:"
188
189 #ifdef PROTOCOL_PJRC
190             " PJRC"
191 #endif
192 #ifdef PROTOCOL_LUFA
193             " LUFA"
194 #endif
195 #ifdef PROTOCOL_VUSB
196             " VUSB"
197 #endif
198 #ifdef BOOTMAGIC_ENABLE
199             " BOOTMAGIC"
200 #endif
201 #ifdef MOUSEKEY_ENABLE
202             " MOUSEKEY"
203 #endif
204 #ifdef EXTRAKEY_ENABLE
205             " EXTRAKEY"
206 #endif
207 #ifdef CONSOLE_ENABLE
208             " CONSOLE"
209 #endif
210 #ifdef COMMAND_ENABLE
211             " COMMAND"
212 #endif
213 #ifdef NKRO_ENABLE
214             " NKRO"
215 #endif
216 #ifdef KEYMAP_SECTION_ENABLE
217             " KEYMAP_SECTION"
218 #endif
219
220             " " STR(BOOTLOADER_SIZE) "\n");
221
222     print("GCC: " STR(__GNUC__) "." STR(__GNUC_MINOR__) "." STR(__GNUC_PATCHLEVEL__)
223 #if defined(__AVR__)
224           " AVR-LIBC: " __AVR_LIBC_VERSION_STRING__
225           " AVR_ARCH: avr" STR(__AVR_ARCH__)
226 #endif
227                   "\n");
228
229         return;
230 }
231
232 static void print_status(void)
233 {
234
235     print("\n\t- Status -\n");
236
237     print_val_hex8(host_keyboard_leds());
238 #ifndef PROTOCOL_VUSB
239     print_val_hex8(keyboard_protocol);
240     print_val_hex8(keyboard_idle);
241 #endif
242 #ifdef NKRO_ENABLE
243     print_val_hex8(keymap_config.nkro);
244 #endif
245     print_val_hex32(timer_read32());
246
247 #ifdef PROTOCOL_PJRC
248     print_val_hex8(UDCON);
249     print_val_hex8(UDIEN);
250     print_val_hex8(UDINT);
251     print_val_hex8(usb_keyboard_leds);
252     print_val_hex8(usb_keyboard_idle_count);
253 #endif
254
255 #ifdef PROTOCOL_PJRC
256 #   if USB_COUNT_SOF
257     print_val_hex8(usbSofCount);
258 #   endif
259 #endif
260         return;
261 }
262
263 #ifdef BOOTMAGIC_ENABLE
264 static void print_eeconfig(void)
265 {
266
267 // Print these variables if NO_PRINT or USER_PRINT are not defined.
268 #if !defined(NO_PRINT) && !defined(USER_PRINT)
269
270     print("default_layer: "); print_dec(eeconfig_read_default_layer()); print("\n");
271
272     debug_config_t dc;
273     dc.raw = eeconfig_read_debug();
274     print("debug_config.raw: "); print_hex8(dc.raw); print("\n");
275     print(".enable: "); print_dec(dc.enable); print("\n");
276     print(".matrix: "); print_dec(dc.matrix); print("\n");
277     print(".keyboard: "); print_dec(dc.keyboard); print("\n");
278     print(".mouse: "); print_dec(dc.mouse); print("\n");
279
280     keymap_config_t kc;
281     kc.raw = eeconfig_read_keymap();
282     print("keymap_config.raw: "); print_hex8(kc.raw); print("\n");
283     print(".swap_control_capslock: "); print_dec(kc.swap_control_capslock); print("\n");
284     print(".capslock_to_control: "); print_dec(kc.capslock_to_control); print("\n");
285     print(".swap_lalt_lgui: "); print_dec(kc.swap_lalt_lgui); print("\n");
286     print(".swap_ralt_rgui: "); print_dec(kc.swap_ralt_rgui); print("\n");
287     print(".no_gui: "); print_dec(kc.no_gui); print("\n");
288     print(".swap_grave_esc: "); print_dec(kc.swap_grave_esc); print("\n");
289     print(".swap_backslash_backspace: "); print_dec(kc.swap_backslash_backspace); print("\n");
290     print(".nkro: "); print_dec(kc.nkro); print("\n");
291
292 #ifdef BACKLIGHT_ENABLE
293     backlight_config_t bc;
294     bc.raw = eeconfig_read_backlight();
295     print("backlight_config.raw: "); print_hex8(bc.raw); print("\n");
296     print(".enable: "); print_dec(bc.enable); print("\n");
297     print(".level: "); print_dec(bc.level); print("\n");
298 #endif /* BACKLIGHT_ENABLE */
299
300 #endif /* !NO_PRINT */
301
302 }
303 #endif /* BOOTMAGIC_ENABLE */
304
305 static bool command_common(uint8_t code)
306 {
307
308 #ifdef KEYBOARD_LOCK_ENABLE
309     static host_driver_t *host_driver = 0;
310 #endif
311
312     switch (code) {
313
314 #ifdef SLEEP_LED_ENABLE
315
316                 // test breathing sleep LED
317         case MAGIC_KC(MAGIC_KEY_SLEEP_LED):
318             print("Sleep LED Test\n");
319             sleep_led_toggle();
320             led_set(host_keyboard_leds());
321             break;
322 #endif
323
324 #ifdef BOOTMAGIC_ENABLE
325
326                 // print stored eeprom config
327         case MAGIC_KC(MAGIC_KEY_EEPROM):
328             print("eeconfig:\n");
329             print_eeconfig();
330             break;
331 #endif
332
333 #ifdef KEYBOARD_LOCK_ENABLE
334
335                 // lock/unlock keyboard
336         case MAGIC_KC(MAGIC_KEY_LOCK):
337             if (host_get_driver()) {
338                 host_driver = host_get_driver();
339                 clear_keyboard();
340                 host_set_driver(0);
341                 print("Locked.\n");
342             } else {
343                 host_set_driver(host_driver);
344                 print("Unlocked.\n");
345             }
346             break;
347 #endif
348
349                 // print help
350         case MAGIC_KC(MAGIC_KEY_HELP1):
351         case MAGIC_KC(MAGIC_KEY_HELP2):
352             command_common_help();
353             break;
354
355                 // activate console
356         case MAGIC_KC(MAGIC_KEY_CONSOLE):
357             debug_matrix   = false;
358             debug_keyboard = false;
359             debug_mouse    = false;
360             debug_enable   = false;
361             command_console_help();
362             print("C> ");
363             command_state = CONSOLE;
364             break;
365
366         // jump to bootloader
367         case MAGIC_KC(MAGIC_KEY_BOOTLOADER):
368             clear_keyboard(); // clear to prevent stuck keys
369             print("\n\nJumping to bootloader... ");
370             #ifdef AUDIO_ENABLE
371                     stop_all_notes();
372                 shutdown_user();
373             #else
374                     wait_ms(1000);
375             #endif
376             bootloader_jump(); // not return
377             break;
378
379         // debug toggle
380         case MAGIC_KC(MAGIC_KEY_DEBUG):
381             debug_enable = !debug_enable;
382             if (debug_enable) {
383                 print("\ndebug: on\n");
384             } else {
385                 print("\ndebug: off\n");
386                 debug_matrix   = false;
387                 debug_keyboard = false;
388                 debug_mouse    = false;
389             }
390             break;
391
392         // debug matrix toggle
393         case MAGIC_KC(MAGIC_KEY_DEBUG_MATRIX):
394             debug_matrix = !debug_matrix;
395             if (debug_matrix) {
396                 print("\nmatrix: on\n");
397                 debug_enable = true;
398             } else {
399                 print("\nmatrix: off\n");
400             }
401             break;
402
403         // debug keyboard toggle
404         case MAGIC_KC(MAGIC_KEY_DEBUG_KBD):
405             debug_keyboard = !debug_keyboard;
406             if (debug_keyboard) {
407                 print("\nkeyboard: on\n");
408                 debug_enable = true;
409             } else {
410                 print("\nkeyboard: off\n");
411             }
412             break;
413
414         // debug mouse toggle
415         case MAGIC_KC(MAGIC_KEY_DEBUG_MOUSE):
416             debug_mouse = !debug_mouse;
417             if (debug_mouse) {
418                 print("\nmouse: on\n");
419                 debug_enable = true;
420             } else {
421                                 print("\nmouse: off\n");
422             }
423             break;
424
425                 // print version
426         case MAGIC_KC(MAGIC_KEY_VERSION):
427                 print_version();
428                     break;
429
430                 // print status
431                 case MAGIC_KC(MAGIC_KEY_STATUS):
432                         print_status();
433             break;
434
435 #ifdef NKRO_ENABLE
436
437                 // NKRO toggle
438         case MAGIC_KC(MAGIC_KEY_NKRO):
439             clear_keyboard(); // clear to prevent stuck keys
440             keymap_config.nkro = !keymap_config.nkro;
441             if (keymap_config.nkro) {
442                 print("NKRO: on\n");
443             } else {
444                 print("NKRO: off\n");
445             }
446             break;
447 #endif
448
449                 // switch layers
450
451                 case MAGIC_KC(MAGIC_KEY_LAYER0_ALT1):
452                 case MAGIC_KC(MAGIC_KEY_LAYER0_ALT2):
453             switch_default_layer(0);
454             break;
455
456 #if MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM
457
458                 case MAGIC_KC(MAGIC_KEY_LAYER0):
459             switch_default_layer(0);
460             break;
461
462                 case MAGIC_KC(MAGIC_KEY_LAYER1):
463             switch_default_layer(1);
464             break;
465
466                 case MAGIC_KC(MAGIC_KEY_LAYER2):
467             switch_default_layer(2);
468             break;
469
470                 case MAGIC_KC(MAGIC_KEY_LAYER3):
471             switch_default_layer(3);
472             break;
473
474                 case MAGIC_KC(MAGIC_KEY_LAYER4):
475             switch_default_layer(4);
476             break;
477
478                 case MAGIC_KC(MAGIC_KEY_LAYER5):
479             switch_default_layer(5);
480             break;
481
482                 case MAGIC_KC(MAGIC_KEY_LAYER6):
483             switch_default_layer(6);
484             break;
485
486                 case MAGIC_KC(MAGIC_KEY_LAYER7):
487             switch_default_layer(7);
488             break;
489
490                 case MAGIC_KC(MAGIC_KEY_LAYER8):
491             switch_default_layer(8);
492             break;
493
494                 case MAGIC_KC(MAGIC_KEY_LAYER9):
495             switch_default_layer(9);
496             break;
497 #endif
498
499
500 #if MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS
501
502         case KC_F1 ... KC_F9:
503             switch_default_layer((code - KC_F1) + 1);
504             break;
505         case KC_F10:
506             switch_default_layer(0);
507             break;
508 #endif
509
510 #if MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS
511
512         case KC_1 ... KC_9:
513             switch_default_layer((code - KC_1) + 1);
514             break;
515         case KC_0:
516             switch_default_layer(0);
517             break;
518 #endif
519
520         default:
521             print("?");
522             return false;
523     }
524     return true;
525 }
526
527
528 /***********************************************************
529  * Command console
530  ***********************************************************/
531 static void command_console_help(void)
532 {
533     print("\n\t- Console -\n"
534           "ESC/q:       quit\n"
535 #ifdef MOUSEKEY_ENABLE
536           "m:   mousekey\n"
537 #endif
538     );
539 }
540
541 static bool command_console(uint8_t code)
542 {
543     switch (code) {
544         case KC_H:
545         case KC_SLASH: /* ? */
546             command_console_help();
547             break;
548         case KC_Q:
549         case KC_ESC:
550             command_state = ONESHOT;
551             return false;
552 #ifdef MOUSEKEY_ENABLE
553         case KC_M:
554             mousekey_console_help();
555             print("M> ");
556             command_state = MOUSEKEY;
557             return true;
558 #endif
559         default:
560             print("?");
561             return false;
562     }
563     print("C> ");
564     return true;
565 }
566
567
568 #ifdef MOUSEKEY_ENABLE
569 /***********************************************************
570  * Mousekey console
571  ***********************************************************/
572 static uint8_t mousekey_param = 0;
573
574 static void mousekey_param_print(void)
575 {
576 // Print these variables if NO_PRINT or USER_PRINT are not defined.
577 #if !defined(NO_PRINT) && !defined(USER_PRINT)
578     print("\n\t- Values -\n");
579     print("1: delay(*10ms): "); pdec(mk_delay); print("\n");
580     print("2: interval(ms): "); pdec(mk_interval); print("\n");
581     print("3: max_speed: "); pdec(mk_max_speed); print("\n");
582     print("4: time_to_max: "); pdec(mk_time_to_max); print("\n");
583     print("5: wheel_max_speed: "); pdec(mk_wheel_max_speed); print("\n");
584     print("6: wheel_time_to_max: "); pdec(mk_wheel_time_to_max); print("\n");
585 #endif /* !NO_PRINT */
586
587 }
588
589 //#define PRINT_SET_VAL(v)  print(#v " = "); print_dec(v); print("\n");
590 #define PRINT_SET_VAL(v)  xprintf(#v " = %d\n", (v))
591 static void mousekey_param_inc(uint8_t param, uint8_t inc)
592 {
593     switch (param) {
594         case 1:
595             if (mk_delay + inc < UINT8_MAX)
596                 mk_delay += inc;
597             else
598                 mk_delay = UINT8_MAX;
599             PRINT_SET_VAL(mk_delay);
600             break;
601         case 2:
602             if (mk_interval + inc < UINT8_MAX)
603                 mk_interval += inc;
604             else
605                 mk_interval = UINT8_MAX;
606             PRINT_SET_VAL(mk_interval);
607             break;
608         case 3:
609             if (mk_max_speed + inc < UINT8_MAX)
610                 mk_max_speed += inc;
611             else
612                 mk_max_speed = UINT8_MAX;
613             PRINT_SET_VAL(mk_max_speed);
614             break;
615         case 4:
616             if (mk_time_to_max + inc < UINT8_MAX)
617                 mk_time_to_max += inc;
618             else
619                 mk_time_to_max = UINT8_MAX;
620             PRINT_SET_VAL(mk_time_to_max);
621             break;
622         case 5:
623             if (mk_wheel_max_speed + inc < UINT8_MAX)
624                 mk_wheel_max_speed += inc;
625             else
626                 mk_wheel_max_speed = UINT8_MAX;
627             PRINT_SET_VAL(mk_wheel_max_speed);
628             break;
629         case 6:
630             if (mk_wheel_time_to_max + inc < UINT8_MAX)
631                 mk_wheel_time_to_max += inc;
632             else
633                 mk_wheel_time_to_max = UINT8_MAX;
634             PRINT_SET_VAL(mk_wheel_time_to_max);
635             break;
636     }
637 }
638
639 static void mousekey_param_dec(uint8_t param, uint8_t dec)
640 {
641     switch (param) {
642         case 1:
643             if (mk_delay > dec)
644                 mk_delay -= dec;
645             else
646                 mk_delay = 0;
647             PRINT_SET_VAL(mk_delay);
648             break;
649         case 2:
650             if (mk_interval > dec)
651                 mk_interval -= dec;
652             else
653                 mk_interval = 0;
654             PRINT_SET_VAL(mk_interval);
655             break;
656         case 3:
657             if (mk_max_speed > dec)
658                 mk_max_speed -= dec;
659             else
660                 mk_max_speed = 0;
661             PRINT_SET_VAL(mk_max_speed);
662             break;
663         case 4:
664             if (mk_time_to_max > dec)
665                 mk_time_to_max -= dec;
666             else
667                 mk_time_to_max = 0;
668             PRINT_SET_VAL(mk_time_to_max);
669             break;
670         case 5:
671             if (mk_wheel_max_speed > dec)
672                 mk_wheel_max_speed -= dec;
673             else
674                 mk_wheel_max_speed = 0;
675             PRINT_SET_VAL(mk_wheel_max_speed);
676             break;
677         case 6:
678             if (mk_wheel_time_to_max > dec)
679                 mk_wheel_time_to_max -= dec;
680             else
681                 mk_wheel_time_to_max = 0;
682             PRINT_SET_VAL(mk_wheel_time_to_max);
683             break;
684     }
685 }
686
687 static void mousekey_console_help(void)
688 {
689     print("\n\t- Mousekey -\n"
690           "ESC/q:       quit\n"
691           "1:   delay(*10ms)\n"
692           "2:   interval(ms)\n"
693           "3:   max_speed\n"
694           "4:   time_to_max\n"
695           "5:   wheel_max_speed\n"
696           "6:   wheel_time_to_max\n"
697           "\n"
698           "p:   print values\n"
699           "d:   set defaults\n"
700           "up:  +1\n"
701           "down:        -1\n"
702           "pgup:        +10\n"
703           "pgdown:      -10\n"
704           "\n"
705           "speed = delta * max_speed * (repeat / time_to_max)\n");
706     xprintf("where delta: cursor=%d, wheel=%d\n"
707             "See http://en.wikipedia.org/wiki/Mouse_keys\n", MOUSEKEY_MOVE_DELTA,  MOUSEKEY_WHEEL_DELTA);
708 }
709
710 static bool mousekey_console(uint8_t code)
711 {
712     switch (code) {
713         case KC_H:
714         case KC_SLASH: /* ? */
715             mousekey_console_help();
716             break;
717         case KC_Q:
718         case KC_ESC:
719             if (mousekey_param) {
720                 mousekey_param = 0;
721             } else {
722                 print("C> ");
723                 command_state = CONSOLE;
724                 return false;
725             }
726             break;
727         case KC_P:
728             mousekey_param_print();
729             break;
730         case KC_1:
731         case KC_2:
732         case KC_3:
733         case KC_4:
734         case KC_5:
735         case KC_6:
736             mousekey_param = numkey2num(code);
737             break;
738         case KC_UP:
739             mousekey_param_inc(mousekey_param, 1);
740             break;
741         case KC_DOWN:
742             mousekey_param_dec(mousekey_param, 1);
743             break;
744         case KC_PGUP:
745             mousekey_param_inc(mousekey_param, 10);
746             break;
747         case KC_PGDN:
748             mousekey_param_dec(mousekey_param, 10);
749             break;
750         case KC_D:
751             mk_delay = MOUSEKEY_DELAY/10;
752             mk_interval = MOUSEKEY_INTERVAL;
753             mk_max_speed = MOUSEKEY_MAX_SPEED;
754             mk_time_to_max = MOUSEKEY_TIME_TO_MAX;
755             mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED;
756             mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX;
757             print("set default\n");
758             break;
759         default:
760             print("?");
761             return false;
762     }
763     if (mousekey_param) {
764         xprintf("M%d> ", mousekey_param);
765     } else {
766         print("M>" );
767     }
768     return true;
769 }
770 #endif
771
772
773 /***********************************************************
774  * Utilities
775  ***********************************************************/
776 uint8_t numkey2num(uint8_t code)
777 {
778     switch (code) {
779         case KC_1: return 1;
780         case KC_2: return 2;
781         case KC_3: return 3;
782         case KC_4: return 4;
783         case KC_5: return 5;
784         case KC_6: return 6;
785         case KC_7: return 7;
786         case KC_8: return 8;
787         case KC_9: return 9;
788         case KC_0: return 0;
789     }
790     return 0;
791 }
792
793 static void switch_default_layer(uint8_t layer)
794 {
795     xprintf("L%d\n", layer);
796     default_layer_set(1UL<<layer);
797     clear_keyboard();
798 }