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.

506 lines
18 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. /*
  2. * Copyright 2011 Jun Wako <wakojun@gmail.com>
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <stdint.h>
  18. #include <string.h>
  19. #include "keycode.h"
  20. #include "host.h"
  21. #include "timer.h"
  22. #include "print.h"
  23. #include "debug.h"
  24. #include "mousekey.h"
  25. inline int8_t times_inv_sqrt2(int8_t x) {
  26. // 181/256 is pretty close to 1/sqrt(2)
  27. // 0.70703125 0.707106781
  28. // 1 too small for x=99 and x=198
  29. // This ends up being a mult and discard lower 8 bits
  30. return (x * 181) >> 8;
  31. }
  32. static report_mouse_t mouse_report = {0};
  33. static void mousekey_debug(void);
  34. static uint8_t mousekey_accel = 0;
  35. static uint8_t mousekey_repeat = 0;
  36. static uint8_t mousekey_wheel_repeat = 0;
  37. #ifdef MK_KINETIC_SPEED
  38. static uint16_t mouse_timer = 0;
  39. #endif
  40. #ifndef MK_3_SPEED
  41. static uint16_t last_timer_c = 0;
  42. static uint16_t last_timer_w = 0;
  43. /*
  44. * Mouse keys acceleration algorithm
  45. * http://en.wikipedia.org/wiki/Mouse_keys
  46. *
  47. * speed = delta * max_speed * (repeat / time_to_max)**((1000+curve)/1000)
  48. */
  49. /* milliseconds between the initial key press and first repeated motion event (0-2550) */
  50. uint8_t mk_delay = MOUSEKEY_DELAY / 10;
  51. /* milliseconds between repeated motion events (0-255) */
  52. uint8_t mk_interval = MOUSEKEY_INTERVAL;
  53. /* steady speed (in action_delta units) applied each event (0-255) */
  54. uint8_t mk_max_speed = MOUSEKEY_MAX_SPEED;
  55. /* number of events (count) accelerating to steady speed (0-255) */
  56. uint8_t mk_time_to_max = MOUSEKEY_TIME_TO_MAX;
  57. /* ramp used to reach maximum pointer speed (NOT SUPPORTED) */
  58. // int8_t mk_curve = 0;
  59. /* wheel params */
  60. /* milliseconds between the initial key press and first repeated motion event (0-2550) */
  61. uint8_t mk_wheel_delay = MOUSEKEY_WHEEL_DELAY / 10;
  62. /* milliseconds between repeated motion events (0-255) */
  63. # ifdef MK_KINETIC_SPEED
  64. float mk_wheel_interval = 1000.0f / MOUSEKEY_WHEEL_INITIAL_MOVEMENTS;
  65. # else
  66. uint8_t mk_wheel_interval = MOUSEKEY_WHEEL_INTERVAL;
  67. # endif
  68. uint8_t mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED;
  69. uint8_t mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX;
  70. # ifndef MK_COMBINED
  71. # ifndef MK_KINETIC_SPEED
  72. /* Default accelerated mode */
  73. static uint8_t move_unit(void) {
  74. uint16_t unit;
  75. if (mousekey_accel & (1 << 0)) {
  76. unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed) / 4;
  77. } else if (mousekey_accel & (1 << 1)) {
  78. unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed) / 2;
  79. } else if (mousekey_accel & (1 << 2)) {
  80. unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed);
  81. } else if (mousekey_repeat == 0) {
  82. unit = MOUSEKEY_MOVE_DELTA;
  83. } else if (mousekey_repeat >= mk_time_to_max) {
  84. unit = MOUSEKEY_MOVE_DELTA * mk_max_speed;
  85. } else {
  86. unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed * mousekey_repeat) / mk_time_to_max;
  87. }
  88. return (unit > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : (unit == 0 ? 1 : unit));
  89. }
  90. static uint8_t wheel_unit(void) {
  91. uint16_t unit;
  92. if (mousekey_accel & (1 << 0)) {
  93. unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed) / 4;
  94. } else if (mousekey_accel & (1 << 1)) {
  95. unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed) / 2;
  96. } else if (mousekey_accel & (1 << 2)) {
  97. unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed);
  98. } else if (mousekey_wheel_repeat == 0) {
  99. unit = MOUSEKEY_WHEEL_DELTA;
  100. } else if (mousekey_wheel_repeat >= mk_wheel_time_to_max) {
  101. unit = MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed;
  102. } else {
  103. unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed * mousekey_wheel_repeat) / mk_wheel_time_to_max;
  104. }
  105. return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : (unit == 0 ? 1 : unit));
  106. }
  107. # else /* #ifndef MK_KINETIC_SPEED */
  108. /*
  109. * Kinetic movement acceleration algorithm
  110. *
  111. * current speed = I + A * T/50 + A * 0.5 * T^2 | maximum B
  112. *
  113. * T: time since the mouse movement started
  114. * E: mouse events per second (set through MOUSEKEY_INTERVAL, UHK sends 250, the
  115. * pro micro on my Signum 3.0 sends only 125!)
  116. * I: initial speed at time 0
  117. * A: acceleration
  118. * B: base mouse travel speed
  119. */
  120. const uint16_t mk_accelerated_speed = MOUSEKEY_ACCELERATED_SPEED;
  121. const uint16_t mk_base_speed = MOUSEKEY_BASE_SPEED;
  122. const uint16_t mk_decelerated_speed = MOUSEKEY_DECELERATED_SPEED;
  123. const uint16_t mk_initial_speed = MOUSEKEY_INITIAL_SPEED;
  124. static uint8_t move_unit(void) {
  125. float speed = mk_initial_speed;
  126. if (mousekey_accel & ((1 << 0) | (1 << 2))) {
  127. speed = mousekey_accel & (1 << 2) ? mk_accelerated_speed : mk_decelerated_speed;
  128. } else if (mousekey_repeat && mouse_timer) {
  129. const float time_elapsed = timer_elapsed(mouse_timer) / 50;
  130. speed = mk_initial_speed + MOUSEKEY_MOVE_DELTA * time_elapsed + MOUSEKEY_MOVE_DELTA * 0.5 * time_elapsed * time_elapsed;
  131. speed = speed > mk_base_speed ? mk_base_speed : speed;
  132. }
  133. /* convert speed to USB mouse speed 1 to 127 */
  134. speed = (uint8_t)(speed / (1000.0f / mk_interval));
  135. speed = speed < 1 ? 1 : speed;
  136. return speed > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : speed;
  137. }
  138. static uint8_t wheel_unit(void) {
  139. float speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS;
  140. if (mousekey_accel & ((1 << 0) | (1 << 2))) {
  141. speed = mousekey_accel & (1 << 2) ? MOUSEKEY_WHEEL_ACCELERATED_MOVEMENTS : MOUSEKEY_WHEEL_DECELERATED_MOVEMENTS;
  142. } else if (mousekey_wheel_repeat && mouse_timer) {
  143. if (mk_wheel_interval != MOUSEKEY_WHEEL_BASE_MOVEMENTS) {
  144. const float time_elapsed = timer_elapsed(mouse_timer) / 50;
  145. speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS + 1 * time_elapsed + 1 * 0.5 * time_elapsed * time_elapsed;
  146. }
  147. speed = speed > MOUSEKEY_WHEEL_BASE_MOVEMENTS ? MOUSEKEY_WHEEL_BASE_MOVEMENTS : speed;
  148. }
  149. mk_wheel_interval = 1000.0f / speed;
  150. return (uint8_t)speed > MOUSEKEY_WHEEL_INITIAL_MOVEMENTS ? 2 : 1;
  151. }
  152. # endif /* #ifndef MK_KINETIC_SPEED */
  153. # else /* #ifndef MK_COMBINED */
  154. /* Combined mode */
  155. static uint8_t move_unit(void) {
  156. uint16_t unit;
  157. if (mousekey_accel & (1 << 0)) {
  158. unit = 1;
  159. } else if (mousekey_accel & (1 << 1)) {
  160. unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed) / 2;
  161. } else if (mousekey_accel & (1 << 2)) {
  162. unit = MOUSEKEY_MOVE_MAX;
  163. } else if (mousekey_repeat == 0) {
  164. unit = MOUSEKEY_MOVE_DELTA;
  165. } else if (mousekey_repeat >= mk_time_to_max) {
  166. unit = MOUSEKEY_MOVE_DELTA * mk_max_speed;
  167. } else {
  168. unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed * mousekey_repeat) / mk_time_to_max;
  169. }
  170. return (unit > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : (unit == 0 ? 1 : unit));
  171. }
  172. static uint8_t wheel_unit(void) {
  173. uint16_t unit;
  174. if (mousekey_accel & (1 << 0)) {
  175. unit = 1;
  176. } else if (mousekey_accel & (1 << 1)) {
  177. unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed) / 2;
  178. } else if (mousekey_accel & (1 << 2)) {
  179. unit = MOUSEKEY_WHEEL_MAX;
  180. } else if (mousekey_repeat == 0) {
  181. unit = MOUSEKEY_WHEEL_DELTA;
  182. } else if (mousekey_repeat >= mk_wheel_time_to_max) {
  183. unit = MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed;
  184. } else {
  185. unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed * mousekey_repeat) / mk_wheel_time_to_max;
  186. }
  187. return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : (unit == 0 ? 1 : unit));
  188. }
  189. # endif /* #ifndef MK_COMBINED */
  190. void mousekey_task(void) {
  191. // report cursor and scroll movement independently
  192. report_mouse_t tmpmr = mouse_report;
  193. mouse_report.x = 0;
  194. mouse_report.y = 0;
  195. mouse_report.v = 0;
  196. mouse_report.h = 0;
  197. if ((tmpmr.x || tmpmr.y) && timer_elapsed(last_timer_c) > (mousekey_repeat ? mk_interval : mk_delay * 10)) {
  198. if (mousekey_repeat != UINT8_MAX) mousekey_repeat++;
  199. if (tmpmr.x != 0) mouse_report.x = move_unit() * ((tmpmr.x > 0) ? 1 : -1);
  200. if (tmpmr.y != 0) mouse_report.y = move_unit() * ((tmpmr.y > 0) ? 1 : -1);
  201. /* diagonal move [1/sqrt(2)] */
  202. if (mouse_report.x && mouse_report.y) {
  203. mouse_report.x = times_inv_sqrt2(mouse_report.x);
  204. if (mouse_report.x == 0) {
  205. mouse_report.x = 1;
  206. }
  207. mouse_report.y = times_inv_sqrt2(mouse_report.y);
  208. if (mouse_report.y == 0) {
  209. mouse_report.y = 1;
  210. }
  211. }
  212. }
  213. if ((tmpmr.v || tmpmr.h) && timer_elapsed(last_timer_w) > (mousekey_wheel_repeat ? mk_wheel_interval : mk_wheel_delay * 10)) {
  214. if (mousekey_wheel_repeat != UINT8_MAX) mousekey_wheel_repeat++;
  215. if (tmpmr.v != 0) mouse_report.v = wheel_unit() * ((tmpmr.v > 0) ? 1 : -1);
  216. if (tmpmr.h != 0) mouse_report.h = wheel_unit() * ((tmpmr.h > 0) ? 1 : -1);
  217. /* diagonal move [1/sqrt(2)] */
  218. if (mouse_report.v && mouse_report.h) {
  219. mouse_report.v = times_inv_sqrt2(mouse_report.v);
  220. if (mouse_report.v == 0) {
  221. mouse_report.v = 1;
  222. }
  223. mouse_report.h = times_inv_sqrt2(mouse_report.h);
  224. if (mouse_report.h == 0) {
  225. mouse_report.h = 1;
  226. }
  227. }
  228. }
  229. if (has_mouse_report_changed(&mouse_report, &tmpmr) || should_mousekey_report_send(&mouse_report)) {
  230. mousekey_send();
  231. }
  232. memcpy(&mouse_report, &tmpmr, sizeof(tmpmr));
  233. }
  234. void mousekey_on(uint8_t code) {
  235. # ifdef MK_KINETIC_SPEED
  236. if (mouse_timer == 0) {
  237. mouse_timer = timer_read();
  238. }
  239. # endif /* #ifdef MK_KINETIC_SPEED */
  240. if (code == KC_MS_UP)
  241. mouse_report.y = move_unit() * -1;
  242. else if (code == KC_MS_DOWN)
  243. mouse_report.y = move_unit();
  244. else if (code == KC_MS_LEFT)
  245. mouse_report.x = move_unit() * -1;
  246. else if (code == KC_MS_RIGHT)
  247. mouse_report.x = move_unit();
  248. else if (code == KC_MS_WH_UP)
  249. mouse_report.v = wheel_unit();
  250. else if (code == KC_MS_WH_DOWN)
  251. mouse_report.v = wheel_unit() * -1;
  252. else if (code == KC_MS_WH_LEFT)
  253. mouse_report.h = wheel_unit() * -1;
  254. else if (code == KC_MS_WH_RIGHT)
  255. mouse_report.h = wheel_unit();
  256. else if (IS_MOUSEKEY_BUTTON(code))
  257. mouse_report.buttons |= 1 << (code - KC_MS_BTN1);
  258. else if (code == KC_MS_ACCEL0)
  259. mousekey_accel |= (1 << 0);
  260. else if (code == KC_MS_ACCEL1)
  261. mousekey_accel |= (1 << 1);
  262. else if (code == KC_MS_ACCEL2)
  263. mousekey_accel |= (1 << 2);
  264. }
  265. void mousekey_off(uint8_t code) {
  266. if (code == KC_MS_UP && mouse_report.y < 0)
  267. mouse_report.y = 0;
  268. else if (code == KC_MS_DOWN && mouse_report.y > 0)
  269. mouse_report.y = 0;
  270. else if (code == KC_MS_LEFT && mouse_report.x < 0)
  271. mouse_report.x = 0;
  272. else if (code == KC_MS_RIGHT && mouse_report.x > 0)
  273. mouse_report.x = 0;
  274. else if (code == KC_MS_WH_UP && mouse_report.v > 0)
  275. mouse_report.v = 0;
  276. else if (code == KC_MS_WH_DOWN && mouse_report.v < 0)
  277. mouse_report.v = 0;
  278. else if (code == KC_MS_WH_LEFT && mouse_report.h < 0)
  279. mouse_report.h = 0;
  280. else if (code == KC_MS_WH_RIGHT && mouse_report.h > 0)
  281. mouse_report.h = 0;
  282. else if (IS_MOUSEKEY_BUTTON(code))
  283. mouse_report.buttons &= ~(1 << (code - KC_MS_BTN1));
  284. else if (code == KC_MS_ACCEL0)
  285. mousekey_accel &= ~(1 << 0);
  286. else if (code == KC_MS_ACCEL1)
  287. mousekey_accel &= ~(1 << 1);
  288. else if (code == KC_MS_ACCEL2)
  289. mousekey_accel &= ~(1 << 2);
  290. if (mouse_report.x == 0 && mouse_report.y == 0) {
  291. mousekey_repeat = 0;
  292. # ifdef MK_KINETIC_SPEED
  293. mouse_timer = 0;
  294. # endif /* #ifdef MK_KINETIC_SPEED */
  295. }
  296. if (mouse_report.v == 0 && mouse_report.h == 0) mousekey_wheel_repeat = 0;
  297. }
  298. #else /* #ifndef MK_3_SPEED */
  299. enum { mkspd_unmod, mkspd_0, mkspd_1, mkspd_2, mkspd_COUNT };
  300. # ifndef MK_MOMENTARY_ACCEL
  301. static uint8_t mk_speed = mkspd_1;
  302. # else
  303. static uint8_t mk_speed = mkspd_unmod;
  304. static uint8_t mkspd_DEFAULT = mkspd_unmod;
  305. # endif
  306. static uint16_t last_timer_c = 0;
  307. static uint16_t last_timer_w = 0;
  308. uint16_t c_offsets[mkspd_COUNT] = {MK_C_OFFSET_UNMOD, MK_C_OFFSET_0, MK_C_OFFSET_1, MK_C_OFFSET_2};
  309. uint16_t c_intervals[mkspd_COUNT] = {MK_C_INTERVAL_UNMOD, MK_C_INTERVAL_0, MK_C_INTERVAL_1, MK_C_INTERVAL_2};
  310. uint16_t w_offsets[mkspd_COUNT] = {MK_W_OFFSET_UNMOD, MK_W_OFFSET_0, MK_W_OFFSET_1, MK_W_OFFSET_2};
  311. uint16_t w_intervals[mkspd_COUNT] = {MK_W_INTERVAL_UNMOD, MK_W_INTERVAL_0, MK_W_INTERVAL_1, MK_W_INTERVAL_2};
  312. void mousekey_task(void) {
  313. // report cursor and scroll movement independently
  314. report_mouse_t tmpmr = mouse_report;
  315. mouse_report.x = 0;
  316. mouse_report.y = 0;
  317. mouse_report.v = 0;
  318. mouse_report.h = 0;
  319. if ((tmpmr.x || tmpmr.y) && timer_elapsed(last_timer_c) > c_intervals[mk_speed]) {
  320. mouse_report.x = tmpmr.x;
  321. mouse_report.y = tmpmr.y;
  322. }
  323. if ((tmpmr.h || tmpmr.v) && timer_elapsed(last_timer_w) > w_intervals[mk_speed]) {
  324. mouse_report.v = tmpmr.v;
  325. mouse_report.h = tmpmr.h;
  326. }
  327. if (has_mouse_report_changed(&mouse_report, &tmpmr) || should_mousekey_report_send(&mouse_report)) {
  328. mousekey_send();
  329. }
  330. memcpy(&mouse_report, &tmpmr, sizeof(tmpmr));
  331. }
  332. void adjust_speed(void) {
  333. uint16_t const c_offset = c_offsets[mk_speed];
  334. uint16_t const w_offset = w_offsets[mk_speed];
  335. if (mouse_report.x > 0) mouse_report.x = c_offset;
  336. if (mouse_report.x < 0) mouse_report.x = c_offset * -1;
  337. if (mouse_report.y > 0) mouse_report.y = c_offset;
  338. if (mouse_report.y < 0) mouse_report.y = c_offset * -1;
  339. if (mouse_report.h > 0) mouse_report.h = w_offset;
  340. if (mouse_report.h < 0) mouse_report.h = w_offset * -1;
  341. if (mouse_report.v > 0) mouse_report.v = w_offset;
  342. if (mouse_report.v < 0) mouse_report.v = w_offset * -1;
  343. // adjust for diagonals
  344. if (mouse_report.x && mouse_report.y) {
  345. mouse_report.x = times_inv_sqrt2(mouse_report.x);
  346. if (mouse_report.x == 0) {
  347. mouse_report.x = 1;
  348. }
  349. mouse_report.y = times_inv_sqrt2(mouse_report.y);
  350. if (mouse_report.y == 0) {
  351. mouse_report.y = 1;
  352. }
  353. }
  354. if (mouse_report.h && mouse_report.v) {
  355. mouse_report.h = times_inv_sqrt2(mouse_report.h);
  356. mouse_report.v = times_inv_sqrt2(mouse_report.v);
  357. }
  358. }
  359. void mousekey_on(uint8_t code) {
  360. uint16_t const c_offset = c_offsets[mk_speed];
  361. uint16_t const w_offset = w_offsets[mk_speed];
  362. uint8_t const old_speed = mk_speed;
  363. if (code == KC_MS_UP)
  364. mouse_report.y = c_offset * -1;
  365. else if (code == KC_MS_DOWN)
  366. mouse_report.y = c_offset;
  367. else if (code == KC_MS_LEFT)
  368. mouse_report.x = c_offset * -1;
  369. else if (code == KC_MS_RIGHT)
  370. mouse_report.x = c_offset;
  371. else if (code == KC_MS_WH_UP)
  372. mouse_report.v = w_offset;
  373. else if (code == KC_MS_WH_DOWN)
  374. mouse_report.v = w_offset * -1;
  375. else if (code == KC_MS_WH_LEFT)
  376. mouse_report.h = w_offset * -1;
  377. else if (code == KC_MS_WH_RIGHT)
  378. mouse_report.h = w_offset;
  379. else if (IS_MOUSEKEY_BUTTON(code))
  380. mouse_report.buttons |= 1 << (code - KC_MS_BTN1);
  381. else if (code == KC_MS_ACCEL0)
  382. mk_speed = mkspd_0;
  383. else if (code == KC_MS_ACCEL1)
  384. mk_speed = mkspd_1;
  385. else if (code == KC_MS_ACCEL2)
  386. mk_speed = mkspd_2;
  387. if (mk_speed != old_speed) adjust_speed();
  388. }
  389. void mousekey_off(uint8_t code) {
  390. # ifdef MK_MOMENTARY_ACCEL
  391. uint8_t const old_speed = mk_speed;
  392. # endif
  393. if (code == KC_MS_UP && mouse_report.y < 0)
  394. mouse_report.y = 0;
  395. else if (code == KC_MS_DOWN && mouse_report.y > 0)
  396. mouse_report.y = 0;
  397. else if (code == KC_MS_LEFT && mouse_report.x < 0)
  398. mouse_report.x = 0;
  399. else if (code == KC_MS_RIGHT && mouse_report.x > 0)
  400. mouse_report.x = 0;
  401. else if (code == KC_MS_WH_UP && mouse_report.v > 0)
  402. mouse_report.v = 0;
  403. else if (code == KC_MS_WH_DOWN && mouse_report.v < 0)
  404. mouse_report.v = 0;
  405. else if (code == KC_MS_WH_LEFT && mouse_report.h < 0)
  406. mouse_report.h = 0;
  407. else if (code == KC_MS_WH_RIGHT && mouse_report.h > 0)
  408. mouse_report.h = 0;
  409. else if (IS_MOUSEKEY_BUTTON(code))
  410. mouse_report.buttons &= ~(1 << (code - KC_MS_BTN1));
  411. # ifdef MK_MOMENTARY_ACCEL
  412. else if (code == KC_MS_ACCEL0)
  413. mk_speed = mkspd_DEFAULT;
  414. else if (code == KC_MS_ACCEL1)
  415. mk_speed = mkspd_DEFAULT;
  416. else if (code == KC_MS_ACCEL2)
  417. mk_speed = mkspd_DEFAULT;
  418. if (mk_speed != old_speed) adjust_speed();
  419. # endif
  420. }
  421. #endif /* #ifndef MK_3_SPEED */
  422. void mousekey_send(void) {
  423. mousekey_debug();
  424. uint16_t time = timer_read();
  425. if (mouse_report.x || mouse_report.y) last_timer_c = time;
  426. if (mouse_report.v || mouse_report.h) last_timer_w = time;
  427. host_mouse_send(&mouse_report);
  428. }
  429. void mousekey_clear(void) {
  430. mouse_report = (report_mouse_t){};
  431. mousekey_repeat = 0;
  432. mousekey_wheel_repeat = 0;
  433. mousekey_accel = 0;
  434. }
  435. static void mousekey_debug(void) {
  436. if (!debug_mouse) return;
  437. print("mousekey [btn|x y v h](rep/acl): [");
  438. print_hex8(mouse_report.buttons);
  439. print("|");
  440. print_decs(mouse_report.x);
  441. print(" ");
  442. print_decs(mouse_report.y);
  443. print(" ");
  444. print_decs(mouse_report.v);
  445. print(" ");
  446. print_decs(mouse_report.h);
  447. print("](");
  448. print_dec(mousekey_repeat);
  449. print("/");
  450. print_dec(mousekey_accel);
  451. print(")\n");
  452. }
  453. report_mouse_t mousekey_get_report(void) {
  454. return mouse_report;
  455. }
  456. bool should_mousekey_report_send(report_mouse_t *mouse_report) {
  457. return mouse_report->x || mouse_report->y || mouse_report->v || mouse_report->h;
  458. }