command.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  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. #ifndef PROTOCOL_VUSB
  195. "keyboard_protocol: %02X\n"
  196. "keyboard_idle: %02X\n"
  197. #endif
  198. #ifdef NKRO_ENABLE
  199. "keymap_config.nkro: %02X\n"
  200. #endif
  201. "timer_read32(): %08lX\n"
  202. , host_keyboard_leds()
  203. #ifndef PROTOCOL_VUSB
  204. /* these aren't set on the V-USB protocol, so we just ignore them for now */
  205. , keyboard_protocol
  206. , keyboard_idle
  207. #endif
  208. #ifdef NKRO_ENABLE
  209. , keymap_config.nkro
  210. #endif
  211. , timer_read32()
  212. ); /* clang-format on */
  213. }
  214. #if !defined(NO_PRINT) && !defined(USER_PRINT)
  215. static void print_eeconfig(void) {
  216. xprintf("eeconfig:\ndefault_layer: %u\n", eeconfig_read_default_layer());
  217. debug_config_t dc;
  218. dc.raw = eeconfig_read_debug();
  219. xprintf(/* clang-format off */
  220. "debug_config.raw: %02X\n"
  221. ".enable: %u\n"
  222. ".matrix: %u\n"
  223. ".keyboard: %u\n"
  224. ".mouse: %u\n"
  225. , dc.raw
  226. , dc.enable
  227. , dc.matrix
  228. , dc.keyboard
  229. , dc.mouse
  230. ); /* clang-format on */
  231. keymap_config_t kc;
  232. kc.raw = eeconfig_read_keymap();
  233. xprintf(/* clang-format off */
  234. "keymap_config.raw: %02X\n"
  235. ".swap_control_capslock: %u\n"
  236. ".capslock_to_control: %u\n"
  237. ".swap_lctl_lgui: %u\n"
  238. ".swap_rctl_rgui: %u\n"
  239. ".swap_lalt_lgui: %u\n"
  240. ".swap_ralt_rgui: %u\n"
  241. ".no_gui: %u\n"
  242. ".swap_grave_esc: %u\n"
  243. ".swap_backslash_backspace: %u\n"
  244. ".nkro: %u\n"
  245. ".swap_escape_capslock: %u\n"
  246. , kc.raw
  247. , kc.swap_control_capslock
  248. , kc.capslock_to_control
  249. , kc.swap_lctl_lgui
  250. , kc.swap_rctl_rgui
  251. , kc.swap_lalt_lgui
  252. , kc.swap_ralt_rgui
  253. , kc.no_gui
  254. , kc.swap_grave_esc
  255. , kc.swap_backslash_backspace
  256. , kc.nkro
  257. , kc.swap_escape_capslock
  258. ); /* clang-format on */
  259. # ifdef BACKLIGHT_ENABLE
  260. backlight_config_t bc;
  261. bc.raw = eeconfig_read_backlight();
  262. xprintf(/* clang-format off */
  263. "backlight_config"
  264. ".raw: %02X\n"
  265. ".enable: %u\n"
  266. ".level: %u\n"
  267. , bc.raw
  268. , bc.enable
  269. , bc.level
  270. ); /* clang-format on */
  271. # endif /* BACKLIGHT_ENABLE */
  272. }
  273. #endif /* !NO_PRINT && !USER_PRINT */
  274. static bool command_common(uint8_t code) {
  275. #ifdef KEYBOARD_LOCK_ENABLE
  276. static host_driver_t *host_driver = 0;
  277. #endif
  278. switch (code) {
  279. #ifdef SLEEP_LED_ENABLE
  280. // test breathing sleep LED
  281. case MAGIC_KC(MAGIC_KEY_SLEEP_LED):
  282. print("Sleep LED Test\n");
  283. sleep_led_toggle();
  284. led_set(host_keyboard_leds());
  285. break;
  286. #endif
  287. // print stored eeprom config
  288. case MAGIC_KC(MAGIC_KEY_EEPROM):
  289. #if !defined(NO_PRINT) && !defined(USER_PRINT)
  290. print_eeconfig();
  291. #endif /* !NO_PRINT && !USER_PRINT */
  292. break;
  293. // clear eeprom
  294. case MAGIC_KC(MAGIC_KEY_EEPROM_CLEAR):
  295. print("Clearing EEPROM\n");
  296. eeconfig_init();
  297. break;
  298. #ifdef KEYBOARD_LOCK_ENABLE
  299. // lock/unlock keyboard
  300. case MAGIC_KC(MAGIC_KEY_LOCK):
  301. if (host_get_driver()) {
  302. host_driver = host_get_driver();
  303. clear_keyboard();
  304. host_set_driver(0);
  305. print("Locked.\n");
  306. } else {
  307. host_set_driver(host_driver);
  308. print("Unlocked.\n");
  309. }
  310. break;
  311. #endif
  312. // print help
  313. case MAGIC_KC(MAGIC_KEY_HELP):
  314. case MAGIC_KC(MAGIC_KEY_HELP_ALT):
  315. command_common_help();
  316. break;
  317. // activate console
  318. case MAGIC_KC(MAGIC_KEY_CONSOLE):
  319. debug_matrix = false;
  320. debug_keyboard = false;
  321. debug_mouse = false;
  322. debug_enable = false;
  323. command_console_help();
  324. print("C> ");
  325. command_state = CONSOLE;
  326. break;
  327. // jump to bootloader
  328. case MAGIC_KC(MAGIC_KEY_BOOTLOADER):
  329. case MAGIC_KC(MAGIC_KEY_BOOTLOADER_ALT):
  330. print("\n\nJumping to bootloader... ");
  331. reset_keyboard();
  332. break;
  333. // debug toggle
  334. case MAGIC_KC(MAGIC_KEY_DEBUG):
  335. debug_enable = !debug_enable;
  336. if (debug_enable) {
  337. print("\ndebug: on\n");
  338. } else {
  339. print("\ndebug: off\n");
  340. debug_matrix = false;
  341. debug_keyboard = false;
  342. debug_mouse = false;
  343. }
  344. break;
  345. // debug matrix toggle
  346. case MAGIC_KC(MAGIC_KEY_DEBUG_MATRIX):
  347. debug_matrix = !debug_matrix;
  348. if (debug_matrix) {
  349. print("\nmatrix: on\n");
  350. debug_enable = true;
  351. } else {
  352. print("\nmatrix: off\n");
  353. }
  354. break;
  355. // debug keyboard toggle
  356. case MAGIC_KC(MAGIC_KEY_DEBUG_KBD):
  357. debug_keyboard = !debug_keyboard;
  358. if (debug_keyboard) {
  359. print("\nkeyboard: on\n");
  360. debug_enable = true;
  361. } else {
  362. print("\nkeyboard: off\n");
  363. }
  364. break;
  365. // debug mouse toggle
  366. case MAGIC_KC(MAGIC_KEY_DEBUG_MOUSE):
  367. debug_mouse = !debug_mouse;
  368. if (debug_mouse) {
  369. print("\nmouse: on\n");
  370. debug_enable = true;
  371. } else {
  372. print("\nmouse: off\n");
  373. }
  374. break;
  375. // print version
  376. case MAGIC_KC(MAGIC_KEY_VERSION):
  377. print_version();
  378. break;
  379. // print status
  380. case MAGIC_KC(MAGIC_KEY_STATUS):
  381. print_status();
  382. break;
  383. #ifdef NKRO_ENABLE
  384. // NKRO toggle
  385. case MAGIC_KC(MAGIC_KEY_NKRO):
  386. clear_keyboard(); // clear to prevent stuck keys
  387. keymap_config.nkro = !keymap_config.nkro;
  388. if (keymap_config.nkro) {
  389. print("NKRO: on\n");
  390. } else {
  391. print("NKRO: off\n");
  392. }
  393. break;
  394. #endif
  395. // switch layers
  396. case MAGIC_KC(MAGIC_KEY_LAYER0_ALT):
  397. switch_default_layer(0);
  398. break;
  399. #if MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM
  400. case MAGIC_KC(MAGIC_KEY_LAYER0):
  401. switch_default_layer(0);
  402. break;
  403. case MAGIC_KC(MAGIC_KEY_LAYER1):
  404. switch_default_layer(1);
  405. break;
  406. case MAGIC_KC(MAGIC_KEY_LAYER2):
  407. switch_default_layer(2);
  408. break;
  409. case MAGIC_KC(MAGIC_KEY_LAYER3):
  410. switch_default_layer(3);
  411. break;
  412. case MAGIC_KC(MAGIC_KEY_LAYER4):
  413. switch_default_layer(4);
  414. break;
  415. case MAGIC_KC(MAGIC_KEY_LAYER5):
  416. switch_default_layer(5);
  417. break;
  418. case MAGIC_KC(MAGIC_KEY_LAYER6):
  419. switch_default_layer(6);
  420. break;
  421. case MAGIC_KC(MAGIC_KEY_LAYER7):
  422. switch_default_layer(7);
  423. break;
  424. case MAGIC_KC(MAGIC_KEY_LAYER8):
  425. switch_default_layer(8);
  426. break;
  427. case MAGIC_KC(MAGIC_KEY_LAYER9):
  428. switch_default_layer(9);
  429. break;
  430. #endif
  431. #if MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS
  432. case KC_F1 ... KC_F9:
  433. switch_default_layer((code - KC_F1) + 1);
  434. break;
  435. case KC_F10:
  436. switch_default_layer(0);
  437. break;
  438. #endif
  439. #if MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS
  440. case KC_1 ... KC_9:
  441. switch_default_layer((code - KC_1) + 1);
  442. break;
  443. case KC_0:
  444. switch_default_layer(0);
  445. break;
  446. #endif
  447. default:
  448. print("?");
  449. return false;
  450. }
  451. return true;
  452. }
  453. /***********************************************************
  454. * Command console
  455. ***********************************************************/
  456. static void command_console_help(void) {
  457. print("\n\t- Console -\n"
  458. "ESC/q: quit\n"
  459. #ifdef MOUSEKEY_ENABLE
  460. "m: mousekey\n"
  461. #endif
  462. );
  463. }
  464. static bool command_console(uint8_t code) {
  465. switch (code) {
  466. case KC_H:
  467. case KC_SLASH: /* ? */
  468. command_console_help();
  469. print("C> ");
  470. return true;
  471. case KC_Q:
  472. case KC_ESC:
  473. command_state = ONESHOT;
  474. return false;
  475. #if defined(MOUSEKEY_ENABLE)
  476. case KC_M:
  477. command_state = MOUSEKEY;
  478. mousekey_console(KC_SLASH /* ? */);
  479. return true;
  480. #endif
  481. default:
  482. print("?");
  483. return false;
  484. }
  485. }
  486. /***********************************************************
  487. * Mousekey console
  488. ***********************************************************/
  489. #if defined(MOUSEKEY_ENABLE)
  490. # if !defined(NO_PRINT) && !defined(USER_PRINT)
  491. static void mousekey_param_print(void) {
  492. xprintf(/* clang-format off */
  493. #ifndef MK_3_SPEED
  494. "1: delay(*10ms): %u\n"
  495. "2: interval(ms): %u\n"
  496. "3: max_speed: %u\n"
  497. "4: time_to_max: %u\n"
  498. "5: wheel_max_speed: %u\n"
  499. "6: wheel_time_to_max: %u\n"
  500. , mk_delay
  501. , mk_interval
  502. , mk_max_speed
  503. , mk_time_to_max
  504. , mk_wheel_max_speed
  505. , mk_wheel_time_to_max
  506. #else
  507. "no knobs sorry\n"
  508. #endif
  509. ); /* clang-format on */
  510. }
  511. # endif /* !NO_PRINT && !USER_PRINT */
  512. # if !defined(NO_PRINT) && !defined(USER_PRINT)
  513. static void mousekey_console_help(void) {
  514. mousekey_param_print();
  515. xprintf(/* clang-format off */
  516. "p: print values\n"
  517. "d: set defaults\n"
  518. "up: +1\n"
  519. "dn: -1\n"
  520. "lt: +10\n"
  521. "rt: -10\n"
  522. "ESC/q: quit\n"
  523. #ifndef MK_3_SPEED
  524. "\n"
  525. "speed = delta * max_speed * (repeat / time_to_max)\n"
  526. "where delta: cursor=%d, wheel=%d\n"
  527. "See http://en.wikipedia.org/wiki/Mouse_keys\n"
  528. , MOUSEKEY_MOVE_DELTA, MOUSEKEY_WHEEL_DELTA
  529. #endif
  530. ); /* clang-format on */
  531. }
  532. # endif /* !NO_PRINT && !USER_PRINT */
  533. /* Only used by `quantum/command.c` / `command_proc()`. To avoid
  534. * any doubt: we return `false` to return to the main console,
  535. * which differs from the `bool` that `command_proc()` returns. */
  536. bool mousekey_console(uint8_t code) {
  537. static uint8_t param = 0;
  538. static uint8_t *pp = NULL;
  539. static char * desc = NULL;
  540. # if defined(NO_PRINT) || defined(USER_PRINT) /* -Wunused-parameter */
  541. (void)desc;
  542. # endif
  543. int8_t change = 0;
  544. switch (code) {
  545. case KC_H:
  546. case KC_SLASH: /* ? */
  547. # if !defined(NO_PRINT) && !defined(USER_PRINT)
  548. print("\n\t- Mousekey -\n");
  549. mousekey_console_help();
  550. # endif
  551. break;
  552. case KC_Q:
  553. case KC_ESC:
  554. print("q\n");
  555. if (!param) return false;
  556. param = 0;
  557. pp = NULL;
  558. desc = NULL;
  559. break;
  560. case KC_P:
  561. # if !defined(NO_PRINT) && !defined(USER_PRINT)
  562. print("\n\t- Values -\n");
  563. mousekey_param_print();
  564. # endif
  565. break;
  566. case KC_1 ... KC_0: /* KC_0 gives param = 10 */
  567. param = 1 + code - KC_1;
  568. switch (param) { /* clang-format off */
  569. # define PARAM(n, v) case n: pp = &(v); desc = #v; break
  570. #ifndef MK_3_SPEED
  571. PARAM(1, mk_delay);
  572. PARAM(2, mk_interval);
  573. PARAM(3, mk_max_speed);
  574. PARAM(4, mk_time_to_max);
  575. PARAM(5, mk_wheel_max_speed);
  576. PARAM(6, mk_wheel_time_to_max);
  577. #endif /* MK_3_SPEED */
  578. # undef PARAM
  579. default:
  580. param = 0;
  581. print("?\n");
  582. break;
  583. } /* clang-format on */
  584. if (param) xprintf("%u\n", param);
  585. break;
  586. /* clang-format off */
  587. case KC_UP: change = +1; break;
  588. case KC_DOWN: change = -1; break;
  589. case KC_LEFT: change = -10; break;
  590. case KC_RIGHT: change = +10; break;
  591. /* clang-format on */
  592. case KC_D:
  593. # ifndef MK_3_SPEED
  594. mk_delay = MOUSEKEY_DELAY / 10;
  595. mk_interval = MOUSEKEY_INTERVAL;
  596. mk_max_speed = MOUSEKEY_MAX_SPEED;
  597. mk_time_to_max = MOUSEKEY_TIME_TO_MAX;
  598. mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED;
  599. mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX;
  600. # endif /* MK_3_SPEED */
  601. print("defaults\n");
  602. break;
  603. default:
  604. print("?\n");
  605. break;
  606. }
  607. if (change) {
  608. if (pp) {
  609. int16_t val = *pp + change;
  610. if (val > (int16_t)UINT8_MAX)
  611. *pp = UINT8_MAX;
  612. else if (val < 0)
  613. *pp = 0;
  614. else
  615. *pp = (uint8_t)val;
  616. xprintf("= %u\n", *pp);
  617. } else {
  618. print("?\n");
  619. }
  620. }
  621. if (param) {
  622. xprintf("M%u:%s> ", param, desc ? desc : "???");
  623. } else {
  624. print("M> ");
  625. }
  626. return true;
  627. }
  628. #endif /* MOUSEKEY_ENABLE */
  629. /***********************************************************
  630. * Utilities
  631. ***********************************************************/
  632. static void switch_default_layer(uint8_t layer) {
  633. xprintf("L%d\n", layer);
  634. default_layer_set((layer_state_t)1 << layer);
  635. clear_keyboard();
  636. }