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