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