]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/common/command.c
[Keyboard] fixed pins for numpad_5x4 layout (#6311)
[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_ALT  ) ":  Switch to Layer 0 (alternate)\n"
155
156                 STR(MAGIC_KEY_BOOTLOADER    ) ":        Jump to Bootloader\n"
157                 STR(MAGIC_KEY_BOOTLOADER_ALT) ":        Jump to Bootloader (alternate)\n"
158
159 #ifdef KEYBOARD_LOCK_ENABLE
160                 STR(MAGIC_KEY_LOCK        ) ":  Lock Keyboard\n"
161 #endif
162
163                 STR(MAGIC_KEY_EEPROM      ) ":  Print EEPROM Settings\n"
164                 STR(MAGIC_KEY_EEPROM_CLEAR) ":  Clear EEPROM\n"
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 static void print_eeconfig(void)
269 {
270
271 // Print these variables if NO_PRINT or USER_PRINT are not defined.
272 #if !defined(NO_PRINT) && !defined(USER_PRINT)
273
274     print("default_layer: "); print_dec(eeconfig_read_default_layer()); print("\n");
275
276     debug_config_t dc;
277     dc.raw = eeconfig_read_debug();
278     print("debug_config.raw: "); print_hex8(dc.raw); print("\n");
279     print(".enable: "); print_dec(dc.enable); print("\n");
280     print(".matrix: "); print_dec(dc.matrix); print("\n");
281     print(".keyboard: "); print_dec(dc.keyboard); print("\n");
282     print(".mouse: "); print_dec(dc.mouse); print("\n");
283
284     keymap_config_t kc;
285     kc.raw = eeconfig_read_keymap();
286     print("keymap_config.raw: "); print_hex8(kc.raw); print("\n");
287     print(".swap_control_capslock: "); print_dec(kc.swap_control_capslock); print("\n");
288     print(".capslock_to_control: "); print_dec(kc.capslock_to_control); print("\n");
289     print(".swap_lalt_lgui: "); print_dec(kc.swap_lalt_lgui); print("\n");
290     print(".swap_ralt_rgui: "); print_dec(kc.swap_ralt_rgui); print("\n");
291     print(".no_gui: "); print_dec(kc.no_gui); print("\n");
292     print(".swap_grave_esc: "); print_dec(kc.swap_grave_esc); print("\n");
293     print(".swap_backslash_backspace: "); print_dec(kc.swap_backslash_backspace); print("\n");
294     print(".nkro: "); print_dec(kc.nkro); print("\n");
295
296 #ifdef BACKLIGHT_ENABLE
297     backlight_config_t bc;
298     bc.raw = eeconfig_read_backlight();
299     print("backlight_config.raw: "); print_hex8(bc.raw); print("\n");
300     print(".enable: "); print_dec(bc.enable); print("\n");
301     print(".level: "); print_dec(bc.level); print("\n");
302 #endif /* BACKLIGHT_ENABLE */
303
304 #endif /* !NO_PRINT */
305
306 }
307
308 static bool command_common(uint8_t code)
309 {
310
311 #ifdef KEYBOARD_LOCK_ENABLE
312     static host_driver_t *host_driver = 0;
313 #endif
314
315     switch (code) {
316
317 #ifdef SLEEP_LED_ENABLE
318
319                 // test breathing sleep LED
320         case MAGIC_KC(MAGIC_KEY_SLEEP_LED):
321             print("Sleep LED Test\n");
322             sleep_led_toggle();
323             led_set(host_keyboard_leds());
324             break;
325 #endif
326
327                 // print stored eeprom config
328         case MAGIC_KC(MAGIC_KEY_EEPROM):
329             print("eeconfig:\n");
330             print_eeconfig();
331             break;
332
333                 // clear eeprom
334         case MAGIC_KC(MAGIC_KEY_EEPROM_CLEAR):
335             print("Clearing EEPROM\n");
336             eeconfig_init();
337             break;
338
339 #ifdef KEYBOARD_LOCK_ENABLE
340
341                 // lock/unlock keyboard
342         case MAGIC_KC(MAGIC_KEY_LOCK):
343             if (host_get_driver()) {
344                 host_driver = host_get_driver();
345                 clear_keyboard();
346                 host_set_driver(0);
347                 print("Locked.\n");
348             } else {
349                 host_set_driver(host_driver);
350                 print("Unlocked.\n");
351             }
352             break;
353 #endif
354
355                 // print help
356         case MAGIC_KC(MAGIC_KEY_HELP):
357         case MAGIC_KC(MAGIC_KEY_HELP_ALT):
358             command_common_help();
359             break;
360
361                 // activate console
362         case MAGIC_KC(MAGIC_KEY_CONSOLE):
363             debug_matrix   = false;
364             debug_keyboard = false;
365             debug_mouse    = false;
366             debug_enable   = false;
367             command_console_help();
368             print("C> ");
369             command_state = CONSOLE;
370             break;
371
372         // jump to bootloader
373         case MAGIC_KC(MAGIC_KEY_BOOTLOADER):
374         case MAGIC_KC(MAGIC_KEY_BOOTLOADER_ALT):
375             clear_keyboard(); // clear to prevent stuck keys
376             print("\n\nJumping to bootloader... ");
377             #ifdef AUDIO_ENABLE
378                     stop_all_notes();
379                 shutdown_user();
380             #else
381                     wait_ms(1000);
382             #endif
383             bootloader_jump(); // not return
384             break;
385
386         // debug toggle
387         case MAGIC_KC(MAGIC_KEY_DEBUG):
388             debug_enable = !debug_enable;
389             if (debug_enable) {
390                 print("\ndebug: on\n");
391             } else {
392                 print("\ndebug: off\n");
393                 debug_matrix   = false;
394                 debug_keyboard = false;
395                 debug_mouse    = false;
396             }
397             break;
398
399         // debug matrix toggle
400         case MAGIC_KC(MAGIC_KEY_DEBUG_MATRIX):
401             debug_matrix = !debug_matrix;
402             if (debug_matrix) {
403                 print("\nmatrix: on\n");
404                 debug_enable = true;
405             } else {
406                 print("\nmatrix: off\n");
407             }
408             break;
409
410         // debug keyboard toggle
411         case MAGIC_KC(MAGIC_KEY_DEBUG_KBD):
412             debug_keyboard = !debug_keyboard;
413             if (debug_keyboard) {
414                 print("\nkeyboard: on\n");
415                 debug_enable = true;
416             } else {
417                 print("\nkeyboard: off\n");
418             }
419             break;
420
421         // debug mouse toggle
422         case MAGIC_KC(MAGIC_KEY_DEBUG_MOUSE):
423             debug_mouse = !debug_mouse;
424             if (debug_mouse) {
425                 print("\nmouse: on\n");
426                 debug_enable = true;
427             } else {
428                                 print("\nmouse: off\n");
429             }
430             break;
431
432                 // print version
433         case MAGIC_KC(MAGIC_KEY_VERSION):
434                 print_version();
435                     break;
436
437                 // print status
438                 case MAGIC_KC(MAGIC_KEY_STATUS):
439                         print_status();
440             break;
441
442 #ifdef NKRO_ENABLE
443
444                 // NKRO toggle
445         case MAGIC_KC(MAGIC_KEY_NKRO):
446             clear_keyboard(); // clear to prevent stuck keys
447             keymap_config.nkro = !keymap_config.nkro;
448             if (keymap_config.nkro) {
449                 print("NKRO: on\n");
450             } else {
451                 print("NKRO: off\n");
452             }
453             break;
454 #endif
455
456                 // switch layers
457
458                 case MAGIC_KC(MAGIC_KEY_LAYER0_ALT):
459             switch_default_layer(0);
460             break;
461
462 #if MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM
463
464                 case MAGIC_KC(MAGIC_KEY_LAYER0):
465             switch_default_layer(0);
466             break;
467
468                 case MAGIC_KC(MAGIC_KEY_LAYER1):
469             switch_default_layer(1);
470             break;
471
472                 case MAGIC_KC(MAGIC_KEY_LAYER2):
473             switch_default_layer(2);
474             break;
475
476                 case MAGIC_KC(MAGIC_KEY_LAYER3):
477             switch_default_layer(3);
478             break;
479
480                 case MAGIC_KC(MAGIC_KEY_LAYER4):
481             switch_default_layer(4);
482             break;
483
484                 case MAGIC_KC(MAGIC_KEY_LAYER5):
485             switch_default_layer(5);
486             break;
487
488                 case MAGIC_KC(MAGIC_KEY_LAYER6):
489             switch_default_layer(6);
490             break;
491
492                 case MAGIC_KC(MAGIC_KEY_LAYER7):
493             switch_default_layer(7);
494             break;
495
496                 case MAGIC_KC(MAGIC_KEY_LAYER8):
497             switch_default_layer(8);
498             break;
499
500                 case MAGIC_KC(MAGIC_KEY_LAYER9):
501             switch_default_layer(9);
502             break;
503 #endif
504
505
506 #if MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS
507
508         case KC_F1 ... KC_F9:
509             switch_default_layer((code - KC_F1) + 1);
510             break;
511         case KC_F10:
512             switch_default_layer(0);
513             break;
514 #endif
515
516 #if MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS
517
518         case KC_1 ... KC_9:
519             switch_default_layer((code - KC_1) + 1);
520             break;
521         case KC_0:
522             switch_default_layer(0);
523             break;
524 #endif
525
526         default:
527             print("?");
528             return false;
529     }
530     return true;
531 }
532
533
534 /***********************************************************
535  * Command console
536  ***********************************************************/
537 static void command_console_help(void)
538 {
539     print("\n\t- Console -\n"
540           "ESC/q:       quit\n"
541 #ifdef MOUSEKEY_ENABLE
542           "m:   mousekey\n"
543 #endif
544     );
545 }
546
547 static bool command_console(uint8_t code)
548 {
549     switch (code) {
550         case KC_H:
551         case KC_SLASH: /* ? */
552             command_console_help();
553             break;
554         case KC_Q:
555         case KC_ESC:
556             command_state = ONESHOT;
557             return false;
558 #ifdef MOUSEKEY_ENABLE
559         case KC_M:
560             mousekey_console_help();
561             print("M> ");
562             command_state = MOUSEKEY;
563             return true;
564 #endif
565         default:
566             print("?");
567             return false;
568     }
569     print("C> ");
570     return true;
571 }
572
573
574 #ifdef MOUSEKEY_ENABLE
575 /***********************************************************
576  * Mousekey console
577  ***********************************************************/
578 static uint8_t mousekey_param = 0;
579
580 static void mousekey_param_print(void)
581 {
582 // Print these variables if NO_PRINT or USER_PRINT are not defined.
583 #if !defined(NO_PRINT) && !defined(USER_PRINT)
584     print("\n\t- Values -\n");
585     print("1: delay(*10ms): "); pdec(mk_delay); print("\n");
586     print("2: interval(ms): "); pdec(mk_interval); print("\n");
587     print("3: max_speed: "); pdec(mk_max_speed); print("\n");
588     print("4: time_to_max: "); pdec(mk_time_to_max); print("\n");
589     print("5: wheel_max_speed: "); pdec(mk_wheel_max_speed); print("\n");
590     print("6: wheel_time_to_max: "); pdec(mk_wheel_time_to_max); print("\n");
591 #endif /* !NO_PRINT */
592
593 }
594
595 //#define PRINT_SET_VAL(v)  print(#v " = "); print_dec(v); print("\n");
596 #define PRINT_SET_VAL(v)  xprintf(#v " = %d\n", (v))
597 static void mousekey_param_inc(uint8_t param, uint8_t inc)
598 {
599     switch (param) {
600         case 1:
601             if (mk_delay + inc < UINT8_MAX)
602                 mk_delay += inc;
603             else
604                 mk_delay = UINT8_MAX;
605             PRINT_SET_VAL(mk_delay);
606             break;
607         case 2:
608             if (mk_interval + inc < UINT8_MAX)
609                 mk_interval += inc;
610             else
611                 mk_interval = UINT8_MAX;
612             PRINT_SET_VAL(mk_interval);
613             break;
614         case 3:
615             if (mk_max_speed + inc < UINT8_MAX)
616                 mk_max_speed += inc;
617             else
618                 mk_max_speed = UINT8_MAX;
619             PRINT_SET_VAL(mk_max_speed);
620             break;
621         case 4:
622             if (mk_time_to_max + inc < UINT8_MAX)
623                 mk_time_to_max += inc;
624             else
625                 mk_time_to_max = UINT8_MAX;
626             PRINT_SET_VAL(mk_time_to_max);
627             break;
628         case 5:
629             if (mk_wheel_max_speed + inc < UINT8_MAX)
630                 mk_wheel_max_speed += inc;
631             else
632                 mk_wheel_max_speed = UINT8_MAX;
633             PRINT_SET_VAL(mk_wheel_max_speed);
634             break;
635         case 6:
636             if (mk_wheel_time_to_max + inc < UINT8_MAX)
637                 mk_wheel_time_to_max += inc;
638             else
639                 mk_wheel_time_to_max = UINT8_MAX;
640             PRINT_SET_VAL(mk_wheel_time_to_max);
641             break;
642     }
643 }
644
645 static void mousekey_param_dec(uint8_t param, uint8_t dec)
646 {
647     switch (param) {
648         case 1:
649             if (mk_delay > dec)
650                 mk_delay -= dec;
651             else
652                 mk_delay = 0;
653             PRINT_SET_VAL(mk_delay);
654             break;
655         case 2:
656             if (mk_interval > dec)
657                 mk_interval -= dec;
658             else
659                 mk_interval = 0;
660             PRINT_SET_VAL(mk_interval);
661             break;
662         case 3:
663             if (mk_max_speed > dec)
664                 mk_max_speed -= dec;
665             else
666                 mk_max_speed = 0;
667             PRINT_SET_VAL(mk_max_speed);
668             break;
669         case 4:
670             if (mk_time_to_max > dec)
671                 mk_time_to_max -= dec;
672             else
673                 mk_time_to_max = 0;
674             PRINT_SET_VAL(mk_time_to_max);
675             break;
676         case 5:
677             if (mk_wheel_max_speed > dec)
678                 mk_wheel_max_speed -= dec;
679             else
680                 mk_wheel_max_speed = 0;
681             PRINT_SET_VAL(mk_wheel_max_speed);
682             break;
683         case 6:
684             if (mk_wheel_time_to_max > dec)
685                 mk_wheel_time_to_max -= dec;
686             else
687                 mk_wheel_time_to_max = 0;
688             PRINT_SET_VAL(mk_wheel_time_to_max);
689             break;
690     }
691 }
692
693 static void mousekey_console_help(void)
694 {
695     print("\n\t- Mousekey -\n"
696           "ESC/q:       quit\n"
697           "1:   delay(*10ms)\n"
698           "2:   interval(ms)\n"
699           "3:   max_speed\n"
700           "4:   time_to_max\n"
701           "5:   wheel_max_speed\n"
702           "6:   wheel_time_to_max\n"
703           "\n"
704           "p:   print values\n"
705           "d:   set defaults\n"
706           "up:  +1\n"
707           "down:        -1\n"
708           "pgup:        +10\n"
709           "pgdown:      -10\n"
710           "\n"
711           "speed = delta * max_speed * (repeat / time_to_max)\n");
712     xprintf("where delta: cursor=%d, wheel=%d\n"
713             "See http://en.wikipedia.org/wiki/Mouse_keys\n", MOUSEKEY_MOVE_DELTA,  MOUSEKEY_WHEEL_DELTA);
714 }
715
716 static bool mousekey_console(uint8_t code)
717 {
718     switch (code) {
719         case KC_H:
720         case KC_SLASH: /* ? */
721             mousekey_console_help();
722             break;
723         case KC_Q:
724         case KC_ESC:
725             if (mousekey_param) {
726                 mousekey_param = 0;
727             } else {
728                 print("C> ");
729                 command_state = CONSOLE;
730                 return false;
731             }
732             break;
733         case KC_P:
734             mousekey_param_print();
735             break;
736         case KC_1:
737         case KC_2:
738         case KC_3:
739         case KC_4:
740         case KC_5:
741         case KC_6:
742             mousekey_param = numkey2num(code);
743             break;
744         case KC_UP:
745             mousekey_param_inc(mousekey_param, 1);
746             break;
747         case KC_DOWN:
748             mousekey_param_dec(mousekey_param, 1);
749             break;
750         case KC_PGUP:
751             mousekey_param_inc(mousekey_param, 10);
752             break;
753         case KC_PGDN:
754             mousekey_param_dec(mousekey_param, 10);
755             break;
756         case KC_D:
757             mk_delay = MOUSEKEY_DELAY/10;
758             mk_interval = MOUSEKEY_INTERVAL;
759             mk_max_speed = MOUSEKEY_MAX_SPEED;
760             mk_time_to_max = MOUSEKEY_TIME_TO_MAX;
761             mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED;
762             mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX;
763             print("set default\n");
764             break;
765         default:
766             print("?");
767             return false;
768     }
769     if (mousekey_param) {
770         xprintf("M%d> ", mousekey_param);
771     } else {
772         print("M>" );
773     }
774     return true;
775 }
776 #endif
777
778
779 /***********************************************************
780  * Utilities
781  ***********************************************************/
782 uint8_t numkey2num(uint8_t code)
783 {
784     switch (code) {
785         case KC_1: return 1;
786         case KC_2: return 2;
787         case KC_3: return 3;
788         case KC_4: return 4;
789         case KC_5: return 5;
790         case KC_6: return 6;
791         case KC_7: return 7;
792         case KC_8: return 8;
793         case KC_9: return 9;
794         case KC_0: return 0;
795     }
796     return 0;
797 }
798
799 static void switch_default_layer(uint8_t layer)
800 {
801     xprintf("L%d\n", layer);
802     default_layer_set(1UL<<layer);
803     clear_keyboard();
804 }