1
0
Fork 0

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.
This commit is contained in:
Liyang HU 2021-08-07 08:12:57 +01:00 committed by GitHub
parent a03aa301de
commit 383fae55c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 276 additions and 316 deletions

View file

@ -55,7 +55,6 @@ static bool command_console(uint8_t code);
static void command_console_help(void); static void command_console_help(void);
#if defined(MOUSEKEY_ENABLE) && !defined(MK_3_SPEED) #if defined(MOUSEKEY_ENABLE) && !defined(MK_3_SPEED)
static bool mousekey_console(uint8_t code); static bool mousekey_console(uint8_t code);
static void mousekey_console_help(void);
#endif #endif
static void switch_default_layer(uint8_t layer); static void switch_default_layer(uint8_t layer);
@ -103,11 +102,32 @@ bool command_console_extra(uint8_t code) {
/*********************************************************** /***********************************************************
* Command common * Command common
***********************************************************/ ***********************************************************/
static void command_common_help(void) { static void command_common_help(void) {
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" print(/* clang-format off */
"\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 #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" 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 #endif
#if MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS #if MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS
@ -120,13 +140,15 @@ static void command_common_help(void) {
STR(MAGIC_KEY_LAYER0_ALT) ": Switch to Layer 0 (alternate)\n" STR(MAGIC_KEY_LAYER0_ALT) ": Switch to Layer 0 (alternate)\n"
STR(MAGIC_KEY_BOOTLOADER) ": Jump to Bootloader\n" STR(MAGIC_KEY_BOOTLOADER_ALT) ": Jump to Bootloader (alternate)\n" STR(MAGIC_KEY_BOOTLOADER) ": Jump to Bootloader\n"
STR(MAGIC_KEY_BOOTLOADER_ALT) ": Jump to Bootloader (alternate)\n"
#ifdef KEYBOARD_LOCK_ENABLE #ifdef KEYBOARD_LOCK_ENABLE
STR(MAGIC_KEY_LOCK) ": Lock Keyboard\n" STR(MAGIC_KEY_LOCK) ": Lock Keyboard\n"
#endif #endif
STR(MAGIC_KEY_EEPROM) ": Print EEPROM Settings\n" STR(MAGIC_KEY_EEPROM_CLEAR) ": Clear EEPROM\n" STR(MAGIC_KEY_EEPROM) ": Print EEPROM Settings\n"
STR(MAGIC_KEY_EEPROM_CLEAR) ": Clear EEPROM\n"
#ifdef NKRO_ENABLE #ifdef NKRO_ENABLE
STR(MAGIC_KEY_NKRO) ": NKRO Toggle\n" STR(MAGIC_KEY_NKRO) ": NKRO Toggle\n"
@ -135,24 +157,25 @@ static void command_common_help(void) {
#ifdef SLEEP_LED_ENABLE #ifdef SLEEP_LED_ENABLE
STR(MAGIC_KEY_SLEEP_LED) ": Sleep LED Test\n" STR(MAGIC_KEY_SLEEP_LED) ": Sleep LED Test\n"
#endif #endif
); ); /* clang-format on */
} }
static void print_version(void) { static void print_version(void) {
// print version & information print(/* clang-format off */
print("\n\t- Version -\n"); "\n\t- Version -\n"
print("VID: " STR(VENDOR_ID) "(" STR(MANUFACTURER) ") " "VID: " STR(VENDOR_ID) "(" STR(MANUFACTURER) ") "
"PID: " STR(PRODUCT_ID) "(" STR(PRODUCT) ") " "PID: " STR(PRODUCT_ID) "(" STR(PRODUCT) ") "
"VER: " STR(DEVICE_VER) "\n"); "VER: " STR(DEVICE_VER) "\n"
print("BUILD: (" __DATE__ ")\n"); "BUILD: (" __DATE__ ")\n"
#ifndef SKIP_VERSION #ifndef SKIP_VERSION
# ifdef PROTOCOL_CHIBIOS # ifdef PROTOCOL_CHIBIOS
print("CHIBIOS: " STR(CHIBIOS_VERSION) ", CONTRIB: " STR(CHIBIOS_CONTRIB_VERSION) "\n"); "CHIBIOS: " STR(CHIBIOS_VERSION)
", CONTRIB: " STR(CHIBIOS_CONTRIB_VERSION) "\n"
# endif # endif
#endif #endif
/* build options */ /* build options */
print("OPTIONS:" "OPTIONS:"
#ifdef PROTOCOL_LUFA #ifdef PROTOCOL_LUFA
" LUFA" " LUFA"
@ -182,111 +205,117 @@ static void print_version(void) {
" LTO" " LTO"
#endif #endif
" " STR(BOOTLOADER_SIZE) "\n"); " " STR(BOOTLOADER_SIZE) "\n"
print("GCC: " STR(__GNUC__) "." STR(__GNUC_MINOR__) "." STR(__GNUC_PATCHLEVEL__) "GCC: " STR(__GNUC__)
"." STR(__GNUC_MINOR__)
"." STR(__GNUC_PATCHLEVEL__)
#if defined(__AVR__) #if defined(__AVR__)
" AVR-LIBC: " __AVR_LIBC_VERSION_STRING__ " AVR_ARCH: avr" STR(__AVR_ARCH__) " AVR-LIBC: " __AVR_LIBC_VERSION_STRING__
" AVR_ARCH: avr" STR(__AVR_ARCH__)
#endif #endif
"\n"); "\n"
); /* clang-format on */
return;
} }
static void print_status(void) { static void print_status(void) {
print("\n\t- Status -\n"); xprintf(/* clang-format off */
"\n\t- Status -\n"
print_val_hex8(host_keyboard_leds()); "host_keyboard_leds(): %02X\n"
#ifndef PROTOCOL_VUSB #ifndef PROTOCOL_VUSB
// these aren't set on the V-USB protocol, so we just ignore them for now "keyboard_protocol: %02X\n"
print_val_hex8(keyboard_protocol); "keyboard_idle: %02X\n"
print_val_hex8(keyboard_idle);
#endif #endif
#ifdef NKRO_ENABLE #ifdef NKRO_ENABLE
print_val_hex8(keymap_config.nkro); "keymap_config.nkro: %02X\n"
#endif #endif
print_val_hex32(timer_read32()); "timer_read32(): %08lX\n"
return;
, host_keyboard_leds()
#ifndef PROTOCOL_VUSB
/* these aren't set on the V-USB protocol, so we just ignore them for now */
, keyboard_protocol
, keyboard_idle
#endif
#ifdef NKRO_ENABLE
, keymap_config.nkro
#endif
, timer_read32()
); /* clang-format on */
} }
static void print_eeconfig(void) {
// Print these variables if NO_PRINT or USER_PRINT are not defined.
#if !defined(NO_PRINT) && !defined(USER_PRINT) #if !defined(NO_PRINT) && !defined(USER_PRINT)
static void print_eeconfig(void) {
print("default_layer: "); xprintf("eeconfig:\ndefault_layer: %u\n", eeconfig_read_default_layer());
print_dec(eeconfig_read_default_layer());
print("\n");
debug_config_t dc; debug_config_t dc;
dc.raw = eeconfig_read_debug(); dc.raw = eeconfig_read_debug();
print("debug_config.raw: "); xprintf(/* clang-format off */
print_hex8(dc.raw);
print("\n"); "debug_config.raw: %02X\n"
print(".enable: "); ".enable: %u\n"
print_dec(dc.enable); ".matrix: %u\n"
print("\n"); ".keyboard: %u\n"
print(".matrix: "); ".mouse: %u\n"
print_dec(dc.matrix);
print("\n"); , dc.raw
print(".keyboard: "); , dc.enable
print_dec(dc.keyboard); , dc.matrix
print("\n"); , dc.keyboard
print(".mouse: "); , dc.mouse
print_dec(dc.mouse); ); /* clang-format on */
print("\n");
keymap_config_t kc; keymap_config_t kc;
kc.raw = eeconfig_read_keymap(); kc.raw = eeconfig_read_keymap();
print("keymap_config.raw: "); xprintf(/* clang-format off */
print_hex8(kc.raw);
print("\n"); "keymap_config.raw: %02X\n"
print(".swap_control_capslock: "); ".swap_control_capslock: %u\n"
print_dec(kc.swap_control_capslock); ".capslock_to_control: %u\n"
print("\n"); ".swap_lctl_lgui: %u\n"
print(".capslock_to_control: "); ".swap_rctl_rgui: %u\n"
print_dec(kc.capslock_to_control); ".swap_lalt_lgui: %u\n"
print("\n"); ".swap_ralt_rgui: %u\n"
print(".swap_lctl_lgui: "); ".no_gui: %u\n"
print_dec(kc.swap_lctl_lgui); ".swap_grave_esc: %u\n"
print("\n"); ".swap_backslash_backspace: %u\n"
print(".swap_rctl_rgui: "); ".nkro: %u\n"
print_dec(kc.swap_rctl_rgui);
print("\n"); , kc.raw
print(".swap_lalt_lgui: "); , kc.swap_control_capslock
print_dec(kc.swap_lalt_lgui); , kc.capslock_to_control
print("\n"); , kc.swap_lctl_lgui
print(".swap_ralt_rgui: "); , kc.swap_rctl_rgui
print_dec(kc.swap_ralt_rgui); , kc.swap_lalt_lgui
print("\n"); , kc.swap_ralt_rgui
print(".no_gui: "); , kc.no_gui
print_dec(kc.no_gui); , kc.swap_grave_esc
print("\n"); , kc.swap_backslash_backspace
print(".swap_grave_esc: "); , kc.nkro
print_dec(kc.swap_grave_esc); ); /* clang-format on */
print("\n");
print(".swap_backslash_backspace: ");
print_dec(kc.swap_backslash_backspace);
print("\n");
print(".nkro: ");
print_dec(kc.nkro);
print("\n");
# ifdef BACKLIGHT_ENABLE # ifdef BACKLIGHT_ENABLE
backlight_config_t bc; backlight_config_t bc;
bc.raw = eeconfig_read_backlight(); bc.raw = eeconfig_read_backlight();
print("backlight_config.raw: "); xprintf(/* clang-format off */
print_hex8(bc.raw); "backlight_config"
print("\n");
print(".enable: ");
print_dec(bc.enable);
print("\n");
print(".level: ");
print_dec(bc.level);
print("\n");
# endif /* BACKLIGHT_ENABLE */
#endif /* !NO_PRINT */ ".raw: %02X\n"
".enable: %u\n"
".level: %u\n"
, bc.raw
, bc.enable
, bc.level
); /* clang-format on */
# endif /* BACKLIGHT_ENABLE */
} }
#endif /* !NO_PRINT && !USER_PRINT */
static bool command_common(uint8_t code) { static bool command_common(uint8_t code) {
#ifdef KEYBOARD_LOCK_ENABLE #ifdef KEYBOARD_LOCK_ENABLE
@ -306,8 +335,9 @@ static bool command_common(uint8_t code) {
// print stored eeprom config // print stored eeprom config
case MAGIC_KC(MAGIC_KEY_EEPROM): case MAGIC_KC(MAGIC_KEY_EEPROM):
print("eeconfig:\n"); #if !defined(NO_PRINT) && !defined(USER_PRINT)
print_eeconfig(); print_eeconfig();
#endif /* !NO_PRINT && !USER_PRINT */
break; break;
// clear eeprom // clear eeprom
@ -519,265 +549,196 @@ static bool command_console(uint8_t code) {
case KC_H: case KC_H:
case KC_SLASH: /* ? */ case KC_SLASH: /* ? */
command_console_help(); command_console_help();
break; print("C> ");
return true;
case KC_Q: case KC_Q:
case KC_ESC: case KC_ESC:
command_state = ONESHOT; command_state = ONESHOT;
return false; return false;
#if defined(MOUSEKEY_ENABLE) && !defined(MK_3_SPEED) #if defined(MOUSEKEY_ENABLE)
case KC_M: case KC_M:
mousekey_console_help();
print("M> ");
command_state = MOUSEKEY; command_state = MOUSEKEY;
mousekey_console(KC_SLASH /* ? */);
return true; return true;
#endif #endif
default: default:
print("?"); print("?");
return false; return false;
} }
print("C> ");
return true;
} }
#if defined(MOUSEKEY_ENABLE) && !defined(MK_3_SPEED)
/*********************************************************** /***********************************************************
* Mousekey console * Mousekey console
***********************************************************/ ***********************************************************/
static uint8_t mousekey_param = 0;
static void mousekey_param_print(void) { #if defined(MOUSEKEY_ENABLE)
// Print these variables if NO_PRINT or USER_PRINT are not defined.
# if !defined(NO_PRINT) && !defined(USER_PRINT) # if !defined(NO_PRINT) && !defined(USER_PRINT)
print("\n\t- Values -\n"); static void mousekey_param_print(void) {
print("1: delay(*10ms): "); xprintf(/* clang-format off */
print_dec(mk_delay);
print("\n");
print("2: interval(ms): ");
print_dec(mk_interval);
print("\n");
print("3: max_speed: ");
print_dec(mk_max_speed);
print("\n");
print("4: time_to_max: ");
print_dec(mk_time_to_max);
print("\n");
print("5: wheel_max_speed: ");
print_dec(mk_wheel_max_speed);
print("\n");
print("6: wheel_time_to_max: ");
print_dec(mk_wheel_time_to_max);
print("\n");
# endif /* !NO_PRINT */
}
//#define PRINT_SET_VAL(v) print(#v " = "); print_dec(v); print("\n"); #ifndef MK_3_SPEED
# define PRINT_SET_VAL(v) xprintf(# v " = %d\n", (v)) "1: delay(*10ms): %u\n"
static void mousekey_param_inc(uint8_t param, uint8_t inc) { "2: interval(ms): %u\n"
switch (param) { "3: max_speed: %u\n"
case 1: "4: time_to_max: %u\n"
if (mk_delay + inc < UINT8_MAX) "5: wheel_max_speed: %u\n"
mk_delay += inc; "6: wheel_time_to_max: %u\n"
else
mk_delay = UINT8_MAX;
PRINT_SET_VAL(mk_delay);
break;
case 2:
if (mk_interval + inc < UINT8_MAX)
mk_interval += inc;
else
mk_interval = UINT8_MAX;
PRINT_SET_VAL(mk_interval);
break;
case 3:
if (mk_max_speed + inc < UINT8_MAX)
mk_max_speed += inc;
else
mk_max_speed = UINT8_MAX;
PRINT_SET_VAL(mk_max_speed);
break;
case 4:
if (mk_time_to_max + inc < UINT8_MAX)
mk_time_to_max += inc;
else
mk_time_to_max = UINT8_MAX;
PRINT_SET_VAL(mk_time_to_max);
break;
case 5:
if (mk_wheel_max_speed + inc < UINT8_MAX)
mk_wheel_max_speed += inc;
else
mk_wheel_max_speed = UINT8_MAX;
PRINT_SET_VAL(mk_wheel_max_speed);
break;
case 6:
if (mk_wheel_time_to_max + inc < UINT8_MAX)
mk_wheel_time_to_max += inc;
else
mk_wheel_time_to_max = UINT8_MAX;
PRINT_SET_VAL(mk_wheel_time_to_max);
break;
}
}
static void mousekey_param_dec(uint8_t param, uint8_t dec) { , mk_delay
switch (param) { , mk_interval
case 1: , mk_max_speed
if (mk_delay > dec) , mk_time_to_max
mk_delay -= dec; , mk_wheel_max_speed
else , mk_wheel_time_to_max
mk_delay = 0; #else
PRINT_SET_VAL(mk_delay); "no knobs sorry\n"
break; #endif
case 2:
if (mk_interval > dec)
mk_interval -= dec;
else
mk_interval = 0;
PRINT_SET_VAL(mk_interval);
break;
case 3:
if (mk_max_speed > dec)
mk_max_speed -= dec;
else
mk_max_speed = 0;
PRINT_SET_VAL(mk_max_speed);
break;
case 4:
if (mk_time_to_max > dec)
mk_time_to_max -= dec;
else
mk_time_to_max = 0;
PRINT_SET_VAL(mk_time_to_max);
break;
case 5:
if (mk_wheel_max_speed > dec)
mk_wheel_max_speed -= dec;
else
mk_wheel_max_speed = 0;
PRINT_SET_VAL(mk_wheel_max_speed);
break;
case 6:
if (mk_wheel_time_to_max > dec)
mk_wheel_time_to_max -= dec;
else
mk_wheel_time_to_max = 0;
PRINT_SET_VAL(mk_wheel_time_to_max);
break;
}
}
); /* clang-format on */
}
# endif /* !NO_PRINT && !USER_PRINT */
# if !defined(NO_PRINT) && !defined(USER_PRINT)
static void mousekey_console_help(void) { static void mousekey_console_help(void) {
print("\n\t- Mousekey -\n" mousekey_param_print();
"ESC/q: quit\n" xprintf(/* clang-format off */
"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" "p: print values\n"
"d: set defaults\n" "d: set defaults\n"
"up: +1\n" "up: +1\n"
"down: -1\n" "dn: -1\n"
"pgup: +10\n" "lt: +10\n"
"pgdown: -10\n" "rt: -10\n"
"\n" "ESC/q: quit\n"
"speed = delta * max_speed * (repeat / time_to_max)\n");
xprintf("where delta: cursor=%d, wheel=%d\n" #ifndef MK_3_SPEED
"See http://en.wikipedia.org/wiki/Mouse_keys\n", "\n"
MOUSEKEY_MOVE_DELTA, MOUSEKEY_WHEEL_DELTA); "speed = delta * max_speed * (repeat / time_to_max)\n"
} "where delta: cursor=%d, wheel=%d\n"
"See http://en.wikipedia.org/wiki/Mouse_keys\n"
, MOUSEKEY_MOVE_DELTA, MOUSEKEY_WHEEL_DELTA
#endif
); /* clang-format on */
}
# endif /* !NO_PRINT && !USER_PRINT */
/* Only used by `quantum/command.c` / `command_proc()`. To avoid
* any doubt: we return `false` to return to the main console,
* which differs from the `bool` that `command_proc()` returns. */
bool mousekey_console(uint8_t code) {
static uint8_t param = 0;
static uint8_t *pp = NULL;
static char * desc = NULL;
# if defined(NO_PRINT) || defined(USER_PRINT) /* -Wunused-parameter */
(void)desc;
# endif
int8_t change = 0;
static bool mousekey_console(uint8_t code) {
switch (code) { switch (code) {
case KC_H: case KC_H:
case KC_SLASH: /* ? */ case KC_SLASH: /* ? */
# if !defined(NO_PRINT) && !defined(USER_PRINT)
print("\n\t- Mousekey -\n");
mousekey_console_help(); mousekey_console_help();
# endif
break; break;
case KC_Q: case KC_Q:
case KC_ESC: case KC_ESC:
if (mousekey_param) { print("q\n");
mousekey_param = 0; if (!param) return false;
} else { param = 0;
print("C> "); pp = NULL;
command_state = CONSOLE; desc = NULL;
return false;
}
break; break;
case KC_P: case KC_P:
# if !defined(NO_PRINT) && !defined(USER_PRINT)
print("\n\t- Values -\n");
mousekey_param_print(); mousekey_param_print();
# endif
break; break;
case KC_1:
case KC_2: case KC_1 ... KC_0: /* KC_0 gives param = 10 */
case KC_3: param = 1 + code - KC_1;
case KC_4: switch (param) { /* clang-format off */
case KC_5: # define PARAM(n, v) case n: pp = &(v); desc = #v; break
case KC_6:
mousekey_param = numkey2num(code); #ifndef MK_3_SPEED
PARAM(1, mk_delay);
PARAM(2, mk_interval);
PARAM(3, mk_max_speed);
PARAM(4, mk_time_to_max);
PARAM(5, mk_wheel_max_speed);
PARAM(6, mk_wheel_time_to_max);
#endif /* MK_3_SPEED */
# undef PARAM
default:
param = 0;
print("?\n");
break; break;
case KC_UP: } /* clang-format on */
mousekey_param_inc(mousekey_param, 1); if (param) xprintf("%u\n", param);
break;
case KC_DOWN:
mousekey_param_dec(mousekey_param, 1);
break;
case KC_PGUP:
mousekey_param_inc(mousekey_param, 10);
break;
case KC_PGDN:
mousekey_param_dec(mousekey_param, 10);
break; break;
/* clang-format off */
case KC_UP: change = +1; break;
case KC_DOWN: change = -1; break;
case KC_LEFT: change = -10; break;
case KC_RIGHT: change = +10; break;
/* clang-format on */
case KC_D: case KC_D:
# ifndef MK_3_SPEED
mk_delay = MOUSEKEY_DELAY / 10; mk_delay = MOUSEKEY_DELAY / 10;
mk_interval = MOUSEKEY_INTERVAL; mk_interval = MOUSEKEY_INTERVAL;
mk_max_speed = MOUSEKEY_MAX_SPEED; mk_max_speed = MOUSEKEY_MAX_SPEED;
mk_time_to_max = MOUSEKEY_TIME_TO_MAX; mk_time_to_max = MOUSEKEY_TIME_TO_MAX;
mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED; mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED;
mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX; mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX;
print("set default\n"); # endif /* MK_3_SPEED */
print("defaults\n");
break; break;
default: default:
print("?"); print("?\n");
return false; break;
} }
if (mousekey_param) {
xprintf("M%d> ", mousekey_param); if (change) {
if (pp) {
int16_t val = *pp + change;
if (val > (int16_t)UINT8_MAX)
*pp = UINT8_MAX;
else if (val < 0)
*pp = 0;
else
*pp = (uint8_t)val;
xprintf("= %u\n", *pp);
} else { } else {
print("M>"); print("?\n");
}
}
if (param) {
xprintf("M%u:%s> ", param, desc ? desc : "???");
} else {
print("M> ");
} }
return true; return true;
} }
#endif
#endif /* MOUSEKEY_ENABLE */
/*********************************************************** /***********************************************************
* Utilities * Utilities
***********************************************************/ ***********************************************************/
uint8_t numkey2num(uint8_t code) {
switch (code) {
case KC_1:
return 1;
case KC_2:
return 2;
case KC_3:
return 3;
case KC_4:
return 4;
case KC_5:
return 5;
case KC_6:
return 6;
case KC_7:
return 7;
case KC_8:
return 8;
case KC_9:
return 9;
case KC_0:
return 0;
}
return 0;
}
static void switch_default_layer(uint8_t layer) { static void switch_default_layer(uint8_t layer) {
xprintf("L%d\n", layer); xprintf("L%d\n", layer);

View file

@ -28,7 +28,6 @@ bool command_extra(uint8_t code);
bool command_console_extra(uint8_t code); bool command_console_extra(uint8_t code);
#ifdef COMMAND_ENABLE #ifdef COMMAND_ENABLE
uint8_t numkey2num(uint8_t code);
bool command_proc(uint8_t code); bool command_proc(uint8_t code);
#else #else
# define command_proc(code) false # define command_proc(code) false