X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=tmk_core%2Fcommon%2Fcommand.c;h=b4cd3ca56b9dc87e6dd342dfbc7d4652b13ba80e;hb=bc65f73c649b3e8edffcff841a84f9d1e0798bab;hp=fbaa9f2d7585775c02096013d60059d3ce8109fb;hpb=a3d96d3aa96318d339a67de1085e0ae495d57c84;p=qmk_firmware.git diff --git a/tmk_core/common/command.c b/tmk_core/common/command.c index fbaa9f2d7..b4cd3ca56 100644 --- a/tmk_core/common/command.c +++ b/tmk_core/common/command.c @@ -52,6 +52,8 @@ along with this program. If not, see . static bool command_common(uint8_t code); static void command_common_help(void); +static void print_version(void); +static void print_status(void); static bool command_console(uint8_t code); static void command_console_help(void); #ifdef MOUSEKEY_ENABLE @@ -112,30 +114,138 @@ bool command_console_extra(uint8_t code) ***********************************************************/ static void command_common_help(void) { - print("\n\n----- Command Help -----\n"); - print("c: enter console mode\n"); - print("d: toggle debug enable\n"); - print("x: toggle matrix debug\n"); - print("k: toggle keyboard debug\n"); - print("m: toggle mouse debug\n"); + 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" + +#if MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM + 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" +#endif + +#if MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS + "F1-F10: Switch to Layer 0-9 (F10 = L0)\n" +#endif + +#if MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS + "0-9: Switch to Layer 0-9\n" +#endif + + STR(MAGIC_KEY_LAYER0_ALT1 ) ": Switch to Layer 0 (alternate key 1)\n" + STR(MAGIC_KEY_LAYER0_ALT2 ) ": Switch to Layer 0 (alternate key 2)\n" + STR(MAGIC_KEY_BOOTLOADER ) ": Jump to Bootloader (Reset)\n" + +#ifdef KEYBOARD_LOCK_ENABLE + STR(MAGIC_KEY_LOCK ) ": Lock\n" +#endif + +#ifdef BOOTMAGIC_ENABLE + STR(MAGIC_KEY_EEPROM ) ": Print EEPROM Settings\n" +#endif + +#ifdef NKRO_ENABLE + STR(MAGIC_KEY_NKRO ) ": NKRO Toggle\n" +#endif + #ifdef SLEEP_LED_ENABLE - print("z: toggle sleep LED test\n"); + STR(MAGIC_KEY_SLEEP_LED ) ": Sleep LED Test\n" +#endif + ); +} + +static void print_version(void) +{ + // print version & information + print("\n\t- Version -\n"); + print("DESC: " STR(DESCRIPTION) "\n"); + print("VID: " STR(VENDOR_ID) "(" STR(MANUFACTURER) ") " + "PID: " STR(PRODUCT_ID) "(" STR(PRODUCT) ") " + "VER: " STR(DEVICE_VER) "\n"); + print("BUILD: " STR(VERSION) " (" __TIME__ " " __DATE__ ")\n"); + + /* build options */ + print("OPTIONS:" + +#ifdef PROTOCOL_PJRC + " PJRC" +#endif +#ifdef PROTOCOL_LUFA + " LUFA" +#endif +#ifdef PROTOCOL_VUSB + " VUSB" +#endif +#ifdef BOOTMAGIC_ENABLE + " BOOTMAGIC" +#endif +#ifdef MOUSEKEY_ENABLE + " MOUSEKEY" +#endif +#ifdef EXTRAKEY_ENABLE + " EXTRAKEY" +#endif +#ifdef CONSOLE_ENABLE + " CONSOLE" +#endif +#ifdef COMMAND_ENABLE + " COMMAND" #endif - print("v: print device version & info\n"); - print("t: print timer count\n"); - print("s: print status\n"); - print("e: print eeprom config\n"); #ifdef NKRO_ENABLE - print("n: toggle NKRO\n"); -#endif - print("0/F10: switch to Layer0 \n"); - print("1/F1: switch to Layer1 \n"); - print("2/F2: switch to Layer2 \n"); - print("3/F3: switch to Layer3 \n"); - print("4/F4: switch to Layer4 \n"); - print("PScr: power down/remote wake-up\n"); - print("Caps: Lock Keyboard(Child Proof)\n"); - print("Paus: jump to bootloader\n"); + " NKRO" +#endif +#ifdef KEYMAP_SECTION_ENABLE + " KEYMAP_SECTION" +#endif + + " " STR(BOOTLOADER_SIZE) "\n"); + + print("GCC: " STR(__GNUC__) "." STR(__GNUC_MINOR__) "." STR(__GNUC_PATCHLEVEL__) + " AVR-LIBC: " __AVR_LIBC_VERSION_STRING__ + " AVR_ARCH: avr" STR(__AVR_ARCH__) "\n"); + + return; +} + +static void print_status(void) +{ + + print("\n\t- Status -\n"); + + print_val_hex8(host_keyboard_leds()); + print_val_hex8(keyboard_protocol); + print_val_hex8(keyboard_idle); +#ifdef NKRO_ENABLE + print_val_hex8(keyboard_nkro); +#endif + print_val_hex32(timer_count); + +#ifdef PROTOCOL_PJRC + print_val_hex8(UDCON); + print_val_hex8(UDIEN); + print_val_hex8(UDINT); + print_val_hex8(usb_keyboard_leds); + print_val_hex8(usb_keyboard_idle_count); +#endif + +#ifdef PROTOCOL_PJRC +# if USB_COUNT_SOF + print_val_hex8(usbSofCount); +# endif +#endif + return; } #ifdef BOOTMAGIC_ENABLE @@ -175,23 +285,36 @@ static void print_eeconfig(void) static bool command_common(uint8_t code) { + +#ifdef KEYBOARD_LOCK_ENABLE static host_driver_t *host_driver = 0; +#endif + switch (code) { + #ifdef SLEEP_LED_ENABLE - case KC_Z: - // test breathing sleep LED - print("Sleep LED test\n"); + + // test breathing sleep LED + case MAGIC_KC(MAGIC_KEY_SLEEP_LED): + print("Sleep LED Test\n"); sleep_led_toggle(); led_set(host_keyboard_leds()); break; #endif + #ifdef BOOTMAGIC_ENABLE - case KC_E: + + // print stored eeprom config + case MAGIC_KC(MAGIC_KEY_EEPROM): print("eeconfig:\n"); print_eeconfig(); break; #endif - case KC_CAPSLOCK: + +#ifdef KEYBOARD_LOCK_ENABLE + + // lock/unlock keyboard + case MAGIC_KC(MAGIC_KEY_LOCK): if (host_get_driver()) { host_driver = host_get_driver(); clear_keyboard(); @@ -202,173 +325,176 @@ static bool command_common(uint8_t code) print("Unlocked.\n"); } break; - case KC_H: - case KC_SLASH: /* ? */ +#endif + + // print help + case MAGIC_KC(MAGIC_KEY_HELP1): + case MAGIC_KC(MAGIC_KEY_HELP2): command_common_help(); break; - case KC_C: + + // activate console + case MAGIC_KC(MAGIC_KEY_CONSOLE): debug_matrix = false; debug_keyboard = false; debug_mouse = false; debug_enable = false; command_console_help(); - print("\nEnter Console Mode\n"); print("C> "); command_state = CONSOLE; break; - case KC_PAUSE: - clear_keyboard(); - print("\n\nJump to bootloader... "); + + // jump to bootloader + case MAGIC_KC(MAGIC_KEY_BOOTLOADER): + clear_keyboard(); // clear to prevent stuck keys + print("\n\nJumping to bootloader... "); _delay_ms(1000); bootloader_jump(); // not return - print("not supported.\n"); break; - case KC_D: + + // debug toggle + case MAGIC_KC(MAGIC_KEY_DEBUG): + debug_enable = !debug_enable; if (debug_enable) { - print("\nDEBUG: disabled.\n"); + print("\ndebug: on\n"); + debug_matrix = true; + debug_keyboard = true; + debug_mouse = true; + } else { + print("\ndebug: off\n"); debug_matrix = false; debug_keyboard = false; debug_mouse = false; - debug_enable = false; - } else { - print("\nDEBUG: enabled.\n"); - debug_enable = true; } break; - case KC_X: // debug matrix toggle + + // debug matrix toggle + case MAGIC_KC(MAGIC_KEY_DEBUG_MATRIX): debug_matrix = !debug_matrix; if (debug_matrix) { - print("\nDEBUG: matrix enabled.\n"); + print("\nmatrix: on\n"); debug_enable = true; } else { - print("\nDEBUG: matrix disabled.\n"); + print("\nmatrix: off\n"); } break; - case KC_K: // debug keyboard toggle + + // debug keyboard toggle + case MAGIC_KC(MAGIC_KEY_DEBUG_KBD): debug_keyboard = !debug_keyboard; if (debug_keyboard) { - print("\nDEBUG: keyboard enabled.\n"); + print("\nkeyboard: on\n"); debug_enable = true; } else { - print("\nDEBUG: keyboard disabled.\n"); + print("\nkeyboard: off\n"); } break; - case KC_M: // debug mouse toggle + + // debug mouse toggle + case MAGIC_KC(MAGIC_KEY_DEBUG_MOUSE): debug_mouse = !debug_mouse; if (debug_mouse) { - print("\nDEBUG: mouse enabled.\n"); + print("\nmouse: on\n"); debug_enable = true; } else { - print("\nDEBUG: mouse disabled.\n"); + print("\nmouse: off\n"); } break; - case KC_V: // print version & information - print("\n\n----- Version -----\n"); - print("DESC: " STR(DESCRIPTION) "\n"); - print("VID: " STR(VENDOR_ID) "(" STR(MANUFACTURER) ") " - "PID: " STR(PRODUCT_ID) "(" STR(PRODUCT) ") " - "VER: " STR(DEVICE_VER) "\n"); - print("BUILD: " STR(VERSION) " (" __TIME__ " " __DATE__ ")\n"); - /* build options */ - print("OPTIONS:" -#ifdef PROTOCOL_PJRC - " PJRC" -#endif -#ifdef PROTOCOL_LUFA - " LUFA" -#endif -#ifdef PROTOCOL_VUSB - " VUSB" -#endif -#ifdef BOOTMAGIC_ENABLE - " BOOTMAGIC" -#endif -#ifdef MOUSEKEY_ENABLE - " MOUSEKEY" -#endif -#ifdef EXTRAKEY_ENABLE - " EXTRAKEY" -#endif -#ifdef CONSOLE_ENABLE - " CONSOLE" -#endif -#ifdef COMMAND_ENABLE - " COMMAND" -#endif -#ifdef NKRO_ENABLE - " NKRO" -#endif -#ifdef KEYMAP_SECTION_ENABLE - " KEYMAP_SECTION" -#endif - " " STR(BOOTLOADER_SIZE) "\n"); - print("GCC: " STR(__GNUC__) "." STR(__GNUC_MINOR__) "." STR(__GNUC_PATCHLEVEL__) - " AVR-LIBC: " __AVR_LIBC_VERSION_STRING__ - " AVR_ARCH: avr" STR(__AVR_ARCH__) "\n"); - break; - case KC_T: // print timer - print_val_hex32(timer_count); - break; - case KC_S: - print("\n\n----- Status -----\n"); - print_val_hex8(host_keyboard_leds()); - print_val_hex8(keyboard_protocol); - print_val_hex8(keyboard_idle); -#ifdef PROTOCOL_PJRC - print_val_hex8(UDCON); - print_val_hex8(UDIEN); - print_val_hex8(UDINT); - print_val_hex8(usb_keyboard_leds); - print_val_hex8(usb_keyboard_idle_count); -#endif + // print version + case MAGIC_KC(MAGIC_KEY_VERSION): + print_version(); + break; -#ifdef PROTOCOL_PJRC -# if USB_COUNT_SOF - print_val_hex8(usbSofCount); -# endif -#endif + // print status + case MAGIC_KC(MAGIC_KEY_STATUS): + print_status(); break; + #ifdef NKRO_ENABLE - case KC_N: - clear_keyboard(); //Prevents stuck keys. + + // NKRO toggle + case MAGIC_KC(MAGIC_KEY_NKRO): + clear_keyboard(); // clear to prevent stuck keys keyboard_nkro = !keyboard_nkro; if (keyboard_nkro) - print("NKRO: enabled\n"); + print("NKRO: on\n"); else - print("NKRO: disabled\n"); + print("NKRO: off\n"); break; #endif -#ifdef EXTRAKEY_ENABLE - case KC_PSCREEN: - // TODO: Power key should take this feature? otherwise any key during suspend. -#ifdef PROTOCOL_PJRC - if (suspend && remote_wakeup) { - usb_remote_wakeup(); - } else { - host_system_send(SYSTEM_POWER_DOWN); - host_system_send(0); - _delay_ms(500); - } -#else - host_system_send(SYSTEM_POWER_DOWN); - _delay_ms(100); - host_system_send(0); - _delay_ms(500); -#endif + + // switch layers + + case MAGIC_KC(MAGIC_KEY_LAYER0_ALT1): + case MAGIC_KC(MAGIC_KEY_LAYER0_ALT2): + switch_default_layer(0); + break; + +#if MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM + + case MAGIC_KC(MAGIC_KEY_LAYER0): + switch_default_layer(0); + break; + + case MAGIC_KC(MAGIC_KEY_LAYER1): + switch_default_layer(1); + break; + + case MAGIC_KC(MAGIC_KEY_LAYER2): + switch_default_layer(2); + break; + + case MAGIC_KC(MAGIC_KEY_LAYER3): + switch_default_layer(3); + break; + + case MAGIC_KC(MAGIC_KEY_LAYER4): + switch_default_layer(4); + break; + + case MAGIC_KC(MAGIC_KEY_LAYER5): + switch_default_layer(5); + break; + + case MAGIC_KC(MAGIC_KEY_LAYER6): + switch_default_layer(6); + break; + + case MAGIC_KC(MAGIC_KEY_LAYER7): + switch_default_layer(7); + break; + + case MAGIC_KC(MAGIC_KEY_LAYER8): + switch_default_layer(8); + break; + + case MAGIC_KC(MAGIC_KEY_LAYER9): + switch_default_layer(9); break; #endif - case KC_ESC: - case KC_GRV: - case KC_0: + + +#if MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS + + case KC_F1 ... KC_F9: + switch_default_layer((code - KC_F1) + 1); + break; + case KC_F10: switch_default_layer(0); break; +#endif + +#if MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS + case KC_1 ... KC_9: switch_default_layer((code - KC_1) + 1); break; - case KC_F1 ... KC_F12: - switch_default_layer((code - KC_F1) + 1); + case KC_0: + switch_default_layer(0); break; +#endif + default: print("?"); return false; @@ -382,11 +508,12 @@ static bool command_common(uint8_t code) ***********************************************************/ static void command_console_help(void) { - print("\n\n----- Console Help -----\n"); - print("ESC/q: quit\n"); + print("\n\t- Console -\n" + "ESC/q: quit\n" #ifdef MOUSEKEY_ENABLE - print("m: mousekey\n"); + "m: mousekey\n" #endif + ); } static bool command_console(uint8_t code) @@ -398,14 +525,12 @@ static bool command_console(uint8_t code) break; case KC_Q: case KC_ESC: - print("\nQuit Console Mode\n"); command_state = ONESHOT; return false; #ifdef MOUSEKEY_ENABLE case KC_M: mousekey_console_help(); - print("\nEnter Mousekey Console\n"); - print("M0>"); + print("M> "); command_state = MOUSEKEY; return true; #endif @@ -426,16 +551,17 @@ static uint8_t mousekey_param = 0; static void mousekey_param_print(void) { - print("\n\n----- Mousekey Parameters -----\n"); - print("1: mk_delay(*10ms): "); pdec(mk_delay); print("\n"); - print("2: mk_interval(ms): "); pdec(mk_interval); print("\n"); - print("3: mk_max_speed: "); pdec(mk_max_speed); print("\n"); - print("4: mk_time_to_max: "); pdec(mk_time_to_max); print("\n"); - print("5: mk_wheel_max_speed: "); pdec(mk_wheel_max_speed); print("\n"); - print("6: mk_wheel_time_to_max: "); pdec(mk_wheel_time_to_max); print("\n"); + print("\n\t- Values -\n"); + print("1: delay(*10ms): "); pdec(mk_delay); print("\n"); + print("2: interval(ms): "); pdec(mk_interval); print("\n"); + print("3: max_speed: "); pdec(mk_max_speed); print("\n"); + print("4: time_to_max: "); pdec(mk_time_to_max); print("\n"); + print("5: wheel_max_speed: "); pdec(mk_wheel_max_speed); print("\n"); + print("6: wheel_time_to_max: "); pdec(mk_wheel_time_to_max); print("\n"); } -#define PRINT_SET_VAL(v) print(#v " = "); print_dec(v); print("\n"); +//#define PRINT_SET_VAL(v) print(#v " = "); print_dec(v); print("\n"); +#define PRINT_SET_VAL(v) xprintf(#v " = %d\n", (v)) static void mousekey_param_inc(uint8_t param, uint8_t inc) { switch (param) { @@ -534,24 +660,25 @@ static void mousekey_param_dec(uint8_t param, uint8_t dec) static void mousekey_console_help(void) { - print("\n\n----- Mousekey Parameters Help -----\n"); - print("ESC/q: quit\n"); - print("1: select mk_delay(*10ms)\n"); - print("2: select mk_interval(ms)\n"); - print("3: select mk_max_speed\n"); - print("4: select mk_time_to_max\n"); - print("5: select mk_wheel_max_speed\n"); - print("6: select mk_wheel_time_to_max\n"); - print("p: print parameters\n"); - print("d: set default values\n"); - print("up: increase parameters(+1)\n"); - print("down: decrease parameters(-1)\n"); - print("pgup: increase parameters(+10)\n"); - print("pgdown: decrease parameters(-10)\n"); - print("\nspeed = delta * max_speed * (repeat / time_to_max)\n"); - print("where delta: cursor="); pdec(MOUSEKEY_MOVE_DELTA); - print(", wheel="); pdec(MOUSEKEY_WHEEL_DELTA); print("\n"); - print("See http://en.wikipedia.org/wiki/Mouse_keys\n"); + print("\n\t- Mousekey -\n" + "ESC/q: quit\n" + "1: delay(*10ms)\n" + "2: interval(ms)\n" + "3: max_speed\n" + "4: time_to_max\n" + "5: wheel_max_speed\n" + "6: wheel_time_to_max\n" + "\n" + "p: print values\n" + "d: set defaults\n" + "up: +1\n" + "down: -1\n" + "pgup: +10\n" + "pgdown: -10\n" + "\n" + "speed = delta * max_speed * (repeat / time_to_max)\n"); + xprintf("where delta: cursor=%d, wheel=%d\n" + "See http://en.wikipedia.org/wiki/Mouse_keys\n", MOUSEKEY_MOVE_DELTA, MOUSEKEY_WHEEL_DELTA); } static bool mousekey_console(uint8_t code) @@ -563,11 +690,14 @@ static bool mousekey_console(uint8_t code) break; case KC_Q: case KC_ESC: - mousekey_param = 0; - print("\nQuit Mousekey Console\n"); - print("C> "); - command_state = CONSOLE; - return false; + if (mousekey_param) { + mousekey_param = 0; + } else { + print("C> "); + command_state = CONSOLE; + return false; + } + break; case KC_P: mousekey_param_print(); break; @@ -577,12 +707,7 @@ static bool mousekey_console(uint8_t code) case KC_4: case KC_5: case KC_6: - case KC_7: - case KC_8: - case KC_9: - case KC_0: mousekey_param = numkey2num(code); - print("selected parameter: "); pdec(mousekey_param); print("\n"); break; case KC_UP: mousekey_param_inc(mousekey_param, 1); @@ -603,13 +728,16 @@ static bool mousekey_console(uint8_t code) mk_time_to_max = MOUSEKEY_TIME_TO_MAX; mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED; mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX; - print("set default values.\n"); + print("set default\n"); break; default: print("?"); return false; } - print("M"); pdec(mousekey_param); print("> "); + if (mousekey_param) + xprintf("M%d> ", mousekey_param); + else + print("M>" ); return true; } #endif @@ -637,8 +765,7 @@ static uint8_t numkey2num(uint8_t code) static void switch_default_layer(uint8_t layer) { - print("switch_default_layer: "); print_dec(biton32(default_layer_state)); - print(" to "); print_dec(layer); print("\n"); + xprintf("L%d\n", layer); default_layer_set(1UL<