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