command.c 19 KB

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