You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

771 lines
20 KiB

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