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