diff options
| author | Liyang HU <github.com@liyang.hu> | 2021-08-07 08:12:57 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-07 17:12:57 +1000 |
| commit | 383fae55c5d53626eda210298f15fa6810510d5e (patch) | |
| tree | 001eabe3cab3ff3e45f06e64e260ec8c99f32312 /quantum | |
| parent | a03aa301def77c867ae6c6c840f7fc82b26d91d6 (diff) | |
| download | qmk_firmware-383fae55c5d53626eda210298f15fa6810510d5e.tar.gz qmk_firmware-383fae55c5d53626eda210298f15fa6810510d5e.zip | |
Refactor `quantum/command.{c,h}` for code size & {read,maintain}ability (#11842)
* quantum/command.c: coalesce `print()`s in `command_common_help()` & `print_version()`
Also undo some damage by clang-format in b624f32f94
* quantum/command.c: replace `print(…); print_{,val_}{dec,hex}*(…);` sequences with single `xprintf(…)`
`print_{dec,hex}*(…)` are just `#define`s for `xprintf(…)` anyway.
Each additional `xprintf(…)` costs ~8 bytes: the call instructions,
plus an additional NUL terminator.
This _really_ adds up: this commit saves 814 bytes on my ATmega32.
* quantum/command.c: optimise `mousekey_console()` for size & legibility
Made various tweaks to the interface, but still functionally identical.
Assume `KC_1`…`KC_0` to be contiguous, and removed `numkey2num(…)` entirely.
It was exported in `command.h` by 1a0bac8bcc for no obvious reason, before
which it was `static`. I doubt anyone uses it.
`mousekey_console()` is now enabled regardless of `MK_3_SPEED`.
Needs fleshing out for things other than the X11 variant though.
This commit saves 638 bytes on my ATmega32.
Diffstat (limited to 'quantum')
| -rw-r--r-- | quantum/command.c | 591 | ||||
| -rw-r--r-- | quantum/command.h | 3 |
2 files changed, 277 insertions, 317 deletions
diff --git a/quantum/command.c b/quantum/command.c index 3a7dc0f8c..2ff640a7b 100644 --- a/quantum/command.c +++ b/quantum/command.c | |||
| @@ -55,7 +55,6 @@ static bool command_console(uint8_t code); | |||
| 55 | static void command_console_help(void); | 55 | static void command_console_help(void); |
| 56 | #if defined(MOUSEKEY_ENABLE) && !defined(MK_3_SPEED) | 56 | #if defined(MOUSEKEY_ENABLE) && !defined(MK_3_SPEED) |
| 57 | static bool mousekey_console(uint8_t code); | 57 | static bool mousekey_console(uint8_t code); |
| 58 | static void mousekey_console_help(void); | ||
| 59 | #endif | 58 | #endif |
| 60 | 59 | ||
| 61 | static void switch_default_layer(uint8_t layer); | 60 | static void switch_default_layer(uint8_t layer); |
| @@ -103,190 +102,220 @@ bool command_console_extra(uint8_t code) { | |||
| 103 | /*********************************************************** | 102 | /*********************************************************** |
| 104 | * Command common | 103 | * Command common |
| 105 | ***********************************************************/ | 104 | ***********************************************************/ |
| 105 | |||
| 106 | static void command_common_help(void) { | 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" | 107 | print(/* clang-format off */ |
| 108 | "\n\t- Magic -\n" | ||
| 109 | |||
| 110 | STR(MAGIC_KEY_DEBUG) ": Debug Message Toggle\n" | ||
| 111 | STR(MAGIC_KEY_DEBUG_MATRIX) ": Matrix Debug Mode Toggle" | ||
| 112 | " - Show keypresses in matrix grid\n" | ||
| 113 | STR(MAGIC_KEY_DEBUG_KBD) ": Keyboard Debug Toggle" | ||
| 114 | " - Show keypress report\n" | ||
| 115 | STR(MAGIC_KEY_DEBUG_MOUSE) ": Debug Mouse Toggle\n" | ||
| 116 | STR(MAGIC_KEY_VERSION) ": Version\n" | ||
| 117 | STR(MAGIC_KEY_STATUS) ": Status\n" | ||
| 118 | STR(MAGIC_KEY_CONSOLE) ": Activate Console Mode\n" | ||
| 108 | 119 | ||
| 109 | #if MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM | 120 | #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" | 121 | STR(MAGIC_KEY_LAYER0) ": Switch to Layer 0\n" |
| 122 | STR(MAGIC_KEY_LAYER1) ": Switch to Layer 1\n" | ||
| 123 | STR(MAGIC_KEY_LAYER2) ": Switch to Layer 2\n" | ||
| 124 | STR(MAGIC_KEY_LAYER3) ": Switch to Layer 3\n" | ||
| 125 | STR(MAGIC_KEY_LAYER4) ": Switch to Layer 4\n" | ||
| 126 | STR(MAGIC_KEY_LAYER5) ": Switch to Layer 5\n" | ||
| 127 | STR(MAGIC_KEY_LAYER6) ": Switch to Layer 6\n" | ||
| 128 | STR(MAGIC_KEY_LAYER7) ": Switch to Layer 7\n" | ||
| 129 | STR(MAGIC_KEY_LAYER8) ": Switch to Layer 8\n" | ||
| 130 | STR(MAGIC_KEY_LAYER9) ": Switch to Layer 9\n" | ||
| 111 | #endif | 131 | #endif |
| 112 | 132 | ||
| 113 | #if MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS | 133 | #if MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS |
| 114 | "F1-F10: Switch to Layer 0-9 (F10 = L0)\n" | 134 | "F1-F10: Switch to Layer 0-9 (F10 = L0)\n" |
| 115 | #endif | 135 | #endif |
| 116 | 136 | ||
| 117 | #if MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS | 137 | #if MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS |
| 118 | "0-9: Switch to Layer 0-9\n" | 138 | "0-9: Switch to Layer 0-9\n" |
| 119 | #endif | 139 | #endif |
| 120 | 140 | ||
| 121 | STR(MAGIC_KEY_LAYER0_ALT) ": Switch to Layer 0 (alternate)\n" | 141 | STR(MAGIC_KEY_LAYER0_ALT) ": Switch to Layer 0 (alternate)\n" |
| 122 | 142 | ||
| 123 | STR(MAGIC_KEY_BOOTLOADER) ": Jump to Bootloader\n" STR(MAGIC_KEY_BOOTLOADER_ALT) ": Jump to Bootloader (alternate)\n" | 143 | STR(MAGIC_KEY_BOOTLOADER) ": Jump to Bootloader\n" |
| 144 | STR(MAGIC_KEY_BOOTLOADER_ALT) ": Jump to Bootloader (alternate)\n" | ||
| 124 | 145 | ||
| 125 | #ifdef KEYBOARD_LOCK_ENABLE | 146 | #ifdef KEYBOARD_LOCK_ENABLE |
| 126 | STR(MAGIC_KEY_LOCK) ": Lock Keyboard\n" | 147 | STR(MAGIC_KEY_LOCK) ": Lock Keyboard\n" |
| 127 | #endif | 148 | #endif |
| 128 | 149 | ||
| 129 | STR(MAGIC_KEY_EEPROM) ": Print EEPROM Settings\n" STR(MAGIC_KEY_EEPROM_CLEAR) ": Clear EEPROM\n" | 150 | STR(MAGIC_KEY_EEPROM) ": Print EEPROM Settings\n" |
| 151 | STR(MAGIC_KEY_EEPROM_CLEAR) ": Clear EEPROM\n" | ||
| 130 | 152 | ||
| 131 | #ifdef NKRO_ENABLE | 153 | #ifdef NKRO_ENABLE |
| 132 | STR(MAGIC_KEY_NKRO) ": NKRO Toggle\n" | 154 | STR(MAGIC_KEY_NKRO) ": NKRO Toggle\n" |
| 133 | #endif | 155 | #endif |
| 134 | 156 | ||
| 135 | #ifdef SLEEP_LED_ENABLE | 157 | #ifdef SLEEP_LED_ENABLE |
| 136 | STR(MAGIC_KEY_SLEEP_LED) ": Sleep LED Test\n" | 158 | STR(MAGIC_KEY_SLEEP_LED) ": Sleep LED Test\n" |
| 137 | #endif | 159 | #endif |
| 138 | ); | 160 | ); /* clang-format on */ |
| 139 | } | 161 | } |
| 140 | 162 | ||
| 141 | static void print_version(void) { | 163 | static void print_version(void) { |
| 142 | // print version & information | 164 | print(/* clang-format off */ |
| 143 | print("\n\t- Version -\n"); | 165 | "\n\t- Version -\n" |
| 144 | print("VID: " STR(VENDOR_ID) "(" STR(MANUFACTURER) ") " | 166 | "VID: " STR(VENDOR_ID) "(" STR(MANUFACTURER) ") " |
| 145 | "PID: " STR(PRODUCT_ID) "(" STR(PRODUCT) ") " | 167 | "PID: " STR(PRODUCT_ID) "(" STR(PRODUCT) ") " |
| 146 | "VER: " STR(DEVICE_VER) "\n"); | 168 | "VER: " STR(DEVICE_VER) "\n" |
| 147 | print("BUILD: (" __DATE__ ")\n"); | 169 | "BUILD: (" __DATE__ ")\n" |
| 148 | #ifndef SKIP_VERSION | 170 | #ifndef SKIP_VERSION |
| 149 | # ifdef PROTOCOL_CHIBIOS | 171 | # ifdef PROTOCOL_CHIBIOS |
| 150 | print("CHIBIOS: " STR(CHIBIOS_VERSION) ", CONTRIB: " STR(CHIBIOS_CONTRIB_VERSION) "\n"); | 172 | "CHIBIOS: " STR(CHIBIOS_VERSION) |
| 173 | ", CONTRIB: " STR(CHIBIOS_CONTRIB_VERSION) "\n" | ||
| 151 | # endif | 174 | # endif |
| 152 | #endif | 175 | #endif |
| 153 | 176 | ||
| 154 | /* build options */ | 177 | /* build options */ |
| 155 | print("OPTIONS:" | 178 | "OPTIONS:" |
| 156 | 179 | ||
| 157 | #ifdef PROTOCOL_LUFA | 180 | #ifdef PROTOCOL_LUFA |
| 158 | " LUFA" | 181 | " LUFA" |
| 159 | #endif | 182 | #endif |
| 160 | #ifdef PROTOCOL_VUSB | 183 | #ifdef PROTOCOL_VUSB |
| 161 | " VUSB" | 184 | " VUSB" |
| 162 | #endif | 185 | #endif |
| 163 | #ifdef BOOTMAGIC_ENABLE | 186 | #ifdef BOOTMAGIC_ENABLE |
| 164 | " BOOTMAGIC" | 187 | " BOOTMAGIC" |
| 165 | #endif | 188 | #endif |
| 166 | #ifdef MOUSEKEY_ENABLE | 189 | #ifdef MOUSEKEY_ENABLE |
| 167 | " MOUSEKEY" | 190 | " MOUSEKEY" |
| 168 | #endif | 191 | #endif |
| 169 | #ifdef EXTRAKEY_ENABLE | 192 | #ifdef EXTRAKEY_ENABLE |
| 170 | " EXTRAKEY" | 193 | " EXTRAKEY" |
| 171 | #endif | 194 | #endif |
| 172 | #ifdef CONSOLE_ENABLE | 195 | #ifdef CONSOLE_ENABLE |
| 173 | " CONSOLE" | 196 | " CONSOLE" |
| 174 | #endif | 197 | #endif |
| 175 | #ifdef COMMAND_ENABLE | 198 | #ifdef COMMAND_ENABLE |
| 176 | " COMMAND" | 199 | " COMMAND" |
| 177 | #endif | 200 | #endif |
| 178 | #ifdef NKRO_ENABLE | 201 | #ifdef NKRO_ENABLE |
| 179 | " NKRO" | 202 | " NKRO" |
| 180 | #endif | 203 | #endif |
| 181 | #ifdef LTO_ENABLE | 204 | #ifdef LTO_ENABLE |
| 182 | " LTO" | 205 | " LTO" |
| 183 | #endif | 206 | #endif |
| 184 | 207 | ||
| 185 | " " STR(BOOTLOADER_SIZE) "\n"); | 208 | " " STR(BOOTLOADER_SIZE) "\n" |
| 186 | 209 | ||
| 187 | print("GCC: " STR(__GNUC__) "." STR(__GNUC_MINOR__) "." STR(__GNUC_PATCHLEVEL__) | 210 | "GCC: " STR(__GNUC__) |
| 211 | "." STR(__GNUC_MINOR__) | ||
| 212 | "." STR(__GNUC_PATCHLEVEL__) | ||
| 188 | #if defined(__AVR__) | 213 | #if defined(__AVR__) |
| 189 | " AVR-LIBC: " __AVR_LIBC_VERSION_STRING__ " AVR_ARCH: avr" STR(__AVR_ARCH__) | 214 | " AVR-LIBC: " __AVR_LIBC_VERSION_STRING__ |
| 215 | " AVR_ARCH: avr" STR(__AVR_ARCH__) | ||
| 190 | #endif | 216 | #endif |
| 191 | "\n"); | 217 | "\n" |
| 192 | 218 | ); /* clang-format on */ | |
| 193 | return; | ||
| 194 | } | 219 | } |
| 195 | 220 | ||
| 196 | static void print_status(void) { | 221 | static void print_status(void) { |
| 197 | print("\n\t- Status -\n"); | 222 | xprintf(/* clang-format off */ |
| 223 | "\n\t- Status -\n" | ||
| 224 | |||
| 225 | "host_keyboard_leds(): %02X\n" | ||
| 226 | #ifndef PROTOCOL_VUSB | ||
| 227 | "keyboard_protocol: %02X\n" | ||
| 228 | "keyboard_idle: %02X\n" | ||
| 229 | #endif | ||
| 230 | #ifdef NKRO_ENABLE | ||
| 231 | "keymap_config.nkro: %02X\n" | ||
| 232 | #endif | ||
| 233 | "timer_read32(): %08lX\n" | ||
| 198 | 234 | ||
| 199 | print_val_hex8(host_keyboard_leds()); | 235 | , host_keyboard_leds() |
| 200 | #ifndef PROTOCOL_VUSB | 236 | #ifndef PROTOCOL_VUSB |
| 201 | // these aren't set on the V-USB protocol, so we just ignore them for now | 237 | /* these aren't set on the V-USB protocol, so we just ignore them for now */ |
| 202 | print_val_hex8(keyboard_protocol); | 238 | , keyboard_protocol |
| 203 | print_val_hex8(keyboard_idle); | 239 | , keyboard_idle |
| 204 | #endif | 240 | #endif |
| 205 | #ifdef NKRO_ENABLE | 241 | #ifdef NKRO_ENABLE |
| 206 | print_val_hex8(keymap_config.nkro); | 242 | , keymap_config.nkro |
| 207 | #endif | 243 | #endif |
| 208 | print_val_hex32(timer_read32()); | 244 | , timer_read32() |
| 209 | return; | 245 | |
| 246 | ); /* clang-format on */ | ||
| 210 | } | 247 | } |
| 211 | 248 | ||
| 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) | 249 | #if !defined(NO_PRINT) && !defined(USER_PRINT) |
| 215 | 250 | static void print_eeconfig(void) { | |
| 216 | print("default_layer: "); | 251 | xprintf("eeconfig:\ndefault_layer: %u\n", eeconfig_read_default_layer()); |
| 217 | print_dec(eeconfig_read_default_layer()); | ||
| 218 | print("\n"); | ||
| 219 | 252 | ||
| 220 | debug_config_t dc; | 253 | debug_config_t dc; |
| 221 | dc.raw = eeconfig_read_debug(); | 254 | dc.raw = eeconfig_read_debug(); |
| 222 | print("debug_config.raw: "); | 255 | xprintf(/* clang-format off */ |
| 223 | print_hex8(dc.raw); | 256 | |
| 224 | print("\n"); | 257 | "debug_config.raw: %02X\n" |
| 225 | print(".enable: "); | 258 | ".enable: %u\n" |
| 226 | print_dec(dc.enable); | 259 | ".matrix: %u\n" |
| 227 | print("\n"); | 260 | ".keyboard: %u\n" |
| 228 | print(".matrix: "); | 261 | ".mouse: %u\n" |
| 229 | print_dec(dc.matrix); | 262 | |
| 230 | print("\n"); | 263 | , dc.raw |
| 231 | print(".keyboard: "); | 264 | , dc.enable |
| 232 | print_dec(dc.keyboard); | 265 | , dc.matrix |
| 233 | print("\n"); | 266 | , dc.keyboard |
| 234 | print(".mouse: "); | 267 | , dc.mouse |
| 235 | print_dec(dc.mouse); | 268 | ); /* clang-format on */ |
| 236 | print("\n"); | ||
| 237 | 269 | ||
| 238 | keymap_config_t kc; | 270 | keymap_config_t kc; |
| 239 | kc.raw = eeconfig_read_keymap(); | 271 | kc.raw = eeconfig_read_keymap(); |
| 240 | print("keymap_config.raw: "); | 272 | xprintf(/* clang-format off */ |
| 241 | print_hex8(kc.raw); | 273 | |
| 242 | print("\n"); | 274 | "keymap_config.raw: %02X\n" |
| 243 | print(".swap_control_capslock: "); | 275 | ".swap_control_capslock: %u\n" |
| 244 | print_dec(kc.swap_control_capslock); | 276 | ".capslock_to_control: %u\n" |
| 245 | print("\n"); | 277 | ".swap_lctl_lgui: %u\n" |
| 246 | print(".capslock_to_control: "); | 278 | ".swap_rctl_rgui: %u\n" |
| 247 | print_dec(kc.capslock_to_control); | 279 | ".swap_lalt_lgui: %u\n" |
| 248 | print("\n"); | 280 | ".swap_ralt_rgui: %u\n" |
| 249 | print(".swap_lctl_lgui: "); | 281 | ".no_gui: %u\n" |
| 250 | print_dec(kc.swap_lctl_lgui); | 282 | ".swap_grave_esc: %u\n" |
| 251 | print("\n"); | 283 | ".swap_backslash_backspace: %u\n" |
| 252 | print(".swap_rctl_rgui: "); | 284 | ".nkro: %u\n" |
| 253 | print_dec(kc.swap_rctl_rgui); | 285 | |
| 254 | print("\n"); | 286 | , kc.raw |
| 255 | print(".swap_lalt_lgui: "); | 287 | , kc.swap_control_capslock |
| 256 | print_dec(kc.swap_lalt_lgui); | 288 | , kc.capslock_to_control |
| 257 | print("\n"); | 289 | , kc.swap_lctl_lgui |
| 258 | print(".swap_ralt_rgui: "); | 290 | , kc.swap_rctl_rgui |
| 259 | print_dec(kc.swap_ralt_rgui); | 291 | , kc.swap_lalt_lgui |
| 260 | print("\n"); | 292 | , kc.swap_ralt_rgui |
| 261 | print(".no_gui: "); | 293 | , kc.no_gui |
| 262 | print_dec(kc.no_gui); | 294 | , kc.swap_grave_esc |
| 263 | print("\n"); | 295 | , kc.swap_backslash_backspace |
| 264 | print(".swap_grave_esc: "); | 296 | , kc.nkro |
| 265 | print_dec(kc.swap_grave_esc); | 297 | ); /* clang-format on */ |
| 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 | 298 | ||
| 274 | # ifdef BACKLIGHT_ENABLE | 299 | # ifdef BACKLIGHT_ENABLE |
| 300 | |||
| 275 | backlight_config_t bc; | 301 | backlight_config_t bc; |
| 276 | bc.raw = eeconfig_read_backlight(); | 302 | bc.raw = eeconfig_read_backlight(); |
| 277 | print("backlight_config.raw: "); | 303 | xprintf(/* clang-format off */ |
| 278 | print_hex8(bc.raw); | 304 | "backlight_config" |
| 279 | print("\n"); | 305 | |
| 280 | print(".enable: "); | 306 | ".raw: %02X\n" |
| 281 | print_dec(bc.enable); | 307 | ".enable: %u\n" |
| 282 | print("\n"); | 308 | ".level: %u\n" |
| 283 | print(".level: "); | 309 | |
| 284 | print_dec(bc.level); | 310 | , bc.raw |
| 285 | print("\n"); | 311 | , bc.enable |
| 286 | # endif /* BACKLIGHT_ENABLE */ | 312 | , bc.level |
| 287 | 313 | ||
| 288 | #endif /* !NO_PRINT */ | 314 | ); /* clang-format on */ |
| 315 | |||
| 316 | # endif /* BACKLIGHT_ENABLE */ | ||
| 289 | } | 317 | } |
| 318 | #endif /* !NO_PRINT && !USER_PRINT */ | ||
| 290 | 319 | ||
| 291 | static bool command_common(uint8_t code) { | 320 | static bool command_common(uint8_t code) { |
| 292 | #ifdef KEYBOARD_LOCK_ENABLE | 321 | #ifdef KEYBOARD_LOCK_ENABLE |
| @@ -306,8 +335,9 @@ static bool command_common(uint8_t code) { | |||
| 306 | 335 | ||
| 307 | // print stored eeprom config | 336 | // print stored eeprom config |
| 308 | case MAGIC_KC(MAGIC_KEY_EEPROM): | 337 | case MAGIC_KC(MAGIC_KEY_EEPROM): |
| 309 | print("eeconfig:\n"); | 338 | #if !defined(NO_PRINT) && !defined(USER_PRINT) |
| 310 | print_eeconfig(); | 339 | print_eeconfig(); |
| 340 | #endif /* !NO_PRINT && !USER_PRINT */ | ||
| 311 | break; | 341 | break; |
| 312 | 342 | ||
| 313 | // clear eeprom | 343 | // clear eeprom |
| @@ -519,265 +549,196 @@ static bool command_console(uint8_t code) { | |||
| 519 | case KC_H: | 549 | case KC_H: |
| 520 | case KC_SLASH: /* ? */ | 550 | case KC_SLASH: /* ? */ |
| 521 | command_console_help(); | 551 | command_console_help(); |
| 522 | break; | 552 | print("C> "); |
| 553 | return true; | ||
| 523 | case KC_Q: | 554 | case KC_Q: |
| 524 | case KC_ESC: | 555 | case KC_ESC: |
| 525 | command_state = ONESHOT; | 556 | command_state = ONESHOT; |
| 526 | return false; | 557 | return false; |
| 527 | #if defined(MOUSEKEY_ENABLE) && !defined(MK_3_SPEED) | 558 | #if defined(MOUSEKEY_ENABLE) |
| 528 | case KC_M: | 559 | case KC_M: |
| 529 | mousekey_console_help(); | ||
| 530 | print("M> "); | ||
| 531 | command_state = MOUSEKEY; | 560 | command_state = MOUSEKEY; |
| 561 | mousekey_console(KC_SLASH /* ? */); | ||
| 532 | return true; | 562 | return true; |
| 533 | #endif | 563 | #endif |
| 534 | default: | 564 | default: |
| 535 | print("?"); | 565 | print("?"); |
| 536 | return false; | 566 | return false; |
| 537 | } | 567 | } |
| 538 | print("C> "); | ||
| 539 | return true; | ||
| 540 | } | 568 | } |
| 541 | 569 | ||
| 542 | #if defined(MOUSEKEY_ENABLE) && !defined(MK_3_SPEED) | ||
| 543 | /*********************************************************** | 570 | /*********************************************************** |
| 544 | * Mousekey console | 571 | * Mousekey console |
| 545 | ***********************************************************/ | 572 | ***********************************************************/ |
| 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 | print_dec(mk_delay); | ||
| 554 | print("\n"); | ||
| 555 | print("2: interval(ms): "); | ||
| 556 | print_dec(mk_interval); | ||
| 557 | print("\n"); | ||
| 558 | print("3: max_speed: "); | ||
| 559 | print_dec(mk_max_speed); | ||
| 560 | print("\n"); | ||
| 561 | print("4: time_to_max: "); | ||
| 562 | print_dec(mk_time_to_max); | ||
| 563 | print("\n"); | ||
| 564 | print("5: wheel_max_speed: "); | ||
| 565 | print_dec(mk_wheel_max_speed); | ||
| 566 | print("\n"); | ||
| 567 | print("6: wheel_time_to_max: "); | ||
| 568 | print_dec(mk_wheel_time_to_max); | ||
| 569 | print("\n"); | ||
| 570 | # endif /* !NO_PRINT */ | ||
| 571 | } | ||
| 572 | 573 | ||
| 573 | //#define PRINT_SET_VAL(v) print(#v " = "); print_dec(v); print("\n"); | 574 | #if defined(MOUSEKEY_ENABLE) |
| 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 | 575 | ||
| 622 | static void mousekey_param_dec(uint8_t param, uint8_t dec) { | 576 | # if !defined(NO_PRINT) && !defined(USER_PRINT) |
| 623 | switch (param) { | 577 | static void mousekey_param_print(void) { |
| 624 | case 1: | 578 | xprintf(/* clang-format off */ |
| 625 | if (mk_delay > dec) | 579 | |
| 626 | mk_delay -= dec; | 580 | #ifndef MK_3_SPEED |
| 627 | else | 581 | "1: delay(*10ms): %u\n" |
| 628 | mk_delay = 0; | 582 | "2: interval(ms): %u\n" |
| 629 | PRINT_SET_VAL(mk_delay); | 583 | "3: max_speed: %u\n" |
| 630 | break; | 584 | "4: time_to_max: %u\n" |
| 631 | case 2: | 585 | "5: wheel_max_speed: %u\n" |
| 632 | if (mk_interval > dec) | 586 | "6: wheel_time_to_max: %u\n" |
| 633 | mk_interval -= dec; | 587 | |
| 634 | else | 588 | , mk_delay |
| 635 | mk_interval = 0; | 589 | , mk_interval |
| 636 | PRINT_SET_VAL(mk_interval); | 590 | , mk_max_speed |
| 637 | break; | 591 | , mk_time_to_max |
| 638 | case 3: | 592 | , mk_wheel_max_speed |
| 639 | if (mk_max_speed > dec) | 593 | , mk_wheel_time_to_max |
| 640 | mk_max_speed -= dec; | 594 | #else |
| 641 | else | 595 | "no knobs sorry\n" |
| 642 | mk_max_speed = 0; | 596 | #endif |
| 643 | PRINT_SET_VAL(mk_max_speed); | 597 | |
| 644 | break; | 598 | ); /* clang-format on */ |
| 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 | } | 599 | } |
| 600 | # endif /* !NO_PRINT && !USER_PRINT */ | ||
| 668 | 601 | ||
| 602 | # if !defined(NO_PRINT) && !defined(USER_PRINT) | ||
| 669 | static void mousekey_console_help(void) { | 603 | static void mousekey_console_help(void) { |
| 670 | print("\n\t- Mousekey -\n" | 604 | mousekey_param_print(); |
| 671 | "ESC/q: quit\n" | 605 | xprintf(/* clang-format off */ |
| 672 | "1: delay(*10ms)\n" | 606 | "p: print values\n" |
| 673 | "2: interval(ms)\n" | 607 | "d: set defaults\n" |
| 674 | "3: max_speed\n" | 608 | "up: +1\n" |
| 675 | "4: time_to_max\n" | 609 | "dn: -1\n" |
| 676 | "5: wheel_max_speed\n" | 610 | "lt: +10\n" |
| 677 | "6: wheel_time_to_max\n" | 611 | "rt: -10\n" |
| 678 | "\n" | 612 | "ESC/q: quit\n" |
| 679 | "p: print values\n" | 613 | |
| 680 | "d: set defaults\n" | 614 | #ifndef MK_3_SPEED |
| 681 | "up: +1\n" | 615 | "\n" |
| 682 | "down: -1\n" | 616 | "speed = delta * max_speed * (repeat / time_to_max)\n" |
| 683 | "pgup: +10\n" | 617 | "where delta: cursor=%d, wheel=%d\n" |
| 684 | "pgdown: -10\n" | 618 | "See http://en.wikipedia.org/wiki/Mouse_keys\n" |
| 685 | "\n" | 619 | , MOUSEKEY_MOVE_DELTA, MOUSEKEY_WHEEL_DELTA |
| 686 | "speed = delta * max_speed * (repeat / time_to_max)\n"); | 620 | #endif |
| 687 | xprintf("where delta: cursor=%d, wheel=%d\n" | 621 | |
| 688 | "See http://en.wikipedia.org/wiki/Mouse_keys\n", | 622 | ); /* clang-format on */ |
| 689 | MOUSEKEY_MOVE_DELTA, MOUSEKEY_WHEEL_DELTA); | ||
| 690 | } | 623 | } |
| 624 | # endif /* !NO_PRINT && !USER_PRINT */ | ||
| 625 | |||
| 626 | /* Only used by `quantum/command.c` / `command_proc()`. To avoid | ||
| 627 | * any doubt: we return `false` to return to the main console, | ||
| 628 | * which differs from the `bool` that `command_proc()` returns. */ | ||
| 629 | bool mousekey_console(uint8_t code) { | ||
| 630 | static uint8_t param = 0; | ||
| 631 | static uint8_t *pp = NULL; | ||
| 632 | static char * desc = NULL; | ||
| 633 | |||
| 634 | # if defined(NO_PRINT) || defined(USER_PRINT) /* -Wunused-parameter */ | ||
| 635 | (void)desc; | ||
| 636 | # endif | ||
| 637 | |||
| 638 | int8_t change = 0; | ||
| 691 | 639 | ||
| 692 | static bool mousekey_console(uint8_t code) { | ||
| 693 | switch (code) { | 640 | switch (code) { |
| 694 | case KC_H: | 641 | case KC_H: |
| 695 | case KC_SLASH: /* ? */ | 642 | case KC_SLASH: /* ? */ |
| 643 | # if !defined(NO_PRINT) && !defined(USER_PRINT) | ||
| 644 | print("\n\t- Mousekey -\n"); | ||
| 696 | mousekey_console_help(); | 645 | mousekey_console_help(); |
| 646 | # endif | ||
| 697 | break; | 647 | break; |
| 648 | |||
| 698 | case KC_Q: | 649 | case KC_Q: |
| 699 | case KC_ESC: | 650 | case KC_ESC: |
| 700 | if (mousekey_param) { | 651 | print("q\n"); |
| 701 | mousekey_param = 0; | 652 | if (!param) return false; |
| 702 | } else { | 653 | param = 0; |
| 703 | print("C> "); | 654 | pp = NULL; |
| 704 | command_state = CONSOLE; | 655 | desc = NULL; |
| 705 | return false; | ||
| 706 | } | ||
| 707 | break; | 656 | break; |
| 657 | |||
| 708 | case KC_P: | 658 | case KC_P: |
| 659 | # if !defined(NO_PRINT) && !defined(USER_PRINT) | ||
| 660 | print("\n\t- Values -\n"); | ||
| 709 | mousekey_param_print(); | 661 | mousekey_param_print(); |
| 662 | # endif | ||
| 710 | break; | 663 | break; |
| 711 | case KC_1: | 664 | |
| 712 | case KC_2: | 665 | case KC_1 ... KC_0: /* KC_0 gives param = 10 */ |
| 713 | case KC_3: | 666 | param = 1 + code - KC_1; |
| 714 | case KC_4: | 667 | switch (param) { /* clang-format off */ |
| 715 | case KC_5: | 668 | # define PARAM(n, v) case n: pp = &(v); desc = #v; break |
| 716 | case KC_6: | 669 | |
| 717 | mousekey_param = numkey2num(code); | 670 | #ifndef MK_3_SPEED |
| 718 | break; | 671 | PARAM(1, mk_delay); |
| 719 | case KC_UP: | 672 | PARAM(2, mk_interval); |
| 720 | mousekey_param_inc(mousekey_param, 1); | 673 | PARAM(3, mk_max_speed); |
| 721 | break; | 674 | PARAM(4, mk_time_to_max); |
| 722 | case KC_DOWN: | 675 | PARAM(5, mk_wheel_max_speed); |
| 723 | mousekey_param_dec(mousekey_param, 1); | 676 | PARAM(6, mk_wheel_time_to_max); |
| 724 | break; | 677 | #endif /* MK_3_SPEED */ |
| 725 | case KC_PGUP: | 678 | |
| 726 | mousekey_param_inc(mousekey_param, 10); | 679 | # undef PARAM |
| 727 | break; | 680 | default: |
| 728 | case KC_PGDN: | 681 | param = 0; |
| 729 | mousekey_param_dec(mousekey_param, 10); | 682 | print("?\n"); |
| 730 | break; | 683 | break; |
| 684 | } /* clang-format on */ | ||
| 685 | if (param) xprintf("%u\n", param); | ||
| 686 | break; | ||
| 687 | |||
| 688 | /* clang-format off */ | ||
| 689 | case KC_UP: change = +1; break; | ||
| 690 | case KC_DOWN: change = -1; break; | ||
| 691 | case KC_LEFT: change = -10; break; | ||
| 692 | case KC_RIGHT: change = +10; break; | ||
| 693 | /* clang-format on */ | ||
| 694 | |||
| 731 | case KC_D: | 695 | case KC_D: |
| 696 | |||
| 697 | # ifndef MK_3_SPEED | ||
| 732 | mk_delay = MOUSEKEY_DELAY / 10; | 698 | mk_delay = MOUSEKEY_DELAY / 10; |
| 733 | mk_interval = MOUSEKEY_INTERVAL; | 699 | mk_interval = MOUSEKEY_INTERVAL; |
| 734 | mk_max_speed = MOUSEKEY_MAX_SPEED; | 700 | mk_max_speed = MOUSEKEY_MAX_SPEED; |
| 735 | mk_time_to_max = MOUSEKEY_TIME_TO_MAX; | 701 | mk_time_to_max = MOUSEKEY_TIME_TO_MAX; |
| 736 | mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED; | 702 | mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED; |
| 737 | mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX; | 703 | mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX; |
| 738 | print("set default\n"); | 704 | # endif /* MK_3_SPEED */ |
| 705 | |||
| 706 | print("defaults\n"); | ||
| 739 | break; | 707 | break; |
| 708 | |||
| 740 | default: | 709 | default: |
| 741 | print("?"); | 710 | print("?\n"); |
| 742 | return false; | 711 | break; |
| 712 | } | ||
| 713 | |||
| 714 | if (change) { | ||
| 715 | if (pp) { | ||
| 716 | int16_t val = *pp + change; | ||
| 717 | if (val > (int16_t)UINT8_MAX) | ||
| 718 | *pp = UINT8_MAX; | ||
| 719 | else if (val < 0) | ||
| 720 | *pp = 0; | ||
| 721 | else | ||
| 722 | *pp = (uint8_t)val; | ||
| 723 | xprintf("= %u\n", *pp); | ||
| 724 | } else { | ||
| 725 | print("?\n"); | ||
| 726 | } | ||
| 743 | } | 727 | } |
| 744 | if (mousekey_param) { | 728 | |
| 745 | xprintf("M%d> ", mousekey_param); | 729 | if (param) { |
| 730 | xprintf("M%u:%s> ", param, desc ? desc : "???"); | ||
| 746 | } else { | 731 | } else { |
| 747 | print("M>"); | 732 | print("M> "); |
| 748 | } | 733 | } |
| 749 | return true; | 734 | return true; |
| 750 | } | 735 | } |
| 751 | #endif | 736 | |
| 737 | #endif /* MOUSEKEY_ENABLE */ | ||
| 752 | 738 | ||
| 753 | /*********************************************************** | 739 | /*********************************************************** |
| 754 | * Utilities | 740 | * Utilities |
| 755 | ***********************************************************/ | 741 | ***********************************************************/ |
| 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 | 742 | ||
| 782 | static void switch_default_layer(uint8_t layer) { | 743 | static void switch_default_layer(uint8_t layer) { |
| 783 | xprintf("L%d\n", layer); | 744 | xprintf("L%d\n", layer); |
diff --git a/quantum/command.h b/quantum/command.h index 4f77be085..676507d3b 100644 --- a/quantum/command.h +++ b/quantum/command.h | |||
| @@ -28,8 +28,7 @@ bool command_extra(uint8_t code); | |||
| 28 | bool command_console_extra(uint8_t code); | 28 | bool command_console_extra(uint8_t code); |
| 29 | 29 | ||
| 30 | #ifdef COMMAND_ENABLE | 30 | #ifdef COMMAND_ENABLE |
| 31 | uint8_t numkey2num(uint8_t code); | 31 | bool command_proc(uint8_t code); |
| 32 | bool command_proc(uint8_t code); | ||
| 33 | #else | 32 | #else |
| 34 | # define command_proc(code) false | 33 | # define command_proc(code) false |
| 35 | #endif | 34 | #endif |
