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