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