]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/common/command.c
Merge remote-tracking branch 'upstream/master'
[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                     stop_all_notes();
361                 play_goodbye_tone();
362             #else
363                     _delay_ms(1000);
364             #endif
365             bootloader_jump(); // not return
366             break;
367
368         // debug toggle
369         case MAGIC_KC(MAGIC_KEY_DEBUG):
370             debug_enable = !debug_enable;
371             if (debug_enable) {
372                 print("\ndebug: on\n");
373                 debug_matrix   = true;
374                 debug_keyboard = true;
375                 debug_mouse    = true;
376             } else {
377                 print("\ndebug: off\n");
378                 debug_matrix   = false;
379                 debug_keyboard = false;
380                 debug_mouse    = false;
381             }
382             break;
383
384         // debug matrix toggle
385         case MAGIC_KC(MAGIC_KEY_DEBUG_MATRIX):
386             debug_matrix = !debug_matrix;
387             if (debug_matrix) {
388                 print("\nmatrix: on\n");
389                 debug_enable = true;
390             } else {
391                 print("\nmatrix: off\n");
392             }
393             break;
394
395         // debug keyboard toggle
396         case MAGIC_KC(MAGIC_KEY_DEBUG_KBD):
397             debug_keyboard = !debug_keyboard;
398             if (debug_keyboard) {
399                 print("\nkeyboard: on\n");
400                 debug_enable = true;
401             } else {
402                 print("\nkeyboard: off\n");
403             }
404             break;
405
406         // debug mouse toggle
407         case MAGIC_KC(MAGIC_KEY_DEBUG_MOUSE):
408             debug_mouse = !debug_mouse;
409             if (debug_mouse) {
410                 print("\nmouse: on\n");
411                 debug_enable = true;
412             } else {
413                                 print("\nmouse: off\n");
414             }
415             break;
416
417                 // print version
418         case MAGIC_KC(MAGIC_KEY_VERSION):
419                 print_version();
420                     break;
421
422                 // print status
423                 case MAGIC_KC(MAGIC_KEY_STATUS):
424                         print_status();
425             break;
426
427 #ifdef NKRO_ENABLE
428
429                 // NKRO toggle
430         case MAGIC_KC(MAGIC_KEY_NKRO):
431             clear_keyboard(); // clear to prevent stuck keys
432             keyboard_nkro = !keyboard_nkro;
433             if (keyboard_nkro)
434                 print("NKRO: on\n");
435             else
436                 print("NKRO: off\n");
437             break;
438 #endif
439
440                 // switch layers
441
442                 case MAGIC_KC(MAGIC_KEY_LAYER0_ALT1):
443                 case MAGIC_KC(MAGIC_KEY_LAYER0_ALT2):
444             switch_default_layer(0);
445             break;
446
447 #if MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM
448
449                 case MAGIC_KC(MAGIC_KEY_LAYER0):
450             switch_default_layer(0);
451             break;
452
453                 case MAGIC_KC(MAGIC_KEY_LAYER1):
454             switch_default_layer(1);
455             break;
456
457                 case MAGIC_KC(MAGIC_KEY_LAYER2):
458             switch_default_layer(2);
459             break;
460
461                 case MAGIC_KC(MAGIC_KEY_LAYER3):
462             switch_default_layer(3);
463             break;
464
465                 case MAGIC_KC(MAGIC_KEY_LAYER4):
466             switch_default_layer(4);
467             break;
468
469                 case MAGIC_KC(MAGIC_KEY_LAYER5):
470             switch_default_layer(5);
471             break;
472
473                 case MAGIC_KC(MAGIC_KEY_LAYER6):
474             switch_default_layer(6);
475             break;
476
477                 case MAGIC_KC(MAGIC_KEY_LAYER7):
478             switch_default_layer(7);
479             break;
480
481                 case MAGIC_KC(MAGIC_KEY_LAYER8):
482             switch_default_layer(8);
483             break;
484
485                 case MAGIC_KC(MAGIC_KEY_LAYER9):
486             switch_default_layer(9);
487             break;
488 #endif
489
490
491 #if MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS
492
493         case KC_F1 ... KC_F9:
494             switch_default_layer((code - KC_F1) + 1);
495             break;
496         case KC_F10:
497             switch_default_layer(0);
498             break;
499 #endif
500
501 #if MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS
502
503         case KC_1 ... KC_9:
504             switch_default_layer((code - KC_1) + 1);
505             break;
506         case KC_0:
507             switch_default_layer(0);
508             break;
509 #endif
510
511         default:
512             print("?");
513             return false;
514     }
515     return true;
516 }
517
518
519 /***********************************************************
520  * Command console
521  ***********************************************************/
522 static void command_console_help(void)
523 {
524     print("\n\t- Console -\n"
525           "ESC/q:       quit\n"
526 #ifdef MOUSEKEY_ENABLE
527           "m:   mousekey\n"
528 #endif
529     );
530 }
531
532 static bool command_console(uint8_t code)
533 {
534     switch (code) {
535         case KC_H:
536         case KC_SLASH: /* ? */
537             command_console_help();
538             break;
539         case KC_Q:
540         case KC_ESC:
541             command_state = ONESHOT;
542             return false;
543 #ifdef MOUSEKEY_ENABLE
544         case KC_M:
545             mousekey_console_help();
546             print("M> ");
547             command_state = MOUSEKEY;
548             return true;
549 #endif
550         default:
551             print("?");
552             return false;
553     }
554     print("C> ");
555     return true;
556 }
557
558
559 #ifdef MOUSEKEY_ENABLE
560 /***********************************************************
561  * Mousekey console
562  ***********************************************************/
563 static uint8_t mousekey_param = 0;
564
565 static void mousekey_param_print(void)
566 {
567 #ifndef NO_PRINT
568     print("\n\t- Values -\n");
569     print("1: delay(*10ms): "); pdec(mk_delay); print("\n");
570     print("2: interval(ms): "); pdec(mk_interval); print("\n");
571     print("3: max_speed: "); pdec(mk_max_speed); print("\n");
572     print("4: time_to_max: "); pdec(mk_time_to_max); print("\n");
573     print("5: wheel_max_speed: "); pdec(mk_wheel_max_speed); print("\n");
574     print("6: wheel_time_to_max: "); pdec(mk_wheel_time_to_max); print("\n");
575 #endif /* !NO_PRINT */
576
577 }
578
579 //#define PRINT_SET_VAL(v)  print(#v " = "); print_dec(v); print("\n");
580 #define PRINT_SET_VAL(v)  xprintf(#v " = %d\n", (v))
581 static void mousekey_param_inc(uint8_t param, uint8_t inc)
582 {
583     switch (param) {
584         case 1:
585             if (mk_delay + inc < UINT8_MAX)
586                 mk_delay += inc;
587             else
588                 mk_delay = UINT8_MAX;
589             PRINT_SET_VAL(mk_delay);
590             break;
591         case 2:
592             if (mk_interval + inc < UINT8_MAX)
593                 mk_interval += inc;
594             else
595                 mk_interval = UINT8_MAX;
596             PRINT_SET_VAL(mk_interval);
597             break;
598         case 3:
599             if (mk_max_speed + inc < UINT8_MAX)
600                 mk_max_speed += inc;
601             else
602                 mk_max_speed = UINT8_MAX;
603             PRINT_SET_VAL(mk_max_speed);
604             break;
605         case 4:
606             if (mk_time_to_max + inc < UINT8_MAX)
607                 mk_time_to_max += inc;
608             else
609                 mk_time_to_max = UINT8_MAX;
610             PRINT_SET_VAL(mk_time_to_max);
611             break;
612         case 5:
613             if (mk_wheel_max_speed + inc < UINT8_MAX)
614                 mk_wheel_max_speed += inc;
615             else
616                 mk_wheel_max_speed = UINT8_MAX;
617             PRINT_SET_VAL(mk_wheel_max_speed);
618             break;
619         case 6:
620             if (mk_wheel_time_to_max + inc < UINT8_MAX)
621                 mk_wheel_time_to_max += inc;
622             else
623                 mk_wheel_time_to_max = UINT8_MAX;
624             PRINT_SET_VAL(mk_wheel_time_to_max);
625             break;
626     }
627 }
628
629 static void mousekey_param_dec(uint8_t param, uint8_t dec)
630 {
631     switch (param) {
632         case 1:
633             if (mk_delay > dec)
634                 mk_delay -= dec;
635             else
636                 mk_delay = 0;
637             PRINT_SET_VAL(mk_delay);
638             break;
639         case 2:
640             if (mk_interval > dec)
641                 mk_interval -= dec;
642             else
643                 mk_interval = 0;
644             PRINT_SET_VAL(mk_interval);
645             break;
646         case 3:
647             if (mk_max_speed > dec)
648                 mk_max_speed -= dec;
649             else
650                 mk_max_speed = 0;
651             PRINT_SET_VAL(mk_max_speed);
652             break;
653         case 4:
654             if (mk_time_to_max > dec)
655                 mk_time_to_max -= dec;
656             else
657                 mk_time_to_max = 0;
658             PRINT_SET_VAL(mk_time_to_max);
659             break;
660         case 5:
661             if (mk_wheel_max_speed > dec)
662                 mk_wheel_max_speed -= dec;
663             else
664                 mk_wheel_max_speed = 0;
665             PRINT_SET_VAL(mk_wheel_max_speed);
666             break;
667         case 6:
668             if (mk_wheel_time_to_max > dec)
669                 mk_wheel_time_to_max -= dec;
670             else
671                 mk_wheel_time_to_max = 0;
672             PRINT_SET_VAL(mk_wheel_time_to_max);
673             break;
674     }
675 }
676
677 static void mousekey_console_help(void)
678 {
679     print("\n\t- Mousekey -\n"
680           "ESC/q:       quit\n"
681           "1:   delay(*10ms)\n"
682           "2:   interval(ms)\n"
683           "3:   max_speed\n"
684           "4:   time_to_max\n"
685           "5:   wheel_max_speed\n"
686           "6:   wheel_time_to_max\n"
687           "\n"
688           "p:   print values\n"
689           "d:   set defaults\n"
690           "up:  +1\n"
691           "down:        -1\n"
692           "pgup:        +10\n"
693           "pgdown:      -10\n"
694           "\n"
695           "speed = delta * max_speed * (repeat / time_to_max)\n");
696     xprintf("where delta: cursor=%d, wheel=%d\n"
697             "See http://en.wikipedia.org/wiki/Mouse_keys\n", MOUSEKEY_MOVE_DELTA,  MOUSEKEY_WHEEL_DELTA);
698 }
699
700 static bool mousekey_console(uint8_t code)
701 {
702     switch (code) {
703         case KC_H:
704         case KC_SLASH: /* ? */
705             mousekey_console_help();
706             break;
707         case KC_Q:
708         case KC_ESC:
709             if (mousekey_param) {
710                 mousekey_param = 0;
711             } else {
712                 print("C> ");
713                 command_state = CONSOLE;
714                 return false;
715             }
716             break;
717         case KC_P:
718             mousekey_param_print();
719             break;
720         case KC_1:
721         case KC_2:
722         case KC_3:
723         case KC_4:
724         case KC_5:
725         case KC_6:
726             mousekey_param = numkey2num(code);
727             break;
728         case KC_UP:
729             mousekey_param_inc(mousekey_param, 1);
730             break;
731         case KC_DOWN:
732             mousekey_param_dec(mousekey_param, 1);
733             break;
734         case KC_PGUP:
735             mousekey_param_inc(mousekey_param, 10);
736             break;
737         case KC_PGDN:
738             mousekey_param_dec(mousekey_param, 10);
739             break;
740         case KC_D:
741             mk_delay = MOUSEKEY_DELAY/10;
742             mk_interval = MOUSEKEY_INTERVAL;
743             mk_max_speed = MOUSEKEY_MAX_SPEED;
744             mk_time_to_max = MOUSEKEY_TIME_TO_MAX;
745             mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED;
746             mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX;
747             print("set default\n");
748             break;
749         default:
750             print("?");
751             return false;
752     }
753     if (mousekey_param)
754         xprintf("M%d> ", mousekey_param);
755     else
756         print("M>" );
757     return true;
758 }
759 #endif
760
761
762 /***********************************************************
763  * Utilities
764  ***********************************************************/
765 static uint8_t numkey2num(uint8_t code)
766 {
767     switch (code) {
768         case KC_1: return 1;
769         case KC_2: return 2;
770         case KC_3: return 3;
771         case KC_4: return 4;
772         case KC_5: return 5;
773         case KC_6: return 6;
774         case KC_7: return 7;
775         case KC_8: return 8;
776         case KC_9: return 9;
777         case KC_0: return 0;
778     }
779     return 0;
780 }
781
782 static void switch_default_layer(uint8_t layer)
783 {
784     xprintf("L%d\n", layer);
785     default_layer_set(1UL<<layer);
786     clear_keyboard();
787 }