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