aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/common/command.c
diff options
context:
space:
mode:
authorskullY <skullydazed@gmail.com>2019-08-30 11:19:03 -0700
committerskullydazed <skullydazed@users.noreply.github.com>2019-08-30 15:01:52 -0700
commitb624f32f944acdc59dcb130674c09090c5c404cb (patch)
treebc13adbba137d122d9a2c2fb2fafcbb08ac10e25 /tmk_core/common/command.c
parent61af76a10d00aba185b8338604171de490a13e3b (diff)
downloadqmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.tar.gz
qmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.zip
clang-format changes
Diffstat (limited to 'tmk_core/common/command.c')
-rw-r--r--tmk_core/common/command.c400
1 files changed, 206 insertions, 194 deletions
diff --git a/tmk_core/common/command.c b/tmk_core/common/command.c
index 949615ecf..8bf72ef25 100644
--- a/tmk_core/common/command.c
+++ b/tmk_core/common/command.c
@@ -37,25 +37,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
37#include "version.h" 37#include "version.h"
38 38
39#ifdef MOUSEKEY_ENABLE 39#ifdef MOUSEKEY_ENABLE
40#include "mousekey.h" 40# include "mousekey.h"
41#endif 41#endif
42 42
43#ifdef PROTOCOL_PJRC 43#ifdef PROTOCOL_PJRC
44 #include "usb_keyboard.h" 44# include "usb_keyboard.h"
45 #ifdef EXTRAKEY_ENABLE 45# ifdef EXTRAKEY_ENABLE
46 #include "usb_extra.h" 46# include "usb_extra.h"
47 #endif 47# endif
48#endif 48#endif
49 49
50#ifdef PROTOCOL_VUSB 50#ifdef PROTOCOL_VUSB
51 #include "usbdrv.h" 51# include "usbdrv.h"
52#endif 52#endif
53 53
54#ifdef AUDIO_ENABLE 54#ifdef AUDIO_ENABLE
55 #include "audio.h" 55# include "audio.h"
56#endif /* AUDIO_ENABLE */ 56#endif /* AUDIO_ENABLE */
57 57
58
59static bool command_common(uint8_t code); 58static bool command_common(uint8_t code);
60static void command_common_help(void); 59static void command_common_help(void);
61static void print_version(void); 60static void print_version(void);
@@ -69,16 +68,12 @@ static void mousekey_console_help(void);
69 68
70static void switch_default_layer(uint8_t layer); 69static void switch_default_layer(uint8_t layer);
71 70
72
73command_state_t command_state = ONESHOT; 71command_state_t command_state = ONESHOT;
74 72
75 73bool command_proc(uint8_t code) {
76bool command_proc(uint8_t code)
77{
78 switch (command_state) { 74 switch (command_state) {
79 case ONESHOT: 75 case ONESHOT:
80 if (!IS_COMMAND()) 76 if (!IS_COMMAND()) return false;
81 return false;
82 return (command_extra(code) || command_common(code)); 77 return (command_extra(code) || command_common(code));
83 break; 78 break;
84 case CONSOLE: 79 case CONSOLE:
@@ -101,86 +96,63 @@ bool command_proc(uint8_t code)
101 96
102/* TODO: Refactoring is needed. */ 97/* TODO: Refactoring is needed. */
103/* This allows to define extra commands. return false when not processed. */ 98/* This allows to define extra commands. return false when not processed. */
104bool command_extra(uint8_t code) __attribute__ ((weak)); 99bool command_extra(uint8_t code) __attribute__((weak));
105bool command_extra(uint8_t code) 100bool command_extra(uint8_t code) {
106{
107 (void)code; 101 (void)code;
108 return false; 102 return false;
109} 103}
110 104
111bool command_console_extra(uint8_t code) __attribute__ ((weak)); 105bool command_console_extra(uint8_t code) __attribute__((weak));
112bool command_console_extra(uint8_t code) 106bool command_console_extra(uint8_t code) {
113{
114 (void)code; 107 (void)code;
115 return false; 108 return false;
116} 109}
117 110
118
119/*********************************************************** 111/***********************************************************
120 * Command common 112 * Command common
121 ***********************************************************/ 113 ***********************************************************/
122static void command_common_help(void) 114static void command_common_help(void) {
123{ 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"
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 116
133#if MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM 117#if MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM
134 STR(MAGIC_KEY_LAYER0 ) ": Switch to Layer 0\n" 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"
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 119#endif
145 120
146#if MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS 121#if MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS
147 "F1-F10: Switch to Layer 0-9 (F10 = L0)\n" 122 "F1-F10: Switch to Layer 0-9 (F10 = L0)\n"
148#endif 123#endif
149 124
150#if MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS 125#if MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS
151 "0-9: Switch to Layer 0-9\n" 126 "0-9: Switch to Layer 0-9\n"
152#endif 127#endif
153 128
154 STR(MAGIC_KEY_LAYER0_ALT ) ": Switch to Layer 0 (alternate)\n" 129 STR(MAGIC_KEY_LAYER0_ALT) ": Switch to Layer 0 (alternate)\n"
155 130
156 STR(MAGIC_KEY_BOOTLOADER ) ": Jump to Bootloader\n" 131 STR(MAGIC_KEY_BOOTLOADER) ": Jump to Bootloader\n" STR(MAGIC_KEY_BOOTLOADER_ALT) ": Jump to Bootloader (alternate)\n"
157 STR(MAGIC_KEY_BOOTLOADER_ALT) ": Jump to Bootloader (alternate)\n"
158 132
159#ifdef KEYBOARD_LOCK_ENABLE 133#ifdef KEYBOARD_LOCK_ENABLE
160 STR(MAGIC_KEY_LOCK ) ": Lock Keyboard\n" 134 STR(MAGIC_KEY_LOCK) ": Lock Keyboard\n"
161#endif 135#endif
162 136
163 STR(MAGIC_KEY_EEPROM ) ": Print EEPROM Settings\n" 137 STR(MAGIC_KEY_EEPROM) ": Print EEPROM Settings\n" STR(MAGIC_KEY_EEPROM_CLEAR) ": Clear EEPROM\n"
164 STR(MAGIC_KEY_EEPROM_CLEAR) ": Clear EEPROM\n"
165 138
166#ifdef NKRO_ENABLE 139#ifdef NKRO_ENABLE
167 STR(MAGIC_KEY_NKRO ) ": NKRO Toggle\n" 140 STR(MAGIC_KEY_NKRO) ": NKRO Toggle\n"
168#endif 141#endif
169 142
170#ifdef SLEEP_LED_ENABLE 143#ifdef SLEEP_LED_ENABLE
171 STR(MAGIC_KEY_SLEEP_LED ) ": Sleep LED Test\n" 144 STR(MAGIC_KEY_SLEEP_LED) ": Sleep LED Test\n"
172#endif 145#endif
173 ); 146 );
174} 147}
175 148
176static void print_version(void) 149static void print_version(void) {
177{ 150 // print version & information
178 // print version & information
179 print("\n\t- Version -\n"); 151 print("\n\t- Version -\n");
180 print("DESC: " STR(DESCRIPTION) "\n"); 152 print("DESC: " STR(DESCRIPTION) "\n");
181 print("VID: " STR(VENDOR_ID) "(" STR(MANUFACTURER) ") " 153 print("VID: " STR(VENDOR_ID) "(" STR(MANUFACTURER) ") "
182 "PID: " STR(PRODUCT_ID) "(" STR(PRODUCT) ") " 154 "PID: " STR(PRODUCT_ID) "(" STR(PRODUCT) ") "
183 "VER: " STR(DEVICE_VER) "\n"); 155 "VER: " STR(DEVICE_VER) "\n");
184#ifdef SKIP_VERSION 156#ifdef SKIP_VERSION
185 print("BUILD: (" __DATE__ ")\n"); 157 print("BUILD: (" __DATE__ ")\n");
186#else 158#else
@@ -191,51 +163,48 @@ static void print_version(void)
191 print("OPTIONS:" 163 print("OPTIONS:"
192 164
193#ifdef PROTOCOL_PJRC 165#ifdef PROTOCOL_PJRC
194 " PJRC" 166 " PJRC"
195#endif 167#endif
196#ifdef PROTOCOL_LUFA 168#ifdef PROTOCOL_LUFA
197 " LUFA" 169 " LUFA"
198#endif 170#endif
199#ifdef PROTOCOL_VUSB 171#ifdef PROTOCOL_VUSB
200 " VUSB" 172 " VUSB"
201#endif 173#endif
202#ifdef BOOTMAGIC_ENABLE 174#ifdef BOOTMAGIC_ENABLE
203 " BOOTMAGIC" 175 " BOOTMAGIC"
204#endif 176#endif
205#ifdef MOUSEKEY_ENABLE 177#ifdef MOUSEKEY_ENABLE
206 " MOUSEKEY" 178 " MOUSEKEY"
207#endif 179#endif
208#ifdef EXTRAKEY_ENABLE 180#ifdef EXTRAKEY_ENABLE
209 " EXTRAKEY" 181 " EXTRAKEY"
210#endif 182#endif
211#ifdef CONSOLE_ENABLE 183#ifdef CONSOLE_ENABLE
212 " CONSOLE" 184 " CONSOLE"
213#endif 185#endif
214#ifdef COMMAND_ENABLE 186#ifdef COMMAND_ENABLE
215 " COMMAND" 187 " COMMAND"
216#endif 188#endif
217#ifdef NKRO_ENABLE 189#ifdef NKRO_ENABLE
218 " NKRO" 190 " NKRO"
219#endif 191#endif
220#ifdef KEYMAP_SECTION_ENABLE 192#ifdef KEYMAP_SECTION_ENABLE
221 " KEYMAP_SECTION" 193 " KEYMAP_SECTION"
222#endif 194#endif
223 195
224 " " STR(BOOTLOADER_SIZE) "\n"); 196 " " STR(BOOTLOADER_SIZE) "\n");
225 197
226 print("GCC: " STR(__GNUC__) "." STR(__GNUC_MINOR__) "." STR(__GNUC_PATCHLEVEL__) 198 print("GCC: " STR(__GNUC__) "." STR(__GNUC_MINOR__) "." STR(__GNUC_PATCHLEVEL__)
227#if defined(__AVR__) 199#if defined(__AVR__)
228 " AVR-LIBC: " __AVR_LIBC_VERSION_STRING__ 200 " AVR-LIBC: " __AVR_LIBC_VERSION_STRING__ " AVR_ARCH: avr" STR(__AVR_ARCH__)
229 " AVR_ARCH: avr" STR(__AVR_ARCH__)
230#endif 201#endif
231 "\n"); 202 "\n");
232 203
233 return; 204 return;
234} 205}
235 206
236static void print_status(void) 207static void print_status(void) {
237{
238
239 print("\n\t- Status -\n"); 208 print("\n\t- Status -\n");
240 209
241 print_val_hex8(host_keyboard_leds()); 210 print_val_hex8(host_keyboard_leds());
@@ -258,67 +227,101 @@ static void print_status(void)
258#endif 227#endif
259 228
260#ifdef PROTOCOL_PJRC 229#ifdef PROTOCOL_PJRC
261# if USB_COUNT_SOF 230# if USB_COUNT_SOF
262 print_val_hex8(usbSofCount); 231 print_val_hex8(usbSofCount);
263# endif 232# endif
264#endif 233#endif
265 return; 234 return;
266} 235}
267 236
268static void print_eeconfig(void) 237static void print_eeconfig(void) {
269{
270
271// Print these variables if NO_PRINT or USER_PRINT are not defined. 238// Print these variables if NO_PRINT or USER_PRINT are not defined.
272#if !defined(NO_PRINT) && !defined(USER_PRINT) 239#if !defined(NO_PRINT) && !defined(USER_PRINT)
273 240
274 print("default_layer: "); print_dec(eeconfig_read_default_layer()); print("\n"); 241 print("default_layer: ");
242 print_dec(eeconfig_read_default_layer());
243 print("\n");
275 244
276 debug_config_t dc; 245 debug_config_t dc;
277 dc.raw = eeconfig_read_debug(); 246 dc.raw = eeconfig_read_debug();
278 print("debug_config.raw: "); print_hex8(dc.raw); print("\n"); 247 print("debug_config.raw: ");
279 print(".enable: "); print_dec(dc.enable); print("\n"); 248 print_hex8(dc.raw);
280 print(".matrix: "); print_dec(dc.matrix); print("\n"); 249 print("\n");
281 print(".keyboard: "); print_dec(dc.keyboard); print("\n"); 250 print(".enable: ");
282 print(".mouse: "); print_dec(dc.mouse); print("\n"); 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");
283 262
284 keymap_config_t kc; 263 keymap_config_t kc;
285 kc.raw = eeconfig_read_keymap(); 264 kc.raw = eeconfig_read_keymap();
286 print("keymap_config.raw: "); print_hex8(kc.raw); print("\n"); 265 print("keymap_config.raw: ");
287 print(".swap_control_capslock: "); print_dec(kc.swap_control_capslock); print("\n"); 266 print_hex8(kc.raw);
288 print(".capslock_to_control: "); print_dec(kc.capslock_to_control); print("\n"); 267 print("\n");
289 print(".swap_lctl_lgui: "); print_dec(kc.swap_lctl_lgui); print("\n"); 268 print(".swap_control_capslock: ");
290 print(".swap_rctl_rgui: "); print_dec(kc.swap_rctl_rgui); print("\n"); 269 print_dec(kc.swap_control_capslock);
291 print(".swap_lalt_lgui: "); print_dec(kc.swap_lalt_lgui); print("\n"); 270 print("\n");
292 print(".swap_ralt_rgui: "); print_dec(kc.swap_ralt_rgui); print("\n"); 271 print(".capslock_to_control: ");
293 print(".no_gui: "); print_dec(kc.no_gui); print("\n"); 272 print_dec(kc.capslock_to_control);
294 print(".swap_grave_esc: "); print_dec(kc.swap_grave_esc); print("\n"); 273 print("\n");
295 print(".swap_backslash_backspace: "); print_dec(kc.swap_backslash_backspace); print("\n"); 274 print(".swap_lctl_lgui: ");
296 print(".nkro: "); print_dec(kc.nkro); print("\n"); 275 print_dec(kc.swap_lctl_lgui);
297 276 print("\n");
298#ifdef BACKLIGHT_ENABLE 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
299 backlight_config_t bc; 300 backlight_config_t bc;
300 bc.raw = eeconfig_read_backlight(); 301 bc.raw = eeconfig_read_backlight();
301 print("backlight_config.raw: "); print_hex8(bc.raw); print("\n"); 302 print("backlight_config.raw: ");
302 print(".enable: "); print_dec(bc.enable); print("\n"); 303 print_hex8(bc.raw);
303 print(".level: "); print_dec(bc.level); print("\n"); 304 print("\n");
304#endif /* BACKLIGHT_ENABLE */ 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 */
305 312
306#endif /* !NO_PRINT */ 313#endif /* !NO_PRINT */
307
308} 314}
309 315
310static bool command_common(uint8_t code) 316static bool command_common(uint8_t code) {
311{
312
313#ifdef KEYBOARD_LOCK_ENABLE 317#ifdef KEYBOARD_LOCK_ENABLE
314 static host_driver_t *host_driver = 0; 318 static host_driver_t *host_driver = 0;
315#endif 319#endif
316 320
317 switch (code) { 321 switch (code) {
318
319#ifdef SLEEP_LED_ENABLE 322#ifdef SLEEP_LED_ENABLE
320 323
321 // test breathing sleep LED 324 // test breathing sleep LED
322 case MAGIC_KC(MAGIC_KEY_SLEEP_LED): 325 case MAGIC_KC(MAGIC_KEY_SLEEP_LED):
323 print("Sleep LED Test\n"); 326 print("Sleep LED Test\n");
324 sleep_led_toggle(); 327 sleep_led_toggle();
@@ -326,21 +329,21 @@ static bool command_common(uint8_t code)
326 break; 329 break;
327#endif 330#endif
328 331
329 // print stored eeprom config 332 // print stored eeprom config
330 case MAGIC_KC(MAGIC_KEY_EEPROM): 333 case MAGIC_KC(MAGIC_KEY_EEPROM):
331 print("eeconfig:\n"); 334 print("eeconfig:\n");
332 print_eeconfig(); 335 print_eeconfig();
333 break; 336 break;
334 337
335 // clear eeprom 338 // clear eeprom
336 case MAGIC_KC(MAGIC_KEY_EEPROM_CLEAR): 339 case MAGIC_KC(MAGIC_KEY_EEPROM_CLEAR):
337 print("Clearing EEPROM\n"); 340 print("Clearing EEPROM\n");
338 eeconfig_init(); 341 eeconfig_init();
339 break; 342 break;
340 343
341#ifdef KEYBOARD_LOCK_ENABLE 344#ifdef KEYBOARD_LOCK_ENABLE
342 345
343 // lock/unlock keyboard 346 // lock/unlock keyboard
344 case MAGIC_KC(MAGIC_KEY_LOCK): 347 case MAGIC_KC(MAGIC_KEY_LOCK):
345 if (host_get_driver()) { 348 if (host_get_driver()) {
346 host_driver = host_get_driver(); 349 host_driver = host_get_driver();
@@ -354,13 +357,13 @@ static bool command_common(uint8_t code)
354 break; 357 break;
355#endif 358#endif
356 359
357 // print help 360 // print help
358 case MAGIC_KC(MAGIC_KEY_HELP): 361 case MAGIC_KC(MAGIC_KEY_HELP):
359 case MAGIC_KC(MAGIC_KEY_HELP_ALT): 362 case MAGIC_KC(MAGIC_KEY_HELP_ALT):
360 command_common_help(); 363 command_common_help();
361 break; 364 break;
362 365
363 // activate console 366 // activate console
364 case MAGIC_KC(MAGIC_KEY_CONSOLE): 367 case MAGIC_KC(MAGIC_KEY_CONSOLE):
365 debug_matrix = false; 368 debug_matrix = false;
366 debug_keyboard = false; 369 debug_keyboard = false;
@@ -374,15 +377,15 @@ static bool command_common(uint8_t code)
374 // jump to bootloader 377 // jump to bootloader
375 case MAGIC_KC(MAGIC_KEY_BOOTLOADER): 378 case MAGIC_KC(MAGIC_KEY_BOOTLOADER):
376 case MAGIC_KC(MAGIC_KEY_BOOTLOADER_ALT): 379 case MAGIC_KC(MAGIC_KEY_BOOTLOADER_ALT):
377 clear_keyboard(); // clear to prevent stuck keys 380 clear_keyboard(); // clear to prevent stuck keys
378 print("\n\nJumping to bootloader... "); 381 print("\n\nJumping to bootloader... ");
379 #ifdef AUDIO_ENABLE 382#ifdef AUDIO_ENABLE
380 stop_all_notes(); 383 stop_all_notes();
381 shutdown_user(); 384 shutdown_user();
382 #else 385#else
383 wait_ms(1000); 386 wait_ms(1000);
384 #endif 387#endif
385 bootloader_jump(); // not return 388 bootloader_jump(); // not return
386 break; 389 break;
387 390
388 // debug toggle 391 // debug toggle
@@ -427,25 +430,25 @@ static bool command_common(uint8_t code)
427 print("\nmouse: on\n"); 430 print("\nmouse: on\n");
428 debug_enable = true; 431 debug_enable = true;
429 } else { 432 } else {
430 print("\nmouse: off\n"); 433 print("\nmouse: off\n");
431 } 434 }
432 break; 435 break;
433 436
434 // print version 437 // print version
435 case MAGIC_KC(MAGIC_KEY_VERSION): 438 case MAGIC_KC(MAGIC_KEY_VERSION):
436 print_version(); 439 print_version();
437 break; 440 break;
438 441
439 // print status 442 // print status
440 case MAGIC_KC(MAGIC_KEY_STATUS): 443 case MAGIC_KC(MAGIC_KEY_STATUS):
441 print_status(); 444 print_status();
442 break; 445 break;
443 446
444#ifdef NKRO_ENABLE 447#ifdef NKRO_ENABLE
445 448
446 // NKRO toggle 449 // NKRO toggle
447 case MAGIC_KC(MAGIC_KEY_NKRO): 450 case MAGIC_KC(MAGIC_KEY_NKRO):
448 clear_keyboard(); // clear to prevent stuck keys 451 clear_keyboard(); // clear to prevent stuck keys
449 keymap_config.nkro = !keymap_config.nkro; 452 keymap_config.nkro = !keymap_config.nkro;
450 if (keymap_config.nkro) { 453 if (keymap_config.nkro) {
451 print("NKRO: on\n"); 454 print("NKRO: on\n");
@@ -455,56 +458,55 @@ static bool command_common(uint8_t code)
455 break; 458 break;
456#endif 459#endif
457 460
458 // switch layers 461 // switch layers
459 462
460 case MAGIC_KC(MAGIC_KEY_LAYER0_ALT): 463 case MAGIC_KC(MAGIC_KEY_LAYER0_ALT):
461 switch_default_layer(0); 464 switch_default_layer(0);
462 break; 465 break;
463 466
464#if MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM 467#if MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM
465 468
466 case MAGIC_KC(MAGIC_KEY_LAYER0): 469 case MAGIC_KC(MAGIC_KEY_LAYER0):
467 switch_default_layer(0); 470 switch_default_layer(0);
468 break; 471 break;
469 472
470 case MAGIC_KC(MAGIC_KEY_LAYER1): 473 case MAGIC_KC(MAGIC_KEY_LAYER1):
471 switch_default_layer(1); 474 switch_default_layer(1);
472 break; 475 break;
473 476
474 case MAGIC_KC(MAGIC_KEY_LAYER2): 477 case MAGIC_KC(MAGIC_KEY_LAYER2):
475 switch_default_layer(2); 478 switch_default_layer(2);
476 break; 479 break;
477 480
478 case MAGIC_KC(MAGIC_KEY_LAYER3): 481 case MAGIC_KC(MAGIC_KEY_LAYER3):
479 switch_default_layer(3); 482 switch_default_layer(3);
480 break; 483 break;
481 484
482 case MAGIC_KC(MAGIC_KEY_LAYER4): 485 case MAGIC_KC(MAGIC_KEY_LAYER4):
483 switch_default_layer(4); 486 switch_default_layer(4);
484 break; 487 break;
485 488
486 case MAGIC_KC(MAGIC_KEY_LAYER5): 489 case MAGIC_KC(MAGIC_KEY_LAYER5):
487 switch_default_layer(5); 490 switch_default_layer(5);
488 break; 491 break;
489 492
490 case MAGIC_KC(MAGIC_KEY_LAYER6): 493 case MAGIC_KC(MAGIC_KEY_LAYER6):
491 switch_default_layer(6); 494 switch_default_layer(6);
492 break; 495 break;
493 496
494 case MAGIC_KC(MAGIC_KEY_LAYER7): 497 case MAGIC_KC(MAGIC_KEY_LAYER7):
495 switch_default_layer(7); 498 switch_default_layer(7);
496 break; 499 break;
497 500
498 case MAGIC_KC(MAGIC_KEY_LAYER8): 501 case MAGIC_KC(MAGIC_KEY_LAYER8):
499 switch_default_layer(8); 502 switch_default_layer(8);
500 break; 503 break;
501 504
502 case MAGIC_KC(MAGIC_KEY_LAYER9): 505 case MAGIC_KC(MAGIC_KEY_LAYER9):
503 switch_default_layer(9); 506 switch_default_layer(9);
504 break; 507 break;
505#endif 508#endif
506 509
507
508#if MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS 510#if MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS
509 511
510 case KC_F1 ... KC_F9: 512 case KC_F1 ... KC_F9:
@@ -532,12 +534,10 @@ static bool command_common(uint8_t code)
532 return true; 534 return true;
533} 535}
534 536
535
536/*********************************************************** 537/***********************************************************
537 * Command console 538 * Command console
538 ***********************************************************/ 539 ***********************************************************/
539static void command_console_help(void) 540static void command_console_help(void) {
540{
541 print("\n\t- Console -\n" 541 print("\n\t- Console -\n"
542 "ESC/q: quit\n" 542 "ESC/q: quit\n"
543#ifdef MOUSEKEY_ENABLE 543#ifdef MOUSEKEY_ENABLE
@@ -546,8 +546,7 @@ static void command_console_help(void)
546 ); 546 );
547} 547}
548 548
549static bool command_console(uint8_t code) 549static bool command_console(uint8_t code) {
550{
551 switch (code) { 550 switch (code) {
552 case KC_H: 551 case KC_H:
553 case KC_SLASH: /* ? */ 552 case KC_SLASH: /* ? */
@@ -572,32 +571,40 @@ static bool command_console(uint8_t code)
572 return true; 571 return true;
573} 572}
574 573
575
576#ifdef MOUSEKEY_ENABLE 574#ifdef MOUSEKEY_ENABLE
577/*********************************************************** 575/***********************************************************
578 * Mousekey console 576 * Mousekey console
579 ***********************************************************/ 577 ***********************************************************/
580static uint8_t mousekey_param = 0; 578static uint8_t mousekey_param = 0;
581 579
582static void mousekey_param_print(void) 580static void mousekey_param_print(void) {
583{
584// Print these variables if NO_PRINT or USER_PRINT are not defined. 581// Print these variables if NO_PRINT or USER_PRINT are not defined.
585#if !defined(NO_PRINT) && !defined(USER_PRINT) 582# if !defined(NO_PRINT) && !defined(USER_PRINT)
586 print("\n\t- Values -\n"); 583 print("\n\t- Values -\n");
587 print("1: delay(*10ms): "); pdec(mk_delay); print("\n"); 584 print("1: delay(*10ms): ");
588 print("2: interval(ms): "); pdec(mk_interval); print("\n"); 585 pdec(mk_delay);
589 print("3: max_speed: "); pdec(mk_max_speed); print("\n"); 586 print("\n");
590 print("4: time_to_max: "); pdec(mk_time_to_max); print("\n"); 587 print("2: interval(ms): ");
591 print("5: wheel_max_speed: "); pdec(mk_wheel_max_speed); print("\n"); 588 pdec(mk_interval);
592 print("6: wheel_time_to_max: "); pdec(mk_wheel_time_to_max); print("\n"); 589 print("\n");
593#endif /* !NO_PRINT */ 590 print("3: max_speed: ");
594 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 */
595} 603}
596 604
597//#define PRINT_SET_VAL(v) print(#v " = "); print_dec(v); print("\n"); 605//#define PRINT_SET_VAL(v) print(#v " = "); print_dec(v); print("\n");
598#define PRINT_SET_VAL(v) xprintf(#v " = %d\n", (v)) 606# define PRINT_SET_VAL(v) xprintf(# v " = %d\n", (v))
599static void mousekey_param_inc(uint8_t param, uint8_t inc) 607static void mousekey_param_inc(uint8_t param, uint8_t inc) {
600{
601 switch (param) { 608 switch (param) {
602 case 1: 609 case 1:
603 if (mk_delay + inc < UINT8_MAX) 610 if (mk_delay + inc < UINT8_MAX)
@@ -644,8 +651,7 @@ static void mousekey_param_inc(uint8_t param, uint8_t inc)
644 } 651 }
645} 652}
646 653
647static void mousekey_param_dec(uint8_t param, uint8_t dec) 654static void mousekey_param_dec(uint8_t param, uint8_t dec) {
648{
649 switch (param) { 655 switch (param) {
650 case 1: 656 case 1:
651 if (mk_delay > dec) 657 if (mk_delay > dec)
@@ -692,8 +698,7 @@ static void mousekey_param_dec(uint8_t param, uint8_t dec)
692 } 698 }
693} 699}
694 700
695static void mousekey_console_help(void) 701static void mousekey_console_help(void) {
696{
697 print("\n\t- Mousekey -\n" 702 print("\n\t- Mousekey -\n"
698 "ESC/q: quit\n" 703 "ESC/q: quit\n"
699 "1: delay(*10ms)\n" 704 "1: delay(*10ms)\n"
@@ -712,11 +717,11 @@ static void mousekey_console_help(void)
712 "\n" 717 "\n"
713 "speed = delta * max_speed * (repeat / time_to_max)\n"); 718 "speed = delta * max_speed * (repeat / time_to_max)\n");
714 xprintf("where delta: cursor=%d, wheel=%d\n" 719 xprintf("where delta: cursor=%d, wheel=%d\n"
715 "See http://en.wikipedia.org/wiki/Mouse_keys\n", MOUSEKEY_MOVE_DELTA, MOUSEKEY_WHEEL_DELTA); 720 "See http://en.wikipedia.org/wiki/Mouse_keys\n",
721 MOUSEKEY_MOVE_DELTA, MOUSEKEY_WHEEL_DELTA);
716} 722}
717 723
718static bool mousekey_console(uint8_t code) 724static bool mousekey_console(uint8_t code) {
719{
720 switch (code) { 725 switch (code) {
721 case KC_H: 726 case KC_H:
722 case KC_SLASH: /* ? */ 727 case KC_SLASH: /* ? */
@@ -756,11 +761,11 @@ static bool mousekey_console(uint8_t code)
756 mousekey_param_dec(mousekey_param, 10); 761 mousekey_param_dec(mousekey_param, 10);
757 break; 762 break;
758 case KC_D: 763 case KC_D:
759 mk_delay = MOUSEKEY_DELAY/10; 764 mk_delay = MOUSEKEY_DELAY / 10;
760 mk_interval = MOUSEKEY_INTERVAL; 765 mk_interval = MOUSEKEY_INTERVAL;
761 mk_max_speed = MOUSEKEY_MAX_SPEED; 766 mk_max_speed = MOUSEKEY_MAX_SPEED;
762 mk_time_to_max = MOUSEKEY_TIME_TO_MAX; 767 mk_time_to_max = MOUSEKEY_TIME_TO_MAX;
763 mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED; 768 mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED;
764 mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX; 769 mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX;
765 print("set default\n"); 770 print("set default\n");
766 break; 771 break;
@@ -771,36 +776,43 @@ static bool mousekey_console(uint8_t code)
771 if (mousekey_param) { 776 if (mousekey_param) {
772 xprintf("M%d> ", mousekey_param); 777 xprintf("M%d> ", mousekey_param);
773 } else { 778 } else {
774 print("M>" ); 779 print("M>");
775 } 780 }
776 return true; 781 return true;
777} 782}
778#endif 783#endif
779 784
780
781/*********************************************************** 785/***********************************************************
782 * Utilities 786 * Utilities
783 ***********************************************************/ 787 ***********************************************************/
784uint8_t numkey2num(uint8_t code) 788uint8_t numkey2num(uint8_t code) {
785{
786 switch (code) { 789 switch (code) {
787 case KC_1: return 1; 790 case KC_1:
788 case KC_2: return 2; 791 return 1;
789 case KC_3: return 3; 792 case KC_2:
790 case KC_4: return 4; 793 return 2;
791 case KC_5: return 5; 794 case KC_3:
792 case KC_6: return 6; 795 return 3;
793 case KC_7: return 7; 796 case KC_4:
794 case KC_8: return 8; 797 return 4;
795 case KC_9: return 9; 798 case KC_5:
796 case KC_0: return 0; 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;
797 } 810 }
798 return 0; 811 return 0;
799} 812}
800 813
801static void switch_default_layer(uint8_t layer) 814static void switch_default_layer(uint8_t layer) {
802{
803 xprintf("L%d\n", layer); 815 xprintf("L%d\n", layer);
804 default_layer_set(1UL<<layer); 816 default_layer_set(1UL << layer);
805 clear_keyboard(); 817 clear_keyboard();
806} 818}