diff options
author | Joel Challis <git@zvecr.com> | 2021-02-07 23:16:15 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-07 23:16:15 +0000 |
commit | 99bffc2a21ebed07fd767ad2a9a7e1aadd491ef3 (patch) | |
tree | 499edfaa4b2a180047f7ca5f6bc882e77f5262fa /quantum/command.c | |
parent | 7e828795534f7351df54d2c0545b2ed159b1bfde (diff) | |
download | qmk_firmware-99bffc2a21ebed07fd767ad2a9a7e1aadd491ef3.tar.gz qmk_firmware-99bffc2a21ebed07fd767ad2a9a7e1aadd491ef3.zip |
Migrate some tmk_core files to quantum (#11791)
* Migrate some tmk_core files to quantum
* Fix build errors
Diffstat (limited to 'quantum/command.c')
-rw-r--r-- | quantum/command.c | 786 |
1 files changed, 786 insertions, 0 deletions
diff --git a/quantum/command.c b/quantum/command.c new file mode 100644 index 000000000..59aa4e4d3 --- /dev/null +++ b/quantum/command.c | |||
@@ -0,0 +1,786 @@ | |||
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 | #if defined(MOUSEKEY_ENABLE) && !defined(MK_3_SPEED) | ||
43 | # include "mousekey.h" | ||
44 | #endif | ||
45 | |||
46 | #ifdef AUDIO_ENABLE | ||
47 | # include "audio.h" | ||
48 | #endif /* AUDIO_ENABLE */ | ||
49 | |||
50 | static bool command_common(uint8_t code); | ||
51 | static void command_common_help(void); | ||
52 | static void print_version(void); | ||
53 | static void print_status(void); | ||
54 | static bool command_console(uint8_t code); | ||
55 | static void command_console_help(void); | ||
56 | #if defined(MOUSEKEY_ENABLE) && !defined(MK_3_SPEED) | ||
57 | static bool mousekey_console(uint8_t code); | ||
58 | static void mousekey_console_help(void); | ||
59 | #endif | ||
60 | |||
61 | static void switch_default_layer(uint8_t layer); | ||
62 | |||
63 | command_state_t command_state = ONESHOT; | ||
64 | |||
65 | bool command_proc(uint8_t code) { | ||
66 | switch (command_state) { | ||
67 | case ONESHOT: | ||
68 | if (!IS_COMMAND()) return false; | ||
69 | return (command_extra(code) || command_common(code)); | ||
70 | break; | ||
71 | case CONSOLE: | ||
72 | if (IS_COMMAND()) | ||
73 | return (command_extra(code) || command_common(code)); | ||
74 | else | ||
75 | return (command_console_extra(code) || command_console(code)); | ||
76 | break; | ||
77 | #if defined(MOUSEKEY_ENABLE) && !defined(MK_3_SPEED) | ||
78 | case MOUSEKEY: | ||
79 | mousekey_console(code); | ||
80 | break; | ||
81 | #endif | ||
82 | default: | ||
83 | command_state = ONESHOT; | ||
84 | return false; | ||
85 | } | ||
86 | return true; | ||
87 | } | ||
88 | |||
89 | /* TODO: Refactoring is needed. */ | ||
90 | /* This allows to define extra commands. return false when not processed. */ | ||
91 | bool command_extra(uint8_t code) __attribute__((weak)); | ||
92 | bool command_extra(uint8_t code) { | ||
93 | (void)code; | ||
94 | return false; | ||
95 | } | ||
96 | |||
97 | bool command_console_extra(uint8_t code) __attribute__((weak)); | ||
98 | bool command_console_extra(uint8_t code) { | ||
99 | (void)code; | ||
100 | return false; | ||
101 | } | ||
102 | |||
103 | /*********************************************************** | ||
104 | * Command common | ||
105 | ***********************************************************/ | ||
106 | static void command_common_help(void) { | ||
107 | 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" | ||
108 | |||
109 | #if MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM | ||
110 | 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" | ||
111 | #endif | ||
112 | |||
113 | #if MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS | ||
114 | "F1-F10: Switch to Layer 0-9 (F10 = L0)\n" | ||
115 | #endif | ||
116 | |||
117 | #if MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS | ||
118 | "0-9: Switch to Layer 0-9\n" | ||
119 | #endif | ||
120 | |||
121 | STR(MAGIC_KEY_LAYER0_ALT) ": Switch to Layer 0 (alternate)\n" | ||
122 | |||
123 | STR(MAGIC_KEY_BOOTLOADER) ": Jump to Bootloader\n" STR(MAGIC_KEY_BOOTLOADER_ALT) ": Jump to Bootloader (alternate)\n" | ||
124 | |||
125 | #ifdef KEYBOARD_LOCK_ENABLE | ||
126 | STR(MAGIC_KEY_LOCK) ": Lock Keyboard\n" | ||
127 | #endif | ||
128 | |||
129 | STR(MAGIC_KEY_EEPROM) ": Print EEPROM Settings\n" STR(MAGIC_KEY_EEPROM_CLEAR) ": Clear EEPROM\n" | ||
130 | |||
131 | #ifdef NKRO_ENABLE | ||
132 | STR(MAGIC_KEY_NKRO) ": NKRO Toggle\n" | ||
133 | #endif | ||
134 | |||
135 | #ifdef SLEEP_LED_ENABLE | ||
136 | STR(MAGIC_KEY_SLEEP_LED) ": Sleep LED Test\n" | ||
137 | #endif | ||
138 | ); | ||
139 | } | ||
140 | |||
141 | static void print_version(void) { | ||
142 | // print version & information | ||
143 | print("\n\t- Version -\n"); | ||
144 | print("VID: " STR(VENDOR_ID) "(" STR(MANUFACTURER) ") " | ||
145 | "PID: " STR(PRODUCT_ID) "(" STR(PRODUCT) ") " | ||
146 | "VER: " STR(DEVICE_VER) "\n"); | ||
147 | print("BUILD: (" __DATE__ ")\n"); | ||
148 | #ifndef SKIP_VERSION | ||
149 | # ifdef PROTOCOL_CHIBIOS | ||
150 | print("CHIBIOS: " STR(CHIBIOS_VERSION) ", CONTRIB: " STR(CHIBIOS_CONTRIB_VERSION) "\n"); | ||
151 | # endif | ||
152 | #endif | ||
153 | |||
154 | /* build options */ | ||
155 | print("OPTIONS:" | ||
156 | |||
157 | #ifdef PROTOCOL_LUFA | ||
158 | " LUFA" | ||
159 | #endif | ||
160 | #ifdef PROTOCOL_VUSB | ||
161 | " VUSB" | ||
162 | #endif | ||
163 | #ifdef BOOTMAGIC_ENABLE | ||
164 | " BOOTMAGIC" | ||
165 | #endif | ||
166 | #ifdef MOUSEKEY_ENABLE | ||
167 | " MOUSEKEY" | ||
168 | #endif | ||
169 | #ifdef EXTRAKEY_ENABLE | ||
170 | " EXTRAKEY" | ||
171 | #endif | ||
172 | #ifdef CONSOLE_ENABLE | ||
173 | " CONSOLE" | ||
174 | #endif | ||
175 | #ifdef COMMAND_ENABLE | ||
176 | " COMMAND" | ||
177 | #endif | ||
178 | #ifdef NKRO_ENABLE | ||
179 | " NKRO" | ||
180 | #endif | ||
181 | #ifdef LTO_ENABLE | ||
182 | " LTO" | ||
183 | #endif | ||
184 | |||
185 | " " STR(BOOTLOADER_SIZE) "\n"); | ||
186 | |||
187 | print("GCC: " STR(__GNUC__) "." STR(__GNUC_MINOR__) "." STR(__GNUC_PATCHLEVEL__) | ||
188 | #if defined(__AVR__) | ||
189 | " AVR-LIBC: " __AVR_LIBC_VERSION_STRING__ " AVR_ARCH: avr" STR(__AVR_ARCH__) | ||
190 | #endif | ||
191 | "\n"); | ||
192 | |||
193 | return; | ||
194 | } | ||
195 | |||
196 | static void print_status(void) { | ||
197 | print("\n\t- Status -\n"); | ||
198 | |||
199 | print_val_hex8(host_keyboard_leds()); | ||
200 | #ifndef PROTOCOL_VUSB | ||
201 | // these aren't set on the V-USB protocol, so we just ignore them for now | ||
202 | print_val_hex8(keyboard_protocol); | ||
203 | print_val_hex8(keyboard_idle); | ||
204 | #endif | ||
205 | #ifdef NKRO_ENABLE | ||
206 | print_val_hex8(keymap_config.nkro); | ||
207 | #endif | ||
208 | print_val_hex32(timer_read32()); | ||
209 | return; | ||
210 | } | ||
211 | |||
212 | static void print_eeconfig(void) { | ||
213 | // Print these variables if NO_PRINT or USER_PRINT are not defined. | ||
214 | #if !defined(NO_PRINT) && !defined(USER_PRINT) | ||
215 | |||
216 | print("default_layer: "); | ||
217 | print_dec(eeconfig_read_default_layer()); | ||
218 | print("\n"); | ||
219 | |||
220 | debug_config_t dc; | ||
221 | dc.raw = eeconfig_read_debug(); | ||
222 | print("debug_config.raw: "); | ||
223 | print_hex8(dc.raw); | ||
224 | print("\n"); | ||
225 | print(".enable: "); | ||
226 | print_dec(dc.enable); | ||
227 | print("\n"); | ||
228 | print(".matrix: "); | ||
229 | print_dec(dc.matrix); | ||
230 | print("\n"); | ||
231 | print(".keyboard: "); | ||
232 | print_dec(dc.keyboard); | ||
233 | print("\n"); | ||
234 | print(".mouse: "); | ||
235 | print_dec(dc.mouse); | ||
236 | print("\n"); | ||
237 | |||
238 | keymap_config_t kc; | ||
239 | kc.raw = eeconfig_read_keymap(); | ||
240 | print("keymap_config.raw: "); | ||
241 | print_hex8(kc.raw); | ||
242 | print("\n"); | ||
243 | print(".swap_control_capslock: "); | ||
244 | print_dec(kc.swap_control_capslock); | ||
245 | print("\n"); | ||
246 | print(".capslock_to_control: "); | ||
247 | print_dec(kc.capslock_to_control); | ||
248 | print("\n"); | ||
249 | print(".swap_lctl_lgui: "); | ||
250 | print_dec(kc.swap_lctl_lgui); | ||
251 | print("\n"); | ||
252 | print(".swap_rctl_rgui: "); | ||
253 | print_dec(kc.swap_rctl_rgui); | ||
254 | print("\n"); | ||
255 | print(".swap_lalt_lgui: "); | ||
256 | print_dec(kc.swap_lalt_lgui); | ||
257 | print("\n"); | ||
258 | print(".swap_ralt_rgui: "); | ||
259 | print_dec(kc.swap_ralt_rgui); | ||
260 | print("\n"); | ||
261 | print(".no_gui: "); | ||
262 | print_dec(kc.no_gui); | ||
263 | print("\n"); | ||
264 | print(".swap_grave_esc: "); | ||
265 | print_dec(kc.swap_grave_esc); | ||
266 | print("\n"); | ||
267 | print(".swap_backslash_backspace: "); | ||
268 | print_dec(kc.swap_backslash_backspace); | ||
269 | print("\n"); | ||
270 | print(".nkro: "); | ||
271 | print_dec(kc.nkro); | ||
272 | print("\n"); | ||
273 | |||
274 | # ifdef BACKLIGHT_ENABLE | ||
275 | backlight_config_t bc; | ||
276 | bc.raw = eeconfig_read_backlight(); | ||
277 | print("backlight_config.raw: "); | ||
278 | print_hex8(bc.raw); | ||
279 | print("\n"); | ||
280 | print(".enable: "); | ||
281 | print_dec(bc.enable); | ||
282 | print("\n"); | ||
283 | print(".level: "); | ||
284 | print_dec(bc.level); | ||
285 | print("\n"); | ||
286 | # endif /* BACKLIGHT_ENABLE */ | ||
287 | |||
288 | #endif /* !NO_PRINT */ | ||
289 | } | ||
290 | |||
291 | static bool command_common(uint8_t code) { | ||
292 | #ifdef KEYBOARD_LOCK_ENABLE | ||
293 | static host_driver_t *host_driver = 0; | ||
294 | #endif | ||
295 | |||
296 | switch (code) { | ||
297 | #ifdef SLEEP_LED_ENABLE | ||
298 | |||
299 | // test breathing sleep LED | ||
300 | case MAGIC_KC(MAGIC_KEY_SLEEP_LED): | ||
301 | print("Sleep LED Test\n"); | ||
302 | sleep_led_toggle(); | ||
303 | led_set(host_keyboard_leds()); | ||
304 | break; | ||
305 | #endif | ||
306 | |||
307 | // print stored eeprom config | ||
308 | case MAGIC_KC(MAGIC_KEY_EEPROM): | ||
309 | print("eeconfig:\n"); | ||
310 | print_eeconfig(); | ||
311 | break; | ||
312 | |||
313 | // clear eeprom | ||
314 | case MAGIC_KC(MAGIC_KEY_EEPROM_CLEAR): | ||
315 | print("Clearing EEPROM\n"); | ||
316 | eeconfig_init(); | ||
317 | break; | ||
318 | |||
319 | #ifdef KEYBOARD_LOCK_ENABLE | ||
320 | |||
321 | // lock/unlock keyboard | ||
322 | case MAGIC_KC(MAGIC_KEY_LOCK): | ||
323 | if (host_get_driver()) { | ||
324 | host_driver = host_get_driver(); | ||
325 | clear_keyboard(); | ||
326 | host_set_driver(0); | ||
327 | print("Locked.\n"); | ||
328 | } else { | ||
329 | host_set_driver(host_driver); | ||
330 | print("Unlocked.\n"); | ||
331 | } | ||
332 | break; | ||
333 | #endif | ||
334 | |||
335 | // print help | ||
336 | case MAGIC_KC(MAGIC_KEY_HELP): | ||
337 | case MAGIC_KC(MAGIC_KEY_HELP_ALT): | ||
338 | command_common_help(); | ||
339 | break; | ||
340 | |||
341 | // activate console | ||
342 | case MAGIC_KC(MAGIC_KEY_CONSOLE): | ||
343 | debug_matrix = false; | ||
344 | debug_keyboard = false; | ||
345 | debug_mouse = false; | ||
346 | debug_enable = false; | ||
347 | command_console_help(); | ||
348 | print("C> "); | ||
349 | command_state = CONSOLE; | ||
350 | break; | ||
351 | |||
352 | // jump to bootloader | ||
353 | case MAGIC_KC(MAGIC_KEY_BOOTLOADER): | ||
354 | case MAGIC_KC(MAGIC_KEY_BOOTLOADER_ALT): | ||
355 | print("\n\nJumping to bootloader... "); | ||
356 | reset_keyboard(); | ||
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 | } else { | ||
365 | print("\ndebug: off\n"); | ||
366 | debug_matrix = false; | ||
367 | debug_keyboard = false; | ||
368 | debug_mouse = false; | ||
369 | } | ||
370 | break; | ||
371 | |||
372 | // debug matrix toggle | ||
373 | case MAGIC_KC(MAGIC_KEY_DEBUG_MATRIX): | ||
374 | debug_matrix = !debug_matrix; | ||
375 | if (debug_matrix) { | ||
376 | print("\nmatrix: on\n"); | ||
377 | debug_enable = true; | ||
378 | } else { | ||
379 | print("\nmatrix: off\n"); | ||
380 | } | ||
381 | break; | ||
382 | |||
383 | // debug keyboard toggle | ||
384 | case MAGIC_KC(MAGIC_KEY_DEBUG_KBD): | ||
385 | debug_keyboard = !debug_keyboard; | ||
386 | if (debug_keyboard) { | ||
387 | print("\nkeyboard: on\n"); | ||
388 | debug_enable = true; | ||
389 | } else { | ||
390 | print("\nkeyboard: off\n"); | ||
391 | } | ||
392 | break; | ||
393 | |||
394 | // debug mouse toggle | ||
395 | case MAGIC_KC(MAGIC_KEY_DEBUG_MOUSE): | ||
396 | debug_mouse = !debug_mouse; | ||
397 | if (debug_mouse) { | ||
398 | print("\nmouse: on\n"); | ||
399 | debug_enable = true; | ||
400 | } else { | ||
401 | print("\nmouse: off\n"); | ||
402 | } | ||
403 | break; | ||
404 | |||
405 | // print version | ||
406 | case MAGIC_KC(MAGIC_KEY_VERSION): | ||
407 | print_version(); | ||
408 | break; | ||
409 | |||
410 | // print status | ||
411 | case MAGIC_KC(MAGIC_KEY_STATUS): | ||
412 | print_status(); | ||
413 | break; | ||
414 | |||
415 | #ifdef NKRO_ENABLE | ||
416 | |||
417 | // NKRO toggle | ||
418 | case MAGIC_KC(MAGIC_KEY_NKRO): | ||
419 | clear_keyboard(); // clear to prevent stuck keys | ||
420 | keymap_config.nkro = !keymap_config.nkro; | ||
421 | if (keymap_config.nkro) { | ||
422 | print("NKRO: on\n"); | ||
423 | } else { | ||
424 | print("NKRO: off\n"); | ||
425 | } | ||
426 | break; | ||
427 | #endif | ||
428 | |||
429 | // switch layers | ||
430 | |||
431 | case MAGIC_KC(MAGIC_KEY_LAYER0_ALT): | ||
432 | switch_default_layer(0); | ||
433 | break; | ||
434 | |||
435 | #if MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM | ||
436 | |||
437 | case MAGIC_KC(MAGIC_KEY_LAYER0): | ||
438 | switch_default_layer(0); | ||
439 | break; | ||
440 | |||
441 | case MAGIC_KC(MAGIC_KEY_LAYER1): | ||
442 | switch_default_layer(1); | ||
443 | break; | ||
444 | |||
445 | case MAGIC_KC(MAGIC_KEY_LAYER2): | ||
446 | switch_default_layer(2); | ||
447 | break; | ||
448 | |||
449 | case MAGIC_KC(MAGIC_KEY_LAYER3): | ||
450 | switch_default_layer(3); | ||
451 | break; | ||
452 | |||
453 | case MAGIC_KC(MAGIC_KEY_LAYER4): | ||
454 | switch_default_layer(4); | ||
455 | break; | ||
456 | |||
457 | case MAGIC_KC(MAGIC_KEY_LAYER5): | ||
458 | switch_default_layer(5); | ||
459 | break; | ||
460 | |||
461 | case MAGIC_KC(MAGIC_KEY_LAYER6): | ||
462 | switch_default_layer(6); | ||
463 | break; | ||
464 | |||
465 | case MAGIC_KC(MAGIC_KEY_LAYER7): | ||
466 | switch_default_layer(7); | ||
467 | break; | ||
468 | |||
469 | case MAGIC_KC(MAGIC_KEY_LAYER8): | ||
470 | switch_default_layer(8); | ||
471 | break; | ||
472 | |||
473 | case MAGIC_KC(MAGIC_KEY_LAYER9): | ||
474 | switch_default_layer(9); | ||
475 | break; | ||
476 | #endif | ||
477 | |||
478 | #if MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS | ||
479 | |||
480 | case KC_F1 ... KC_F9: | ||
481 | switch_default_layer((code - KC_F1) + 1); | ||
482 | break; | ||
483 | case KC_F10: | ||
484 | switch_default_layer(0); | ||
485 | break; | ||
486 | #endif | ||
487 | |||
488 | #if MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS | ||
489 | |||
490 | case KC_1 ... KC_9: | ||
491 | switch_default_layer((code - KC_1) + 1); | ||
492 | break; | ||
493 | case KC_0: | ||
494 | switch_default_layer(0); | ||
495 | break; | ||
496 | #endif | ||
497 | |||
498 | default: | ||
499 | print("?"); | ||
500 | return false; | ||
501 | } | ||
502 | return true; | ||
503 | } | ||
504 | |||
505 | /*********************************************************** | ||
506 | * Command console | ||
507 | ***********************************************************/ | ||
508 | static void command_console_help(void) { | ||
509 | print("\n\t- Console -\n" | ||
510 | "ESC/q: quit\n" | ||
511 | #ifdef MOUSEKEY_ENABLE | ||
512 | "m: mousekey\n" | ||
513 | #endif | ||
514 | ); | ||
515 | } | ||
516 | |||
517 | static bool command_console(uint8_t code) { | ||
518 | switch (code) { | ||
519 | case KC_H: | ||
520 | case KC_SLASH: /* ? */ | ||
521 | command_console_help(); | ||
522 | break; | ||
523 | case KC_Q: | ||
524 | case KC_ESC: | ||
525 | command_state = ONESHOT; | ||
526 | return false; | ||
527 | #if defined(MOUSEKEY_ENABLE) && !defined(MK_3_SPEED) | ||
528 | case KC_M: | ||
529 | mousekey_console_help(); | ||
530 | print("M> "); | ||
531 | command_state = MOUSEKEY; | ||
532 | return true; | ||
533 | #endif | ||
534 | default: | ||
535 | print("?"); | ||
536 | return false; | ||
537 | } | ||
538 | print("C> "); | ||
539 | return true; | ||
540 | } | ||
541 | |||
542 | #if defined(MOUSEKEY_ENABLE) && !defined(MK_3_SPEED) | ||
543 | /*********************************************************** | ||
544 | * Mousekey console | ||
545 | ***********************************************************/ | ||
546 | static uint8_t mousekey_param = 0; | ||
547 | |||
548 | static void mousekey_param_print(void) { | ||
549 | // Print these variables if NO_PRINT or USER_PRINT are not defined. | ||
550 | # if !defined(NO_PRINT) && !defined(USER_PRINT) | ||
551 | print("\n\t- Values -\n"); | ||
552 | print("1: delay(*10ms): "); | ||
553 | pdec(mk_delay); | ||
554 | print("\n"); | ||
555 | print("2: interval(ms): "); | ||
556 | pdec(mk_interval); | ||
557 | print("\n"); | ||
558 | print("3: max_speed: "); | ||
559 | pdec(mk_max_speed); | ||
560 | print("\n"); | ||
561 | print("4: time_to_max: "); | ||
562 | pdec(mk_time_to_max); | ||
563 | print("\n"); | ||
564 | print("5: wheel_max_speed: "); | ||
565 | pdec(mk_wheel_max_speed); | ||
566 | print("\n"); | ||
567 | print("6: wheel_time_to_max: "); | ||
568 | pdec(mk_wheel_time_to_max); | ||
569 | print("\n"); | ||
570 | # endif /* !NO_PRINT */ | ||
571 | } | ||
572 | |||
573 | //#define PRINT_SET_VAL(v) print(#v " = "); print_dec(v); print("\n"); | ||
574 | # define PRINT_SET_VAL(v) xprintf(# v " = %d\n", (v)) | ||
575 | static void mousekey_param_inc(uint8_t param, uint8_t inc) { | ||
576 | switch (param) { | ||
577 | case 1: | ||
578 | if (mk_delay + inc < UINT8_MAX) | ||
579 | mk_delay += inc; | ||
580 | else | ||
581 | mk_delay = UINT8_MAX; | ||
582 | PRINT_SET_VAL(mk_delay); | ||
583 | break; | ||
584 | case 2: | ||
585 | if (mk_interval + inc < UINT8_MAX) | ||
586 | mk_interval += inc; | ||
587 | else | ||
588 | mk_interval = UINT8_MAX; | ||
589 | PRINT_SET_VAL(mk_interval); | ||
590 | break; | ||
591 | case 3: | ||
592 | if (mk_max_speed + inc < UINT8_MAX) | ||
593 | mk_max_speed += inc; | ||
594 | else | ||
595 | mk_max_speed = UINT8_MAX; | ||
596 | PRINT_SET_VAL(mk_max_speed); | ||
597 | break; | ||
598 | case 4: | ||
599 | if (mk_time_to_max + inc < UINT8_MAX) | ||
600 | mk_time_to_max += inc; | ||
601 | else | ||
602 | mk_time_to_max = UINT8_MAX; | ||
603 | PRINT_SET_VAL(mk_time_to_max); | ||
604 | break; | ||
605 | case 5: | ||
606 | if (mk_wheel_max_speed + inc < UINT8_MAX) | ||
607 | mk_wheel_max_speed += inc; | ||
608 | else | ||
609 | mk_wheel_max_speed = UINT8_MAX; | ||
610 | PRINT_SET_VAL(mk_wheel_max_speed); | ||
611 | break; | ||
612 | case 6: | ||
613 | if (mk_wheel_time_to_max + inc < UINT8_MAX) | ||
614 | mk_wheel_time_to_max += inc; | ||
615 | else | ||
616 | mk_wheel_time_to_max = UINT8_MAX; | ||
617 | PRINT_SET_VAL(mk_wheel_time_to_max); | ||
618 | break; | ||
619 | } | ||
620 | } | ||
621 | |||
622 | static void mousekey_param_dec(uint8_t param, uint8_t dec) { | ||
623 | switch (param) { | ||
624 | case 1: | ||
625 | if (mk_delay > dec) | ||
626 | mk_delay -= dec; | ||
627 | else | ||
628 | mk_delay = 0; | ||
629 | PRINT_SET_VAL(mk_delay); | ||
630 | break; | ||
631 | case 2: | ||
632 | if (mk_interval > dec) | ||
633 | mk_interval -= dec; | ||
634 | else | ||
635 | mk_interval = 0; | ||
636 | PRINT_SET_VAL(mk_interval); | ||
637 | break; | ||
638 | case 3: | ||
639 | if (mk_max_speed > dec) | ||
640 | mk_max_speed -= dec; | ||
641 | else | ||
642 | mk_max_speed = 0; | ||
643 | PRINT_SET_VAL(mk_max_speed); | ||
644 | break; | ||
645 | case 4: | ||
646 | if (mk_time_to_max > dec) | ||
647 | mk_time_to_max -= dec; | ||
648 | else | ||
649 | mk_time_to_max = 0; | ||
650 | PRINT_SET_VAL(mk_time_to_max); | ||
651 | break; | ||
652 | case 5: | ||
653 | if (mk_wheel_max_speed > dec) | ||
654 | mk_wheel_max_speed -= dec; | ||
655 | else | ||
656 | mk_wheel_max_speed = 0; | ||
657 | PRINT_SET_VAL(mk_wheel_max_speed); | ||
658 | break; | ||
659 | case 6: | ||
660 | if (mk_wheel_time_to_max > dec) | ||
661 | mk_wheel_time_to_max -= dec; | ||
662 | else | ||
663 | mk_wheel_time_to_max = 0; | ||
664 | PRINT_SET_VAL(mk_wheel_time_to_max); | ||
665 | break; | ||
666 | } | ||
667 | } | ||
668 | |||
669 | static void mousekey_console_help(void) { | ||
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", | ||
689 | MOUSEKEY_MOVE_DELTA, MOUSEKEY_WHEEL_DELTA); | ||
690 | } | ||
691 | |||
692 | static bool mousekey_console(uint8_t code) { | ||
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 | } | ||
749 | return true; | ||
750 | } | ||
751 | #endif | ||
752 | |||
753 | /*********************************************************** | ||
754 | * Utilities | ||
755 | ***********************************************************/ | ||
756 | uint8_t numkey2num(uint8_t code) { | ||
757 | switch (code) { | ||
758 | case KC_1: | ||
759 | return 1; | ||
760 | case KC_2: | ||
761 | return 2; | ||
762 | case KC_3: | ||
763 | return 3; | ||
764 | case KC_4: | ||
765 | return 4; | ||
766 | case KC_5: | ||
767 | return 5; | ||
768 | case KC_6: | ||
769 | return 6; | ||
770 | case KC_7: | ||
771 | return 7; | ||
772 | case KC_8: | ||
773 | return 8; | ||
774 | case KC_9: | ||
775 | return 9; | ||
776 | case KC_0: | ||
777 | return 0; | ||
778 | } | ||
779 | return 0; | ||
780 | } | ||
781 | |||
782 | static void switch_default_layer(uint8_t layer) { | ||
783 | xprintf("L%d\n", layer); | ||
784 | default_layer_set(1UL << layer); | ||
785 | clear_keyboard(); | ||
786 | } | ||