aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/common/command.c
diff options
context:
space:
mode:
authortmk <hasu@tmk-kbd.com>2015-05-13 15:29:30 +0900
committertmk <hasu@tmk-kbd.com>2015-05-13 15:29:30 +0900
commit67137a908aaf22fbd0509fbc127a092b9c0ff84f (patch)
tree72b7d7936246119dbce47ee95de70cea72a38521 /tmk_core/common/command.c
parent192024124b65fb65a65b44eef0bbc308c5971cea (diff)
downloadqmk_firmware-67137a908aaf22fbd0509fbc127a092b9c0ff84f.tar.gz
qmk_firmware-67137a908aaf22fbd0509fbc127a092b9c0ff84f.zip
Reduce code size of magic commands
Diffstat (limited to 'tmk_core/common/command.c')
-rw-r--r--tmk_core/common/command.c195
1 files changed, 90 insertions, 105 deletions
diff --git a/tmk_core/common/command.c b/tmk_core/common/command.c
index fbaa9f2d7..1b6808be0 100644
--- a/tmk_core/common/command.c
+++ b/tmk_core/common/command.c
@@ -112,30 +112,33 @@ bool command_console_extra(uint8_t code)
112 ***********************************************************/ 112 ***********************************************************/
113static void command_common_help(void) 113static void command_common_help(void)
114{ 114{
115 print("\n\n----- Command Help -----\n"); 115 print("\n\t- Magic -\n"
116 print("c: enter console mode\n"); 116 "d: debug\n"
117 print("d: toggle debug enable\n"); 117 "x: debug matrix\n"
118 print("x: toggle matrix debug\n"); 118 "k: debug keyboard\n"
119 print("k: toggle keyboard debug\n"); 119 "m: debug mouse\n"
120 print("m: toggle mouse debug\n"); 120 "v: version\n"
121#ifdef SLEEP_LED_ENABLE 121 "s: status\n"
122 print("z: toggle sleep LED test\n"); 122 "c: console mode\n"
123 "0-4: layer0-4(F10-F4)\n"
124 "Paus: bootloader\n"
125
126#ifdef KEYBOARD_LOCK_ENABLE
127 "Caps: Lock\n"
128#endif
129
130#ifdef BOOTMAGIC_ENABLE
131 "e: eeprom\n"
123#endif 132#endif
124 print("v: print device version & info\n"); 133
125 print("t: print timer count\n");
126 print("s: print status\n");
127 print("e: print eeprom config\n");
128#ifdef NKRO_ENABLE 134#ifdef NKRO_ENABLE
129 print("n: toggle NKRO\n"); 135 "n: NKRO\n"
136#endif
137
138#ifdef SLEEP_LED_ENABLE
139 "z: sleep LED test\n"
130#endif 140#endif
131 print("0/F10: switch to Layer0 \n"); 141 );
132 print("1/F1: switch to Layer1 \n");
133 print("2/F2: switch to Layer2 \n");
134 print("3/F3: switch to Layer3 \n");
135 print("4/F4: switch to Layer4 \n");
136 print("PScr: power down/remote wake-up\n");
137 print("Caps: Lock Keyboard(Child Proof)\n");
138 print("Paus: jump to bootloader\n");
139} 142}
140 143
141#ifdef BOOTMAGIC_ENABLE 144#ifdef BOOTMAGIC_ENABLE
@@ -191,6 +194,7 @@ static bool command_common(uint8_t code)
191 print_eeconfig(); 194 print_eeconfig();
192 break; 195 break;
193#endif 196#endif
197#ifdef KEYBOARD_LOCK_ENABLE
194 case KC_CAPSLOCK: 198 case KC_CAPSLOCK:
195 if (host_get_driver()) { 199 if (host_get_driver()) {
196 host_driver = host_get_driver(); 200 host_driver = host_get_driver();
@@ -202,6 +206,7 @@ static bool command_common(uint8_t code)
202 print("Unlocked.\n"); 206 print("Unlocked.\n");
203 } 207 }
204 break; 208 break;
209#endif
205 case KC_H: 210 case KC_H:
206 case KC_SLASH: /* ? */ 211 case KC_SLASH: /* ? */
207 command_common_help(); 212 command_common_help();
@@ -212,58 +217,56 @@ static bool command_common(uint8_t code)
212 debug_mouse = false; 217 debug_mouse = false;
213 debug_enable = false; 218 debug_enable = false;
214 command_console_help(); 219 command_console_help();
215 print("\nEnter Console Mode\n");
216 print("C> "); 220 print("C> ");
217 command_state = CONSOLE; 221 command_state = CONSOLE;
218 break; 222 break;
219 case KC_PAUSE: 223 case KC_PAUSE:
220 clear_keyboard(); 224 clear_keyboard();
221 print("\n\nJump to bootloader... "); 225 print("\n\nbootloader... ");
222 _delay_ms(1000); 226 _delay_ms(1000);
223 bootloader_jump(); // not return 227 bootloader_jump(); // not return
224 print("not supported.\n");
225 break; 228 break;
226 case KC_D: 229 case KC_D:
227 if (debug_enable) { 230 if (debug_enable) {
228 print("\nDEBUG: disabled.\n"); 231 print("\ndebug: on\n");
229 debug_matrix = false; 232 debug_matrix = false;
230 debug_keyboard = false; 233 debug_keyboard = false;
231 debug_mouse = false; 234 debug_mouse = false;
232 debug_enable = false; 235 debug_enable = false;
233 } else { 236 } else {
234 print("\nDEBUG: enabled.\n"); 237 print("\ndebug: off\n");
235 debug_enable = true; 238 debug_enable = true;
236 } 239 }
237 break; 240 break;
238 case KC_X: // debug matrix toggle 241 case KC_X: // debug matrix toggle
239 debug_matrix = !debug_matrix; 242 debug_matrix = !debug_matrix;
240 if (debug_matrix) { 243 if (debug_matrix) {
241 print("\nDEBUG: matrix enabled.\n"); 244 print("\nmatrix: on\n");
242 debug_enable = true; 245 debug_enable = true;
243 } else { 246 } else {
244 print("\nDEBUG: matrix disabled.\n"); 247 print("\nmatrix: off\n");
245 } 248 }
246 break; 249 break;
247 case KC_K: // debug keyboard toggle 250 case KC_K: // debug keyboard toggle
248 debug_keyboard = !debug_keyboard; 251 debug_keyboard = !debug_keyboard;
249 if (debug_keyboard) { 252 if (debug_keyboard) {
250 print("\nDEBUG: keyboard enabled.\n"); 253 print("\nkeyboard: on\n");
251 debug_enable = true; 254 debug_enable = true;
252 } else { 255 } else {
253 print("\nDEBUG: keyboard disabled.\n"); 256 print("\nkeyboard: off\n");
254 } 257 }
255 break; 258 break;
256 case KC_M: // debug mouse toggle 259 case KC_M: // debug mouse toggle
257 debug_mouse = !debug_mouse; 260 debug_mouse = !debug_mouse;
258 if (debug_mouse) { 261 if (debug_mouse) {
259 print("\nDEBUG: mouse enabled.\n"); 262 print("\nmouse: on\n");
260 debug_enable = true; 263 debug_enable = true;
261 } else { 264 } else {
262 print("\nDEBUG: mouse disabled.\n"); 265 print("\nmouse: off\n");
263 } 266 }
264 break; 267 break;
265 case KC_V: // print version & information 268 case KC_V: // print version & information
266 print("\n\n----- Version -----\n"); 269 print("\n\t- Version -\n");
267 print("DESC: " STR(DESCRIPTION) "\n"); 270 print("DESC: " STR(DESCRIPTION) "\n");
268 print("VID: " STR(VENDOR_ID) "(" STR(MANUFACTURER) ") " 271 print("VID: " STR(VENDOR_ID) "(" STR(MANUFACTURER) ") "
269 "PID: " STR(PRODUCT_ID) "(" STR(PRODUCT) ") " 272 "PID: " STR(PRODUCT_ID) "(" STR(PRODUCT) ") "
@@ -307,14 +310,13 @@ static bool command_common(uint8_t code)
307 " AVR-LIBC: " __AVR_LIBC_VERSION_STRING__ 310 " AVR-LIBC: " __AVR_LIBC_VERSION_STRING__
308 " AVR_ARCH: avr" STR(__AVR_ARCH__) "\n"); 311 " AVR_ARCH: avr" STR(__AVR_ARCH__) "\n");
309 break; 312 break;
310 case KC_T: // print timer
311 print_val_hex32(timer_count);
312 break;
313 case KC_S: 313 case KC_S:
314 print("\n\n----- Status -----\n"); 314 print("\n\t- Status -\n");
315 print_val_hex8(host_keyboard_leds()); 315 print_val_hex8(host_keyboard_leds());
316 print_val_hex8(keyboard_protocol); 316 print_val_hex8(keyboard_protocol);
317 print_val_hex8(keyboard_idle); 317 print_val_hex8(keyboard_idle);
318 print_val_hex32(timer_count);
319
318#ifdef PROTOCOL_PJRC 320#ifdef PROTOCOL_PJRC
319 print_val_hex8(UDCON); 321 print_val_hex8(UDCON);
320 print_val_hex8(UDIEN); 322 print_val_hex8(UDIEN);
@@ -334,39 +336,21 @@ static bool command_common(uint8_t code)
334 clear_keyboard(); //Prevents stuck keys. 336 clear_keyboard(); //Prevents stuck keys.
335 keyboard_nkro = !keyboard_nkro; 337 keyboard_nkro = !keyboard_nkro;
336 if (keyboard_nkro) 338 if (keyboard_nkro)
337 print("NKRO: enabled\n"); 339 print("NKRO: on\n");
338 else 340 else
339 print("NKRO: disabled\n"); 341 print("NKRO: off\n");
340 break;
341#endif
342#ifdef EXTRAKEY_ENABLE
343 case KC_PSCREEN:
344 // TODO: Power key should take this feature? otherwise any key during suspend.
345#ifdef PROTOCOL_PJRC
346 if (suspend && remote_wakeup) {
347 usb_remote_wakeup();
348 } else {
349 host_system_send(SYSTEM_POWER_DOWN);
350 host_system_send(0);
351 _delay_ms(500);
352 }
353#else
354 host_system_send(SYSTEM_POWER_DOWN);
355 _delay_ms(100);
356 host_system_send(0);
357 _delay_ms(500);
358#endif
359 break; 342 break;
360#endif 343#endif
361 case KC_ESC: 344 case KC_ESC:
362 case KC_GRV: 345 case KC_GRV:
363 case KC_0: 346 case KC_0:
347 case KC_F10:
364 switch_default_layer(0); 348 switch_default_layer(0);
365 break; 349 break;
366 case KC_1 ... KC_9: 350 case KC_1 ... KC_9:
367 switch_default_layer((code - KC_1) + 1); 351 switch_default_layer((code - KC_1) + 1);
368 break; 352 break;
369 case KC_F1 ... KC_F12: 353 case KC_F1 ... KC_F9:
370 switch_default_layer((code - KC_F1) + 1); 354 switch_default_layer((code - KC_F1) + 1);
371 break; 355 break;
372 default: 356 default:
@@ -382,11 +366,12 @@ static bool command_common(uint8_t code)
382 ***********************************************************/ 366 ***********************************************************/
383static void command_console_help(void) 367static void command_console_help(void)
384{ 368{
385 print("\n\n----- Console Help -----\n"); 369 print("\n\t- Console -\n"
386 print("ESC/q: quit\n"); 370 "ESC/q: quit\n"
387#ifdef MOUSEKEY_ENABLE 371#ifdef MOUSEKEY_ENABLE
388 print("m: mousekey\n"); 372 "m: mousekey\n"
389#endif 373#endif
374 );
390} 375}
391 376
392static bool command_console(uint8_t code) 377static bool command_console(uint8_t code)
@@ -398,14 +383,12 @@ static bool command_console(uint8_t code)
398 break; 383 break;
399 case KC_Q: 384 case KC_Q:
400 case KC_ESC: 385 case KC_ESC:
401 print("\nQuit Console Mode\n");
402 command_state = ONESHOT; 386 command_state = ONESHOT;
403 return false; 387 return false;
404#ifdef MOUSEKEY_ENABLE 388#ifdef MOUSEKEY_ENABLE
405 case KC_M: 389 case KC_M:
406 mousekey_console_help(); 390 mousekey_console_help();
407 print("\nEnter Mousekey Console\n"); 391 print("M> ");
408 print("M0>");
409 command_state = MOUSEKEY; 392 command_state = MOUSEKEY;
410 return true; 393 return true;
411#endif 394#endif
@@ -426,16 +409,17 @@ static uint8_t mousekey_param = 0;
426 409
427static void mousekey_param_print(void) 410static void mousekey_param_print(void)
428{ 411{
429 print("\n\n----- Mousekey Parameters -----\n"); 412 print("\n\t- Values -\n");
430 print("1: mk_delay(*10ms): "); pdec(mk_delay); print("\n"); 413 print("1: delay(*10ms): "); pdec(mk_delay); print("\n");
431 print("2: mk_interval(ms): "); pdec(mk_interval); print("\n"); 414 print("2: interval(ms): "); pdec(mk_interval); print("\n");
432 print("3: mk_max_speed: "); pdec(mk_max_speed); print("\n"); 415 print("3: max_speed: "); pdec(mk_max_speed); print("\n");
433 print("4: mk_time_to_max: "); pdec(mk_time_to_max); print("\n"); 416 print("4: time_to_max: "); pdec(mk_time_to_max); print("\n");
434 print("5: mk_wheel_max_speed: "); pdec(mk_wheel_max_speed); print("\n"); 417 print("5: wheel_max_speed: "); pdec(mk_wheel_max_speed); print("\n");
435 print("6: mk_wheel_time_to_max: "); pdec(mk_wheel_time_to_max); print("\n"); 418 print("6: wheel_time_to_max: "); pdec(mk_wheel_time_to_max); print("\n");
436} 419}
437 420
438#define PRINT_SET_VAL(v) print(#v " = "); print_dec(v); print("\n"); 421//#define PRINT_SET_VAL(v) print(#v " = "); print_dec(v); print("\n");
422#define PRINT_SET_VAL(v) xprintf(#v " = %d\n", (v))
439static void mousekey_param_inc(uint8_t param, uint8_t inc) 423static void mousekey_param_inc(uint8_t param, uint8_t inc)
440{ 424{
441 switch (param) { 425 switch (param) {
@@ -534,24 +518,25 @@ static void mousekey_param_dec(uint8_t param, uint8_t dec)
534 518
535static void mousekey_console_help(void) 519static void mousekey_console_help(void)
536{ 520{
537 print("\n\n----- Mousekey Parameters Help -----\n"); 521 print("\n\t- Mousekey -\n"
538 print("ESC/q: quit\n"); 522 "ESC/q: quit\n"
539 print("1: select mk_delay(*10ms)\n"); 523 "1: delay(*10ms)\n"
540 print("2: select mk_interval(ms)\n"); 524 "2: interval(ms)\n"
541 print("3: select mk_max_speed\n"); 525 "3: max_speed\n"
542 print("4: select mk_time_to_max\n"); 526 "4: time_to_max\n"
543 print("5: select mk_wheel_max_speed\n"); 527 "5: wheel_max_speed\n"
544 print("6: select mk_wheel_time_to_max\n"); 528 "6: wheel_time_to_max\n"
545 print("p: print parameters\n"); 529 "\n"
546 print("d: set default values\n"); 530 "p: print values\n"
547 print("up: increase parameters(+1)\n"); 531 "d: set defaults\n"
548 print("down: decrease parameters(-1)\n"); 532 "up: +1\n"
549 print("pgup: increase parameters(+10)\n"); 533 "down: -1\n"
550 print("pgdown: decrease parameters(-10)\n"); 534 "pgup: +10\n"
551 print("\nspeed = delta * max_speed * (repeat / time_to_max)\n"); 535 "pgdown: -10\n"
552 print("where delta: cursor="); pdec(MOUSEKEY_MOVE_DELTA); 536 "\n"
553 print(", wheel="); pdec(MOUSEKEY_WHEEL_DELTA); print("\n"); 537 "speed = delta * max_speed * (repeat / time_to_max)\n");
554 print("See http://en.wikipedia.org/wiki/Mouse_keys\n"); 538 xprintf("where delta: cursor=%d, wheel=%d\n"
539 "See http://en.wikipedia.org/wiki/Mouse_keys\n", MOUSEKEY_MOVE_DELTA, MOUSEKEY_WHEEL_DELTA);
555} 540}
556 541
557static bool mousekey_console(uint8_t code) 542static bool mousekey_console(uint8_t code)
@@ -563,11 +548,14 @@ static bool mousekey_console(uint8_t code)
563 break; 548 break;
564 case KC_Q: 549 case KC_Q:
565 case KC_ESC: 550 case KC_ESC:
566 mousekey_param = 0; 551 if (mousekey_param) {
567 print("\nQuit Mousekey Console\n"); 552 mousekey_param = 0;
568 print("C> "); 553 } else {
569 command_state = CONSOLE; 554 print("C> ");
570 return false; 555 command_state = CONSOLE;
556 return false;
557 }
558 break;
571 case KC_P: 559 case KC_P:
572 mousekey_param_print(); 560 mousekey_param_print();
573 break; 561 break;
@@ -577,12 +565,7 @@ static bool mousekey_console(uint8_t code)
577 case KC_4: 565 case KC_4:
578 case KC_5: 566 case KC_5:
579 case KC_6: 567 case KC_6:
580 case KC_7:
581 case KC_8:
582 case KC_9:
583 case KC_0:
584 mousekey_param = numkey2num(code); 568 mousekey_param = numkey2num(code);
585 print("selected parameter: "); pdec(mousekey_param); print("\n");
586 break; 569 break;
587 case KC_UP: 570 case KC_UP:
588 mousekey_param_inc(mousekey_param, 1); 571 mousekey_param_inc(mousekey_param, 1);
@@ -603,13 +586,16 @@ static bool mousekey_console(uint8_t code)
603 mk_time_to_max = MOUSEKEY_TIME_TO_MAX; 586 mk_time_to_max = MOUSEKEY_TIME_TO_MAX;
604 mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED; 587 mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED;
605 mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX; 588 mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX;
606 print("set default values.\n"); 589 print("set default\n");
607 break; 590 break;
608 default: 591 default:
609 print("?"); 592 print("?");
610 return false; 593 return false;
611 } 594 }
612 print("M"); pdec(mousekey_param); print("> "); 595 if (mousekey_param)
596 xprintf("M%d> ", mousekey_param);
597 else
598 print("M>" );
613 return true; 599 return true;
614} 600}
615#endif 601#endif
@@ -637,8 +623,7 @@ static uint8_t numkey2num(uint8_t code)
637 623
638static void switch_default_layer(uint8_t layer) 624static void switch_default_layer(uint8_t layer)
639{ 625{
640 print("switch_default_layer: "); print_dec(biton32(default_layer_state)); 626 xprintf("L%d\n", layer);
641 print(" to "); print_dec(layer); print("\n");
642 default_layer_set(1UL<<layer); 627 default_layer_set(1UL<<layer);
643 clear_keyboard(); 628 clear_keyboard();
644} 629}