]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/common/command.c
f79d5a257b9cfdf9294cc61ed72828085d0dd2ab
[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     // these aren't set on the V-USB protocol, so we just ignore them for now
240     print_val_hex8(keyboard_protocol);
241     print_val_hex8(keyboard_idle);
242 #endif
243 #ifdef NKRO_ENABLE
244     print_val_hex8(keymap_config.nkro);
245 #endif
246     print_val_hex32(timer_read32());
247
248 #ifdef PROTOCOL_PJRC
249     print_val_hex8(UDCON);
250     print_val_hex8(UDIEN);
251     print_val_hex8(UDINT);
252     print_val_hex8(usb_keyboard_leds);
253     print_val_hex8(usb_keyboard_idle_count);
254 #endif
255
256 #ifdef PROTOCOL_PJRC
257 #   if USB_COUNT_SOF
258     print_val_hex8(usbSofCount);
259 #   endif
260 #endif
261         return;
262 }
263
264 #ifdef BOOTMAGIC_ENABLE
265 static void print_eeconfig(void)
266 {
267
268 // Print these variables if NO_PRINT or USER_PRINT are not defined.
269 #if !defined(NO_PRINT) && !defined(USER_PRINT)
270
271     print("default_layer: "); print_dec(eeconfig_read_default_layer()); print("\n");
272
273     debug_config_t dc;
274     dc.raw = eeconfig_read_debug();
275     print("debug_config.raw: "); print_hex8(dc.raw); print("\n");
276     print(".enable: "); print_dec(dc.enable); print("\n");
277     print(".matrix: "); print_dec(dc.matrix); print("\n");
278     print(".keyboard: "); print_dec(dc.keyboard); print("\n");
279     print(".mouse: "); print_dec(dc.mouse); print("\n");
280
281     keymap_config_t kc;
282     kc.raw = eeconfig_read_keymap();
283     print("keymap_config.raw: "); print_hex8(kc.raw); print("\n");
284     print(".swap_control_capslock: "); print_dec(kc.swap_control_capslock); print("\n");
285     print(".capslock_to_control: "); print_dec(kc.capslock_to_control); print("\n");
286     print(".swap_lalt_lgui: "); print_dec(kc.swap_lalt_lgui); print("\n");
287     print(".swap_ralt_rgui: "); print_dec(kc.swap_ralt_rgui); print("\n");
288     print(".no_gui: "); print_dec(kc.no_gui); print("\n");
289     print(".swap_grave_esc: "); print_dec(kc.swap_grave_esc); print("\n");
290     print(".swap_backslash_backspace: "); print_dec(kc.swap_backslash_backspace); print("\n");
291     print(".nkro: "); print_dec(kc.nkro); print("\n");
292
293 #ifdef BACKLIGHT_ENABLE
294     backlight_config_t bc;
295     bc.raw = eeconfig_read_backlight();
296     print("backlight_config.raw: "); print_hex8(bc.raw); print("\n");
297     print(".enable: "); print_dec(bc.enable); print("\n");
298     print(".level: "); print_dec(bc.level); print("\n");
299 #endif /* BACKLIGHT_ENABLE */
300
301 #endif /* !NO_PRINT */
302
303 }
304 #endif /* BOOTMAGIC_ENABLE */
305
306 static bool command_common(uint8_t code)
307 {
308
309 #ifdef KEYBOARD_LOCK_ENABLE
310     static host_driver_t *host_driver = 0;
311 #endif
312
313     switch (code) {
314
315 #ifdef SLEEP_LED_ENABLE
316
317                 // test breathing sleep LED
318         case MAGIC_KC(MAGIC_KEY_SLEEP_LED):
319             print("Sleep LED Test\n");
320             sleep_led_toggle();
321             led_set(host_keyboard_leds());
322             break;
323 #endif
324
325 #ifdef BOOTMAGIC_ENABLE
326
327                 // print stored eeprom config
328         case MAGIC_KC(MAGIC_KEY_EEPROM):
329             print("eeconfig:\n");
330             print_eeconfig();
331             break;
332 #endif
333
334 #ifdef KEYBOARD_LOCK_ENABLE
335
336                 // lock/unlock keyboard
337         case MAGIC_KC(MAGIC_KEY_LOCK):
338             if (host_get_driver()) {
339                 host_driver = host_get_driver();
340                 clear_keyboard();
341                 host_set_driver(0);
342                 print("Locked.\n");
343             } else {
344                 host_set_driver(host_driver);
345                 print("Unlocked.\n");
346             }
347             break;
348 #endif
349
350                 // print help
351         case MAGIC_KC(MAGIC_KEY_HELP1):
352         case MAGIC_KC(MAGIC_KEY_HELP2):
353             command_common_help();
354             break;
355
356                 // activate console
357         case MAGIC_KC(MAGIC_KEY_CONSOLE):
358             debug_matrix   = false;
359             debug_keyboard = false;
360             debug_mouse    = false;
361             debug_enable   = false;
362             command_console_help();
363             print("C> ");
364             command_state = CONSOLE;
365             break;
366
367         // jump to bootloader
368         case MAGIC_KC(MAGIC_KEY_BOOTLOADER):
369             clear_keyboard(); // clear to prevent stuck keys
370             print("\n\nJumping to bootloader... ");
371             #ifdef AUDIO_ENABLE
372                     stop_all_notes();
373                 shutdown_user();
374             #else
375                     wait_ms(1000);
376             #endif
377             bootloader_jump(); // not return
378             break;
379
380         // debug toggle
381         case MAGIC_KC(MAGIC_KEY_DEBUG):
382             debug_enable = !debug_enable;
383             if (debug_enable) {
384                 print("\ndebug: on\n");
385             } else {
386                 print("\ndebug: off\n");
387                 debug_matrix   = false;
388                 debug_keyboard = false;
389                 debug_mouse    = false;
390             }
391             break;
392
393         // debug matrix toggle
394         case MAGIC_KC(MAGIC_KEY_DEBUG_MATRIX):
395             debug_matrix = !debug_matrix;
396             if (debug_matrix) {
397                 print("\nmatrix: on\n");
398                 debug_enable = true;
399             } else {
400                 print("\nmatrix: off\n");
401             }
402             break;
403
404         // debug keyboard toggle
405         case MAGIC_KC(MAGIC_KEY_DEBUG_KBD):
406             debug_keyboard = !debug_keyboard;
407             if (debug_keyboard) {
408                 print("\nkeyboard: on\n");
409                 debug_enable = true;
410             } else {
411                 print("\nkeyboard: off\n");
412             }
413             break;
414
415         // debug mouse toggle
416         case MAGIC_KC(MAGIC_KEY_DEBUG_MOUSE):
417             debug_mouse = !debug_mouse;
418             if (debug_mouse) {
419                 print("\nmouse: on\n");
420                 debug_enable = true;
421             } else {
422                                 print("\nmouse: off\n");
423             }
424             break;
425
426                 // print version
427         case MAGIC_KC(MAGIC_KEY_VERSION):
428                 print_version();
429                     break;
430
431                 // print status
432                 case MAGIC_KC(MAGIC_KEY_STATUS):
433                         print_status();
434             break;
435
436 #ifdef NKRO_ENABLE
437
438                 // NKRO toggle
439         case MAGIC_KC(MAGIC_KEY_NKRO):
440             clear_keyboard(); // clear to prevent stuck keys
441             keymap_config.nkro = !keymap_config.nkro;
442             if (keymap_config.nkro) {
443                 print("NKRO: on\n");
444             } else {
445                 print("NKRO: off\n");
446             }
447             break;
448 #endif
449
450                 // switch layers
451
452                 case MAGIC_KC(MAGIC_KEY_LAYER0_ALT1):
453                 case MAGIC_KC(MAGIC_KEY_LAYER0_ALT2):
454             switch_default_layer(0);
455             break;
456
457 #if MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM
458
459                 case MAGIC_KC(MAGIC_KEY_LAYER0):
460             switch_default_layer(0);
461             break;
462
463                 case MAGIC_KC(MAGIC_KEY_LAYER1):
464             switch_default_layer(1);
465             break;
466
467                 case MAGIC_KC(MAGIC_KEY_LAYER2):
468             switch_default_layer(2);
469             break;
470
471                 case MAGIC_KC(MAGIC_KEY_LAYER3):
472             switch_default_layer(3);
473             break;
474
475                 case MAGIC_KC(MAGIC_KEY_LAYER4):
476             switch_default_layer(4);
477             break;
478
479                 case MAGIC_KC(MAGIC_KEY_LAYER5):
480             switch_default_layer(5);
481             break;
482
483                 case MAGIC_KC(MAGIC_KEY_LAYER6):
484             switch_default_layer(6);
485             break;
486
487                 case MAGIC_KC(MAGIC_KEY_LAYER7):
488             switch_default_layer(7);
489             break;
490
491                 case MAGIC_KC(MAGIC_KEY_LAYER8):
492             switch_default_layer(8);
493             break;
494
495                 case MAGIC_KC(MAGIC_KEY_LAYER9):
496             switch_default_layer(9);
497             break;
498 #endif
499
500
501 #if MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS
502
503         case KC_F1 ... KC_F9:
504             switch_default_layer((code - KC_F1) + 1);
505             break;
506         case KC_F10:
507             switch_default_layer(0);
508             break;
509 #endif
510
511 #if MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS
512
513         case KC_1 ... KC_9:
514             switch_default_layer((code - KC_1) + 1);
515             break;
516         case KC_0:
517             switch_default_layer(0);
518             break;
519 #endif
520
521         default:
522             print("?");
523             return false;
524     }
525     return true;
526 }
527
528
529 /***********************************************************
530  * Command console
531  ***********************************************************/
532 static void command_console_help(void)
533 {
534     print("\n\t- Console -\n"
535           "ESC/q:       quit\n"
536 #ifdef MOUSEKEY_ENABLE
537           "m:   mousekey\n"
538 #endif
539     );
540 }
541
542 static bool command_console(uint8_t code)
543 {
544     switch (code) {
545         case KC_H:
546         case KC_SLASH: /* ? */
547             command_console_help();
548             break;
549         case KC_Q:
550         case KC_ESC:
551             command_state = ONESHOT;
552             return false;
553 #ifdef MOUSEKEY_ENABLE
554         case KC_M:
555             mousekey_console_help();
556             print("M> ");
557             command_state = MOUSEKEY;
558             return true;
559 #endif
560         default:
561             print("?");
562             return false;
563     }
564     print("C> ");
565     return true;
566 }
567
568
569 #ifdef MOUSEKEY_ENABLE
570 /***********************************************************
571  * Mousekey console
572  ***********************************************************/
573 static uint8_t mousekey_param = 0;
574
575 static void mousekey_param_print(void)
576 {
577 // Print these variables if NO_PRINT or USER_PRINT are not defined.
578 #if !defined(NO_PRINT) && !defined(USER_PRINT)
579     print("\n\t- Values -\n");
580     print("1: delay(*10ms): "); pdec(mk_delay); print("\n");
581     print("2: interval(ms): "); pdec(mk_interval); print("\n");
582     print("3: max_speed: "); pdec(mk_max_speed); print("\n");
583     print("4: time_to_max: "); pdec(mk_time_to_max); print("\n");
584     print("5: wheel_max_speed: "); pdec(mk_wheel_max_speed); print("\n");
585     print("6: wheel_time_to_max: "); pdec(mk_wheel_time_to_max); print("\n");
586 #endif /* !NO_PRINT */
587
588 }
589
590 //#define PRINT_SET_VAL(v)  print(#v " = "); print_dec(v); print("\n");
591 #define PRINT_SET_VAL(v)  xprintf(#v " = %d\n", (v))
592 static void mousekey_param_inc(uint8_t param, uint8_t inc)
593 {
594     switch (param) {
595         case 1:
596             if (mk_delay + inc < UINT8_MAX)
597                 mk_delay += inc;
598             else
599                 mk_delay = UINT8_MAX;
600             PRINT_SET_VAL(mk_delay);
601             break;
602         case 2:
603             if (mk_interval + inc < UINT8_MAX)
604                 mk_interval += inc;
605             else
606                 mk_interval = UINT8_MAX;
607             PRINT_SET_VAL(mk_interval);
608             break;
609         case 3:
610             if (mk_max_speed + inc < UINT8_MAX)
611                 mk_max_speed += inc;
612             else
613                 mk_max_speed = UINT8_MAX;
614             PRINT_SET_VAL(mk_max_speed);
615             break;
616         case 4:
617             if (mk_time_to_max + inc < UINT8_MAX)
618                 mk_time_to_max += inc;
619             else
620                 mk_time_to_max = UINT8_MAX;
621             PRINT_SET_VAL(mk_time_to_max);
622             break;
623         case 5:
624             if (mk_wheel_max_speed + inc < UINT8_MAX)
625                 mk_wheel_max_speed += inc;
626             else
627                 mk_wheel_max_speed = UINT8_MAX;
628             PRINT_SET_VAL(mk_wheel_max_speed);
629             break;
630         case 6:
631             if (mk_wheel_time_to_max + inc < UINT8_MAX)
632                 mk_wheel_time_to_max += inc;
633             else
634                 mk_wheel_time_to_max = UINT8_MAX;
635             PRINT_SET_VAL(mk_wheel_time_to_max);
636             break;
637     }
638 }
639
640 static void mousekey_param_dec(uint8_t param, uint8_t dec)
641 {
642     switch (param) {
643         case 1:
644             if (mk_delay > dec)
645                 mk_delay -= dec;
646             else
647                 mk_delay = 0;
648             PRINT_SET_VAL(mk_delay);
649             break;
650         case 2:
651             if (mk_interval > dec)
652                 mk_interval -= dec;
653             else
654                 mk_interval = 0;
655             PRINT_SET_VAL(mk_interval);
656             break;
657         case 3:
658             if (mk_max_speed > dec)
659                 mk_max_speed -= dec;
660             else
661                 mk_max_speed = 0;
662             PRINT_SET_VAL(mk_max_speed);
663             break;
664         case 4:
665             if (mk_time_to_max > dec)
666                 mk_time_to_max -= dec;
667             else
668                 mk_time_to_max = 0;
669             PRINT_SET_VAL(mk_time_to_max);
670             break;
671         case 5:
672             if (mk_wheel_max_speed > dec)
673                 mk_wheel_max_speed -= dec;
674             else
675                 mk_wheel_max_speed = 0;
676             PRINT_SET_VAL(mk_wheel_max_speed);
677             break;
678         case 6:
679             if (mk_wheel_time_to_max > dec)
680                 mk_wheel_time_to_max -= dec;
681             else
682                 mk_wheel_time_to_max = 0;
683             PRINT_SET_VAL(mk_wheel_time_to_max);
684             break;
685     }
686 }
687
688 static void mousekey_console_help(void)
689 {
690     print("\n\t- Mousekey -\n"
691           "ESC/q:       quit\n"
692           "1:   delay(*10ms)\n"
693           "2:   interval(ms)\n"
694           "3:   max_speed\n"
695           "4:   time_to_max\n"
696           "5:   wheel_max_speed\n"
697           "6:   wheel_time_to_max\n"
698           "\n"
699           "p:   print values\n"
700           "d:   set defaults\n"
701           "up:  +1\n"
702           "down:        -1\n"
703           "pgup:        +10\n"
704           "pgdown:      -10\n"
705           "\n"
706           "speed = delta * max_speed * (repeat / time_to_max)\n");
707     xprintf("where delta: cursor=%d, wheel=%d\n"
708             "See http://en.wikipedia.org/wiki/Mouse_keys\n", MOUSEKEY_MOVE_DELTA,  MOUSEKEY_WHEEL_DELTA);
709 }
710
711 static bool mousekey_console(uint8_t code)
712 {
713     switch (code) {
714         case KC_H:
715         case KC_SLASH: /* ? */
716             mousekey_console_help();
717             break;
718         case KC_Q:
719         case KC_ESC:
720             if (mousekey_param) {
721                 mousekey_param = 0;
722             } else {
723                 print("C> ");
724                 command_state = CONSOLE;
725                 return false;
726             }
727             break;
728         case KC_P:
729             mousekey_param_print();
730             break;
731         case KC_1:
732         case KC_2:
733         case KC_3:
734         case KC_4:
735         case KC_5:
736         case KC_6:
737             mousekey_param = numkey2num(code);
738             break;
739         case KC_UP:
740             mousekey_param_inc(mousekey_param, 1);
741             break;
742         case KC_DOWN:
743             mousekey_param_dec(mousekey_param, 1);
744             break;
745         case KC_PGUP:
746             mousekey_param_inc(mousekey_param, 10);
747             break;
748         case KC_PGDN:
749             mousekey_param_dec(mousekey_param, 10);
750             break;
751         case KC_D:
752             mk_delay = MOUSEKEY_DELAY/10;
753             mk_interval = MOUSEKEY_INTERVAL;
754             mk_max_speed = MOUSEKEY_MAX_SPEED;
755             mk_time_to_max = MOUSEKEY_TIME_TO_MAX;
756             mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED;
757             mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX;
758             print("set default\n");
759             break;
760         default:
761             print("?");
762             return false;
763     }
764     if (mousekey_param) {
765         xprintf("M%d> ", mousekey_param);
766     } else {
767         print("M>" );
768     }
769     return true;
770 }
771 #endif
772
773
774 /***********************************************************
775  * Utilities
776  ***********************************************************/
777 uint8_t numkey2num(uint8_t code)
778 {
779     switch (code) {
780         case KC_1: return 1;
781         case KC_2: return 2;
782         case KC_3: return 3;
783         case KC_4: return 4;
784         case KC_5: return 5;
785         case KC_6: return 6;
786         case KC_7: return 7;
787         case KC_8: return 8;
788         case KC_9: return 9;
789         case KC_0: return 0;
790     }
791     return 0;
792 }
793
794 static void switch_default_layer(uint8_t layer)
795 {
796     xprintf("L%d\n", layer);
797     default_layer_set(1UL<<layer);
798     clear_keyboard();
799 }