command.c 19 KB

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