command.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. /*
  2. Copyright 2011 Jun Wako <wakojun@gmail.com>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include <stdint.h>
  15. #include <stdbool.h>
  16. #include "wait.h"
  17. #include "keycode.h"
  18. #include "host.h"
  19. #include "print.h"
  20. #include "debug.h"
  21. #include "util.h"
  22. #include "timer.h"
  23. #include "keyboard.h"
  24. #include "bootloader.h"
  25. #include "action_layer.h"
  26. #include "action_util.h"
  27. #include "eeconfig.h"
  28. #include "led.h"
  29. #include "command.h"
  30. #include "quantum.h"
  31. #include "usb_device_state.h"
  32. #include "version.h"
  33. #ifdef BACKLIGHT_ENABLE
  34. # include "backlight.h"
  35. #endif
  36. #ifdef SLEEP_LED_ENABLE
  37. # include "sleep_led.h"
  38. #endif
  39. #if defined(MOUSEKEY_ENABLE)
  40. # include "mousekey.h"
  41. #endif
  42. #ifdef AUDIO_ENABLE
  43. # include "audio.h"
  44. #endif /* AUDIO_ENABLE */
  45. static bool command_common(uint8_t code);
  46. static void command_common_help(void);
  47. static void print_version(void);
  48. static void print_status(void);
  49. static bool command_console(uint8_t code);
  50. static void command_console_help(void);
  51. #if defined(MOUSEKEY_ENABLE)
  52. static bool mousekey_console(uint8_t code);
  53. #endif
  54. static void switch_default_layer(uint8_t layer);
  55. command_state_t command_state = ONESHOT;
  56. bool command_proc(uint8_t code) {
  57. switch (command_state) {
  58. case ONESHOT:
  59. if (!IS_COMMAND()) return false;
  60. return (command_extra(code) || command_common(code));
  61. break;
  62. case CONSOLE:
  63. if (IS_COMMAND())
  64. return (command_extra(code) || command_common(code));
  65. else
  66. return (command_console_extra(code) || command_console(code));
  67. break;
  68. #if defined(MOUSEKEY_ENABLE)
  69. case MOUSEKEY:
  70. mousekey_console(code);
  71. break;
  72. #endif
  73. default:
  74. command_state = ONESHOT;
  75. return false;
  76. }
  77. return true;
  78. }
  79. /* TODO: Refactoring is needed. */
  80. /* This allows to define extra commands. return false when not processed. */
  81. bool command_extra(uint8_t code) __attribute__((weak));
  82. bool command_extra(uint8_t code) {
  83. (void)code;
  84. return false;
  85. }
  86. bool command_console_extra(uint8_t code) __attribute__((weak));
  87. bool command_console_extra(uint8_t code) {
  88. (void)code;
  89. return false;
  90. }
  91. /***********************************************************
  92. * Command common
  93. ***********************************************************/
  94. static void command_common_help(void) {
  95. print(/* clang-format off */
  96. "\n\t- Magic -\n"
  97. STR(MAGIC_KEY_DEBUG) ": Debug Message Toggle\n"
  98. STR(MAGIC_KEY_DEBUG_MATRIX) ": Matrix Debug Mode Toggle"
  99. " - Show keypresses in matrix grid\n"
  100. STR(MAGIC_KEY_DEBUG_KBD) ": Keyboard Debug Toggle"
  101. " - Show keypress report\n"
  102. STR(MAGIC_KEY_DEBUG_MOUSE) ": Debug Mouse Toggle\n"
  103. STR(MAGIC_KEY_VERSION) ": Version\n"
  104. STR(MAGIC_KEY_STATUS) ": Status\n"
  105. STR(MAGIC_KEY_CONSOLE) ": Activate Console Mode\n"
  106. #if MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM
  107. STR(MAGIC_KEY_LAYER0) ": Switch to Layer 0\n"
  108. STR(MAGIC_KEY_LAYER1) ": Switch to Layer 1\n"
  109. STR(MAGIC_KEY_LAYER2) ": Switch to Layer 2\n"
  110. STR(MAGIC_KEY_LAYER3) ": Switch to Layer 3\n"
  111. STR(MAGIC_KEY_LAYER4) ": Switch to Layer 4\n"
  112. STR(MAGIC_KEY_LAYER5) ": Switch to Layer 5\n"
  113. STR(MAGIC_KEY_LAYER6) ": Switch to Layer 6\n"
  114. STR(MAGIC_KEY_LAYER7) ": Switch to Layer 7\n"
  115. STR(MAGIC_KEY_LAYER8) ": Switch to Layer 8\n"
  116. STR(MAGIC_KEY_LAYER9) ": Switch to Layer 9\n"
  117. #endif
  118. #if MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS
  119. "F1-F10: Switch to Layer 0-9 (F10 = L0)\n"
  120. #endif
  121. #if MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS
  122. "0-9: Switch to Layer 0-9\n"
  123. #endif
  124. STR(MAGIC_KEY_LAYER0_ALT) ": Switch to Layer 0 (alternate)\n"
  125. STR(MAGIC_KEY_BOOTLOADER) ": Jump to Bootloader\n"
  126. STR(MAGIC_KEY_BOOTLOADER_ALT) ": Jump to Bootloader (alternate)\n"
  127. #ifdef KEYBOARD_LOCK_ENABLE
  128. STR(MAGIC_KEY_LOCK) ": Lock Keyboard\n"
  129. #endif
  130. STR(MAGIC_KEY_EEPROM) ": Print EEPROM Settings\n"
  131. STR(MAGIC_KEY_EEPROM_CLEAR) ": Clear EEPROM\n"
  132. #ifdef NKRO_ENABLE
  133. STR(MAGIC_KEY_NKRO) ": NKRO Toggle\n"
  134. #endif
  135. #ifdef SLEEP_LED_ENABLE
  136. STR(MAGIC_KEY_SLEEP_LED) ": Sleep LED Test\n"
  137. #endif
  138. ); /* clang-format on */
  139. }
  140. static void print_version(void) {
  141. xprintf("%s", /* clang-format off */
  142. "\n\t- Version -\n"
  143. "VID: " STR(VENDOR_ID) "(" STR(MANUFACTURER) ") "
  144. "PID: " STR(PRODUCT_ID) "(" STR(PRODUCT) ") "
  145. "VER: " STR(DEVICE_VER) "\n"
  146. "BUILD: (" __DATE__ ")\n"
  147. #ifndef SKIP_VERSION
  148. # ifdef PROTOCOL_CHIBIOS
  149. "CHIBIOS: " STR(CHIBIOS_VERSION)
  150. ", CONTRIB: " STR(CHIBIOS_CONTRIB_VERSION) "\n"
  151. # endif
  152. #endif
  153. /* build options */
  154. "OPTIONS:"
  155. #ifdef PROTOCOL_LUFA
  156. " LUFA"
  157. #endif
  158. #ifdef PROTOCOL_VUSB
  159. " VUSB"
  160. #endif
  161. #ifdef BOOTMAGIC_ENABLE
  162. " BOOTMAGIC"
  163. #endif
  164. #ifdef MOUSEKEY_ENABLE
  165. " MOUSEKEY"
  166. #endif
  167. #ifdef EXTRAKEY_ENABLE
  168. " EXTRAKEY"
  169. #endif
  170. #ifdef CONSOLE_ENABLE
  171. " CONSOLE"
  172. #endif
  173. #ifdef COMMAND_ENABLE
  174. " COMMAND"
  175. #endif
  176. #ifdef NKRO_ENABLE
  177. " NKRO"
  178. #endif
  179. #ifdef LTO_ENABLE
  180. " LTO"
  181. #endif
  182. " " STR(BOOTLOADER_SIZE) "\n"
  183. "GCC: " STR(__GNUC__)
  184. "." STR(__GNUC_MINOR__)
  185. "." STR(__GNUC_PATCHLEVEL__)
  186. #if defined(__AVR__)
  187. " AVR-LIBC: " __AVR_LIBC_VERSION_STRING__
  188. " AVR_ARCH: avr" STR(__AVR_ARCH__)
  189. #endif
  190. "\n"
  191. ); /* clang-format on */
  192. }
  193. static void print_status(void) {
  194. xprintf(/* clang-format off */
  195. "\n\t- Status -\n"
  196. "host_keyboard_leds(): %02X\n"
  197. "keyboard_protocol: %02X\n"
  198. "keyboard_idle: %02X\n"
  199. #ifdef NKRO_ENABLE
  200. "keymap_config.nkro: %02X\n"
  201. #endif
  202. "timer_read32(): %08lX\n"
  203. , host_keyboard_leds()
  204. , usb_device_state_get_protocol()
  205. , usb_device_state_get_idle_rate()
  206. #ifdef NKRO_ENABLE
  207. , keymap_config.nkro
  208. #endif
  209. , timer_read32()
  210. ); /* clang-format on */
  211. }
  212. #if !defined(NO_PRINT) && !defined(USER_PRINT)
  213. static void print_eeconfig(void) {
  214. xprintf("eeconfig:\ndefault_layer: %" PRIu32 "\n", (uint32_t)eeconfig_read_default_layer());
  215. debug_config_t dc;
  216. eeconfig_read_debug(&dc);
  217. xprintf(/* clang-format off */
  218. "debug_config.raw: %02X\n"
  219. ".enable: %u\n"
  220. ".matrix: %u\n"
  221. ".keyboard: %u\n"
  222. ".mouse: %u\n"
  223. , dc.raw
  224. , dc.enable
  225. , dc.matrix
  226. , dc.keyboard
  227. , dc.mouse
  228. ); /* clang-format on */
  229. keymap_config_t kc;
  230. eeconfig_read_keymap(&kc);
  231. xprintf(/* clang-format off */
  232. "keymap_config.raw: %02X\n"
  233. ".swap_control_capslock: %u\n"
  234. ".capslock_to_control: %u\n"
  235. ".swap_lctl_lgui: %u\n"
  236. ".swap_rctl_rgui: %u\n"
  237. ".swap_lalt_lgui: %u\n"
  238. ".swap_ralt_rgui: %u\n"
  239. ".no_gui: %u\n"
  240. ".swap_grave_esc: %u\n"
  241. ".swap_backslash_backspace: %u\n"
  242. ".nkro: %u\n"
  243. ".swap_escape_capslock: %u\n"
  244. , kc.raw
  245. , kc.swap_control_capslock
  246. , kc.capslock_to_control
  247. , kc.swap_lctl_lgui
  248. , kc.swap_rctl_rgui
  249. , kc.swap_lalt_lgui
  250. , kc.swap_ralt_rgui
  251. , kc.no_gui
  252. , kc.swap_grave_esc
  253. , kc.swap_backslash_backspace
  254. , kc.nkro
  255. , kc.swap_escape_capslock
  256. ); /* clang-format on */
  257. # ifdef BACKLIGHT_ENABLE
  258. backlight_config_t bc;
  259. eeconfig_read_backlight(&bc);
  260. xprintf(/* clang-format off */
  261. "backlight_config"
  262. ".raw: %02X\n"
  263. ".enable: %u\n"
  264. ".level: %u\n"
  265. , bc.raw
  266. , bc.enable
  267. , bc.level
  268. ); /* clang-format on */
  269. # endif /* BACKLIGHT_ENABLE */
  270. }
  271. #endif /* !NO_PRINT && !USER_PRINT */
  272. static bool command_common(uint8_t code) {
  273. #ifdef KEYBOARD_LOCK_ENABLE
  274. static host_driver_t *host_driver = 0;
  275. #endif
  276. switch (code) {
  277. #ifdef SLEEP_LED_ENABLE
  278. // test breathing sleep LED
  279. case MAGIC_KC(MAGIC_KEY_SLEEP_LED):
  280. print("Sleep LED Test\n");
  281. sleep_led_toggle();
  282. led_set(host_keyboard_leds());
  283. break;
  284. #endif
  285. // print stored eeprom config
  286. case MAGIC_KC(MAGIC_KEY_EEPROM):
  287. #if !defined(NO_PRINT) && !defined(USER_PRINT)
  288. print_eeconfig();
  289. #endif /* !NO_PRINT && !USER_PRINT */
  290. break;
  291. // clear eeprom
  292. case MAGIC_KC(MAGIC_KEY_EEPROM_CLEAR):
  293. print("Clearing EEPROM\n");
  294. eeconfig_init();
  295. break;
  296. #ifdef KEYBOARD_LOCK_ENABLE
  297. // lock/unlock keyboard
  298. case MAGIC_KC(MAGIC_KEY_LOCK):
  299. if (host_get_driver()) {
  300. host_driver = host_get_driver();
  301. clear_keyboard();
  302. host_set_driver(0);
  303. print("Locked.\n");
  304. } else {
  305. host_set_driver(host_driver);
  306. print("Unlocked.\n");
  307. }
  308. break;
  309. #endif
  310. // print help
  311. case MAGIC_KC(MAGIC_KEY_HELP):
  312. case MAGIC_KC(MAGIC_KEY_HELP_ALT):
  313. command_common_help();
  314. break;
  315. // activate console
  316. case MAGIC_KC(MAGIC_KEY_CONSOLE):
  317. debug_matrix = false;
  318. debug_keyboard = false;
  319. debug_mouse = false;
  320. debug_enable = false;
  321. command_console_help();
  322. print("C> ");
  323. command_state = CONSOLE;
  324. break;
  325. // jump to bootloader
  326. case MAGIC_KC(MAGIC_KEY_BOOTLOADER):
  327. case MAGIC_KC(MAGIC_KEY_BOOTLOADER_ALT):
  328. print("\n\nJumping to bootloader... ");
  329. reset_keyboard();
  330. break;
  331. // debug toggle
  332. case MAGIC_KC(MAGIC_KEY_DEBUG):
  333. debug_enable = !debug_enable;
  334. if (debug_enable) {
  335. print("\ndebug: on\n");
  336. } else {
  337. print("\ndebug: off\n");
  338. debug_matrix = false;
  339. debug_keyboard = false;
  340. debug_mouse = false;
  341. }
  342. break;
  343. // debug matrix toggle
  344. case MAGIC_KC(MAGIC_KEY_DEBUG_MATRIX):
  345. debug_matrix = !debug_matrix;
  346. if (debug_matrix) {
  347. print("\nmatrix: on\n");
  348. debug_enable = true;
  349. } else {
  350. print("\nmatrix: off\n");
  351. }
  352. break;
  353. // debug keyboard toggle
  354. case MAGIC_KC(MAGIC_KEY_DEBUG_KBD):
  355. debug_keyboard = !debug_keyboard;
  356. if (debug_keyboard) {
  357. print("\nkeyboard: on\n");
  358. debug_enable = true;
  359. } else {
  360. print("\nkeyboard: off\n");
  361. }
  362. break;
  363. // debug mouse toggle
  364. case MAGIC_KC(MAGIC_KEY_DEBUG_MOUSE):
  365. debug_mouse = !debug_mouse;
  366. if (debug_mouse) {
  367. print("\nmouse: on\n");
  368. debug_enable = true;
  369. } else {
  370. print("\nmouse: off\n");
  371. }
  372. break;
  373. // print version
  374. case MAGIC_KC(MAGIC_KEY_VERSION):
  375. print_version();
  376. break;
  377. // print status
  378. case MAGIC_KC(MAGIC_KEY_STATUS):
  379. print_status();
  380. break;
  381. #ifdef NKRO_ENABLE
  382. // NKRO toggle
  383. case MAGIC_KC(MAGIC_KEY_NKRO):
  384. clear_keyboard(); // clear to prevent stuck keys
  385. keymap_config.nkro = !keymap_config.nkro;
  386. if (keymap_config.nkro) {
  387. print("NKRO: on\n");
  388. } else {
  389. print("NKRO: off\n");
  390. }
  391. break;
  392. #endif
  393. // switch layers
  394. case MAGIC_KC(MAGIC_KEY_LAYER0_ALT):
  395. switch_default_layer(0);
  396. break;
  397. #if MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM
  398. case MAGIC_KC(MAGIC_KEY_LAYER0):
  399. switch_default_layer(0);
  400. break;
  401. case MAGIC_KC(MAGIC_KEY_LAYER1):
  402. switch_default_layer(1);
  403. break;
  404. case MAGIC_KC(MAGIC_KEY_LAYER2):
  405. switch_default_layer(2);
  406. break;
  407. case MAGIC_KC(MAGIC_KEY_LAYER3):
  408. switch_default_layer(3);
  409. break;
  410. case MAGIC_KC(MAGIC_KEY_LAYER4):
  411. switch_default_layer(4);
  412. break;
  413. case MAGIC_KC(MAGIC_KEY_LAYER5):
  414. switch_default_layer(5);
  415. break;
  416. case MAGIC_KC(MAGIC_KEY_LAYER6):
  417. switch_default_layer(6);
  418. break;
  419. case MAGIC_KC(MAGIC_KEY_LAYER7):
  420. switch_default_layer(7);
  421. break;
  422. case MAGIC_KC(MAGIC_KEY_LAYER8):
  423. switch_default_layer(8);
  424. break;
  425. case MAGIC_KC(MAGIC_KEY_LAYER9):
  426. switch_default_layer(9);
  427. break;
  428. #endif
  429. #if MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS
  430. case KC_F1 ... KC_F9:
  431. switch_default_layer((code - KC_F1) + 1);
  432. break;
  433. case KC_F10:
  434. switch_default_layer(0);
  435. break;
  436. #endif
  437. #if MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS
  438. case KC_1 ... KC_9:
  439. switch_default_layer((code - KC_1) + 1);
  440. break;
  441. case KC_0:
  442. switch_default_layer(0);
  443. break;
  444. #endif
  445. default:
  446. print("?");
  447. return false;
  448. }
  449. return true;
  450. }
  451. /***********************************************************
  452. * Command console
  453. ***********************************************************/
  454. static void command_console_help(void) {
  455. print("\n\t- Console -\n"
  456. "ESC/q: quit\n"
  457. #ifdef MOUSEKEY_ENABLE
  458. "m: mousekey\n"
  459. #endif
  460. );
  461. }
  462. static bool command_console(uint8_t code) {
  463. switch (code) {
  464. case KC_H:
  465. case KC_SLASH: /* ? */
  466. command_console_help();
  467. print("C> ");
  468. return true;
  469. case KC_Q:
  470. case KC_ESC:
  471. command_state = ONESHOT;
  472. return false;
  473. #if defined(MOUSEKEY_ENABLE)
  474. case KC_M:
  475. command_state = MOUSEKEY;
  476. mousekey_console(KC_SLASH /* ? */);
  477. return true;
  478. #endif
  479. default:
  480. print("?");
  481. return false;
  482. }
  483. }
  484. /***********************************************************
  485. * Mousekey console
  486. ***********************************************************/
  487. #if defined(MOUSEKEY_ENABLE)
  488. # if !defined(NO_PRINT) && !defined(USER_PRINT)
  489. static void mousekey_param_print(void) {
  490. xprintf(/* clang-format off */
  491. #ifndef MK_3_SPEED
  492. "1: delay(*10ms): %u\n"
  493. "2: interval(ms): %u\n"
  494. "3: max_speed: %u\n"
  495. "4: time_to_max: %u\n"
  496. "5: wheel_max_speed: %u\n"
  497. "6: wheel_time_to_max: %u\n"
  498. , mk_delay
  499. , mk_interval
  500. , mk_max_speed
  501. , mk_time_to_max
  502. , mk_wheel_max_speed
  503. , mk_wheel_time_to_max
  504. #else
  505. "no knobs sorry\n"
  506. #endif
  507. ); /* clang-format on */
  508. }
  509. # endif /* !NO_PRINT && !USER_PRINT */
  510. # if !defined(NO_PRINT) && !defined(USER_PRINT)
  511. static void mousekey_console_help(void) {
  512. mousekey_param_print();
  513. xprintf(/* clang-format off */
  514. "p: print values\n"
  515. "d: set defaults\n"
  516. "up: +1\n"
  517. "dn: -1\n"
  518. "lt: +10\n"
  519. "rt: -10\n"
  520. "ESC/q: quit\n"
  521. #ifndef MK_3_SPEED
  522. "\n"
  523. "speed = delta * max_speed * (repeat / time_to_max)\n"
  524. "where delta: cursor=%d, wheel=%d\n"
  525. "See http://en.wikipedia.org/wiki/Mouse_keys\n"
  526. , MOUSEKEY_MOVE_DELTA, MOUSEKEY_WHEEL_DELTA
  527. #endif
  528. ); /* clang-format on */
  529. }
  530. # endif /* !NO_PRINT && !USER_PRINT */
  531. /* Only used by `quantum/command.c` / `command_proc()`. To avoid
  532. * any doubt: we return `false` to return to the main console,
  533. * which differs from the `bool` that `command_proc()` returns. */
  534. bool mousekey_console(uint8_t code) {
  535. static uint8_t param = 0;
  536. static uint8_t *pp = NULL;
  537. static char *desc = NULL;
  538. # if defined(NO_PRINT) || defined(USER_PRINT) /* -Wunused-parameter */
  539. (void)desc;
  540. # endif
  541. int8_t change = 0;
  542. switch (code) {
  543. case KC_H:
  544. case KC_SLASH: /* ? */
  545. # if !defined(NO_PRINT) && !defined(USER_PRINT)
  546. print("\n\t- Mousekey -\n");
  547. mousekey_console_help();
  548. # endif
  549. break;
  550. case KC_Q:
  551. case KC_ESC:
  552. print("q\n");
  553. if (!param) return false;
  554. param = 0;
  555. pp = NULL;
  556. desc = NULL;
  557. break;
  558. case KC_P:
  559. # if !defined(NO_PRINT) && !defined(USER_PRINT)
  560. print("\n\t- Values -\n");
  561. mousekey_param_print();
  562. # endif
  563. break;
  564. case KC_1 ... KC_0: /* KC_0 gives param = 10 */
  565. param = 1 + code - KC_1;
  566. switch (param) { /* clang-format off */
  567. # define PARAM(n, v) case n: pp = &(v); desc = #v; break
  568. #ifndef MK_3_SPEED
  569. PARAM(1, mk_delay);
  570. PARAM(2, mk_interval);
  571. PARAM(3, mk_max_speed);
  572. PARAM(4, mk_time_to_max);
  573. PARAM(5, mk_wheel_max_speed);
  574. PARAM(6, mk_wheel_time_to_max);
  575. #endif /* MK_3_SPEED */
  576. # undef PARAM
  577. default:
  578. param = 0;
  579. print("?\n");
  580. break;
  581. } /* clang-format on */
  582. if (param) xprintf("%u\n", param);
  583. break;
  584. /* clang-format off */
  585. case KC_UP: change = +1; break;
  586. case KC_DOWN: change = -1; break;
  587. case KC_LEFT: change = -10; break;
  588. case KC_RIGHT: change = +10; break;
  589. /* clang-format on */
  590. case KC_D:
  591. # ifndef MK_3_SPEED
  592. mk_delay = MOUSEKEY_DELAY / 10;
  593. mk_interval = MOUSEKEY_INTERVAL;
  594. mk_max_speed = MOUSEKEY_MAX_SPEED;
  595. mk_time_to_max = MOUSEKEY_TIME_TO_MAX;
  596. mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED;
  597. mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX;
  598. # endif /* MK_3_SPEED */
  599. print("defaults\n");
  600. break;
  601. default:
  602. print("?\n");
  603. break;
  604. }
  605. if (change) {
  606. if (pp) {
  607. int16_t val = *pp + change;
  608. if (val > (int16_t)UINT8_MAX)
  609. *pp = UINT8_MAX;
  610. else if (val < 0)
  611. *pp = 0;
  612. else
  613. *pp = (uint8_t)val;
  614. xprintf("= %u\n", *pp);
  615. } else {
  616. print("?\n");
  617. }
  618. }
  619. if (param) {
  620. xprintf("M%u:%s> ", param, desc ? desc : "???");
  621. } else {
  622. print("M> ");
  623. }
  624. return true;
  625. }
  626. #endif /* MOUSEKEY_ENABLE */
  627. /***********************************************************
  628. * Utilities
  629. ***********************************************************/
  630. static void switch_default_layer(uint8_t layer) {
  631. xprintf("L%d\n", layer);
  632. default_layer_set((layer_state_t)1 << layer);
  633. clear_keyboard();
  634. }