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.

501 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. uint8_t mk_wheel_interval = MOUSEKEY_WHEEL_INTERVAL;
  64. uint8_t mk_wheel_max_speed = MOUSEKEY_WHEEL_MAX_SPEED;
  65. uint8_t mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX;
  66. # ifndef MK_COMBINED
  67. static uint8_t move_unit(void) {
  68. uint16_t unit;
  69. if (mousekey_accel & (1 << 0)) {
  70. unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed) / 4;
  71. } else if (mousekey_accel & (1 << 1)) {
  72. unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed) / 2;
  73. } else if (mousekey_accel & (1 << 2)) {
  74. unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed);
  75. } else if (mousekey_repeat == 0) {
  76. unit = MOUSEKEY_MOVE_DELTA;
  77. } else if (mousekey_repeat >= mk_time_to_max) {
  78. unit = MOUSEKEY_MOVE_DELTA * mk_max_speed;
  79. } else {
  80. unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed * mousekey_repeat) / mk_time_to_max;
  81. }
  82. return (unit > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : (unit == 0 ? 1 : unit));
  83. }
  84. static uint8_t wheel_unit(void) {
  85. uint16_t unit;
  86. if (mousekey_accel & (1 << 0)) {
  87. unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed) / 4;
  88. } else if (mousekey_accel & (1 << 1)) {
  89. unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed) / 2;
  90. } else if (mousekey_accel & (1 << 2)) {
  91. unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed);
  92. } else if (mousekey_wheel_repeat == 0) {
  93. unit = MOUSEKEY_WHEEL_DELTA;
  94. } else if (mousekey_wheel_repeat >= mk_wheel_time_to_max) {
  95. unit = MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed;
  96. } else {
  97. unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed * mousekey_wheel_repeat) / mk_wheel_time_to_max;
  98. }
  99. return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : (unit == 0 ? 1 : unit));
  100. }
  101. # else /* #ifndef MK_COMBINED */
  102. # ifdef MK_KINETIC_SPEED
  103. /*
  104. * Kinetic movement acceleration algorithm
  105. *
  106. * current speed = I + A * T/50 + A * 0.5 * T^2 | maximum B
  107. *
  108. * T: time since the mouse movement started
  109. * E: mouse events per second (set through MOUSEKEY_INTERVAL, UHK sends 250, the
  110. * pro micro on my Signum 3.0 sends only 125!)
  111. * I: initial speed at time 0
  112. * A: acceleration
  113. * B: base mouse travel speed
  114. */
  115. const uint16_t mk_accelerated_speed = MOUSEKEY_ACCELERATED_SPEED;
  116. const uint16_t mk_base_speed = MOUSEKEY_BASE_SPEED;
  117. const uint16_t mk_decelerated_speed = MOUSEKEY_DECELERATED_SPEED;
  118. const uint16_t mk_initial_speed = MOUSEKEY_INITIAL_SPEED;
  119. static uint8_t move_unit(void) {
  120. float speed = mk_initial_speed;
  121. if (mousekey_accel & ((1 << 0) | (1 << 2))) {
  122. speed = mousekey_accel & (1 << 2) ? mk_accelerated_speed : mk_decelerated_speed;
  123. } else if (mousekey_repeat && mouse_timer) {
  124. const float time_elapsed = timer_elapsed(mouse_timer) / 50;
  125. speed = mk_initial_speed + MOUSEKEY_MOVE_DELTA * time_elapsed + MOUSEKEY_MOVE_DELTA * 0.5 * time_elapsed * time_elapsed;
  126. speed = speed > mk_base_speed ? mk_base_speed : speed;
  127. }
  128. /* convert speed to USB mouse speed 1 to 127 */
  129. speed = (uint8_t)(speed / (1000.0f / mk_interval));
  130. speed = speed < 1 ? 1 : speed;
  131. return speed > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : speed;
  132. }
  133. float mk_wheel_interval = 1000.0f / MOUSEKEY_WHEEL_INITIAL_MOVEMENTS;
  134. static uint8_t wheel_unit(void) {
  135. float speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS;
  136. if (mousekey_accel & ((1 << 0) | (1 << 2))) {
  137. speed = mousekey_accel & (1 << 2) ? MOUSEKEY_WHEEL_ACCELERATED_MOVEMENTS : MOUSEKEY_WHEEL_DECELERATED_MOVEMENTS;
  138. } else if (mousekey_repeat && mouse_timer) {
  139. if (mk_wheel_interval != MOUSEKEY_WHEEL_BASE_MOVEMENTS) {
  140. const float time_elapsed = timer_elapsed(mouse_timer) / 50;
  141. speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS + 1 * time_elapsed + 1 * 0.5 * time_elapsed * time_elapsed;
  142. }
  143. speed = speed > MOUSEKEY_WHEEL_BASE_MOVEMENTS ? MOUSEKEY_WHEEL_BASE_MOVEMENTS : speed;
  144. }
  145. mk_wheel_interval = 1000.0f / speed;
  146. return 1;
  147. }
  148. # else /* #ifndef MK_KINETIC_SPEED */
  149. static uint8_t move_unit(void) {
  150. uint16_t unit;
  151. if (mousekey_accel & (1 << 0)) {
  152. unit = 1;
  153. } else if (mousekey_accel & (1 << 1)) {
  154. unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed) / 2;
  155. } else if (mousekey_accel & (1 << 2)) {
  156. unit = MOUSEKEY_MOVE_MAX;
  157. } else if (mousekey_repeat == 0) {
  158. unit = MOUSEKEY_MOVE_DELTA;
  159. } else if (mousekey_repeat >= mk_time_to_max) {
  160. unit = MOUSEKEY_MOVE_DELTA * mk_max_speed;
  161. } else {
  162. unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed * mousekey_repeat) / mk_time_to_max;
  163. }
  164. return (unit > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : (unit == 0 ? 1 : unit));
  165. }
  166. static uint8_t wheel_unit(void) {
  167. uint16_t unit;
  168. if (mousekey_accel & (1 << 0)) {
  169. unit = 1;
  170. } else if (mousekey_accel & (1 << 1)) {
  171. unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed) / 2;
  172. } else if (mousekey_accel & (1 << 2)) {
  173. unit = MOUSEKEY_WHEEL_MAX;
  174. } else if (mousekey_repeat == 0) {
  175. unit = MOUSEKEY_WHEEL_DELTA;
  176. } else if (mousekey_repeat >= mk_wheel_time_to_max) {
  177. unit = MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed;
  178. } else {
  179. unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed * mousekey_repeat) / mk_wheel_time_to_max;
  180. }
  181. return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : (unit == 0 ? 1 : unit));
  182. }
  183. # endif /* #ifndef MK_KINETIC_SPEED */
  184. # endif /* #ifndef MK_COMBINED */
  185. void mousekey_task(void) {
  186. // report cursor and scroll movement independently
  187. report_mouse_t tmpmr = mouse_report;
  188. mouse_report.x = 0;
  189. mouse_report.y = 0;
  190. mouse_report.v = 0;
  191. mouse_report.h = 0;
  192. if ((tmpmr.x || tmpmr.y) && timer_elapsed(last_timer_c) > (mousekey_repeat ? mk_interval : mk_delay * 10)) {
  193. if (mousekey_repeat != UINT8_MAX) mousekey_repeat++;
  194. if (tmpmr.x != 0) mouse_report.x = move_unit() * ((tmpmr.x > 0) ? 1 : -1);
  195. if (tmpmr.y != 0) mouse_report.y = move_unit() * ((tmpmr.y > 0) ? 1 : -1);
  196. /* diagonal move [1/sqrt(2)] */
  197. if (mouse_report.x && mouse_report.y) {
  198. mouse_report.x = times_inv_sqrt2(mouse_report.x);
  199. if (mouse_report.x == 0) {
  200. mouse_report.x = 1;
  201. }
  202. mouse_report.y = times_inv_sqrt2(mouse_report.y);
  203. if (mouse_report.y == 0) {
  204. mouse_report.y = 1;
  205. }
  206. }
  207. }
  208. if ((tmpmr.v || tmpmr.h) && timer_elapsed(last_timer_w) > (mousekey_wheel_repeat ? mk_wheel_interval : mk_wheel_delay * 10)) {
  209. if (mousekey_wheel_repeat != UINT8_MAX) mousekey_wheel_repeat++;
  210. if (tmpmr.v != 0) mouse_report.v = wheel_unit() * ((tmpmr.v > 0) ? 1 : -1);
  211. if (tmpmr.h != 0) mouse_report.h = wheel_unit() * ((tmpmr.h > 0) ? 1 : -1);
  212. /* diagonal move [1/sqrt(2)] */
  213. if (mouse_report.v && mouse_report.h) {
  214. mouse_report.v = times_inv_sqrt2(mouse_report.v);
  215. if (mouse_report.v == 0) {
  216. mouse_report.v = 1;
  217. }
  218. mouse_report.h = times_inv_sqrt2(mouse_report.h);
  219. if (mouse_report.h == 0) {
  220. mouse_report.h = 1;
  221. }
  222. }
  223. }
  224. if (has_mouse_report_changed(&mouse_report, &tmpmr) || should_mousekey_report_send(&mouse_report)) {
  225. mousekey_send();
  226. }
  227. memcpy(&mouse_report, &tmpmr, sizeof(tmpmr));
  228. }
  229. void mousekey_on(uint8_t code) {
  230. # ifdef MK_KINETIC_SPEED
  231. if (mouse_timer == 0) {
  232. mouse_timer = timer_read();
  233. }
  234. # endif /* #ifdef MK_KINETIC_SPEED */
  235. if (code == KC_MS_UP)
  236. mouse_report.y = move_unit() * -1;
  237. else if (code == KC_MS_DOWN)
  238. mouse_report.y = move_unit();
  239. else if (code == KC_MS_LEFT)
  240. mouse_report.x = move_unit() * -1;
  241. else if (code == KC_MS_RIGHT)
  242. mouse_report.x = move_unit();
  243. else if (code == KC_MS_WH_UP)
  244. mouse_report.v = wheel_unit();
  245. else if (code == KC_MS_WH_DOWN)
  246. mouse_report.v = wheel_unit() * -1;
  247. else if (code == KC_MS_WH_LEFT)
  248. mouse_report.h = wheel_unit() * -1;
  249. else if (code == KC_MS_WH_RIGHT)
  250. mouse_report.h = wheel_unit();
  251. else if (IS_MOUSEKEY_BUTTON(code))
  252. mouse_report.buttons |= 1 << (code - KC_MS_BTN1);
  253. else if (code == KC_MS_ACCEL0)
  254. mousekey_accel |= (1 << 0);
  255. else if (code == KC_MS_ACCEL1)
  256. mousekey_accel |= (1 << 1);
  257. else if (code == KC_MS_ACCEL2)
  258. mousekey_accel |= (1 << 2);
  259. }
  260. void mousekey_off(uint8_t code) {
  261. if (code == KC_MS_UP && mouse_report.y < 0)
  262. mouse_report.y = 0;
  263. else if (code == KC_MS_DOWN && mouse_report.y > 0)
  264. mouse_report.y = 0;
  265. else if (code == KC_MS_LEFT && mouse_report.x < 0)
  266. mouse_report.x = 0;
  267. else if (code == KC_MS_RIGHT && mouse_report.x > 0)
  268. mouse_report.x = 0;
  269. else if (code == KC_MS_WH_UP && mouse_report.v > 0)
  270. mouse_report.v = 0;
  271. else if (code == KC_MS_WH_DOWN && mouse_report.v < 0)
  272. mouse_report.v = 0;
  273. else if (code == KC_MS_WH_LEFT && mouse_report.h < 0)
  274. mouse_report.h = 0;
  275. else if (code == KC_MS_WH_RIGHT && mouse_report.h > 0)
  276. mouse_report.h = 0;
  277. else if (IS_MOUSEKEY_BUTTON(code))
  278. mouse_report.buttons &= ~(1 << (code - KC_MS_BTN1));
  279. else if (code == KC_MS_ACCEL0)
  280. mousekey_accel &= ~(1 << 0);
  281. else if (code == KC_MS_ACCEL1)
  282. mousekey_accel &= ~(1 << 1);
  283. else if (code == KC_MS_ACCEL2)
  284. mousekey_accel &= ~(1 << 2);
  285. if (mouse_report.x == 0 && mouse_report.y == 0) {
  286. mousekey_repeat = 0;
  287. # ifdef MK_KINETIC_SPEED
  288. mouse_timer = 0;
  289. # endif /* #ifdef MK_KINETIC_SPEED */
  290. }
  291. if (mouse_report.v == 0 && mouse_report.h == 0) mousekey_wheel_repeat = 0;
  292. }
  293. #else /* #ifndef MK_3_SPEED */
  294. enum { mkspd_unmod, mkspd_0, mkspd_1, mkspd_2, mkspd_COUNT };
  295. # ifndef MK_MOMENTARY_ACCEL
  296. static uint8_t mk_speed = mkspd_1;
  297. # else
  298. static uint8_t mk_speed = mkspd_unmod;
  299. static uint8_t mkspd_DEFAULT = mkspd_unmod;
  300. # endif
  301. static uint16_t last_timer_c = 0;
  302. static uint16_t last_timer_w = 0;
  303. uint16_t c_offsets[mkspd_COUNT] = {MK_C_OFFSET_UNMOD, MK_C_OFFSET_0, MK_C_OFFSET_1, MK_C_OFFSET_2};
  304. uint16_t c_intervals[mkspd_COUNT] = {MK_C_INTERVAL_UNMOD, MK_C_INTERVAL_0, MK_C_INTERVAL_1, MK_C_INTERVAL_2};
  305. uint16_t w_offsets[mkspd_COUNT] = {MK_W_OFFSET_UNMOD, MK_W_OFFSET_0, MK_W_OFFSET_1, MK_W_OFFSET_2};
  306. uint16_t w_intervals[mkspd_COUNT] = {MK_W_INTERVAL_UNMOD, MK_W_INTERVAL_0, MK_W_INTERVAL_1, MK_W_INTERVAL_2};
  307. void mousekey_task(void) {
  308. // report cursor and scroll movement independently
  309. report_mouse_t tmpmr = mouse_report;
  310. mouse_report.x = 0;
  311. mouse_report.y = 0;
  312. mouse_report.v = 0;
  313. mouse_report.h = 0;
  314. if ((tmpmr.x || tmpmr.y) && timer_elapsed(last_timer_c) > c_intervals[mk_speed]) {
  315. mouse_report.x = tmpmr.x;
  316. mouse_report.y = tmpmr.y;
  317. }
  318. if ((tmpmr.h || tmpmr.v) && timer_elapsed(last_timer_w) > w_intervals[mk_speed]) {
  319. mouse_report.v = tmpmr.v;
  320. mouse_report.h = tmpmr.h;
  321. }
  322. if (has_mouse_report_changed(&mouse_report, &tmpmr) || should_mousekey_report_send(&mouse_report)) {
  323. mousekey_send();
  324. }
  325. memcpy(&mouse_report, &tmpmr, sizeof(tmpmr));
  326. }
  327. void adjust_speed(void) {
  328. uint16_t const c_offset = c_offsets[mk_speed];
  329. uint16_t const w_offset = w_offsets[mk_speed];
  330. if (mouse_report.x > 0) mouse_report.x = c_offset;
  331. if (mouse_report.x < 0) mouse_report.x = c_offset * -1;
  332. if (mouse_report.y > 0) mouse_report.y = c_offset;
  333. if (mouse_report.y < 0) mouse_report.y = c_offset * -1;
  334. if (mouse_report.h > 0) mouse_report.h = w_offset;
  335. if (mouse_report.h < 0) mouse_report.h = w_offset * -1;
  336. if (mouse_report.v > 0) mouse_report.v = w_offset;
  337. if (mouse_report.v < 0) mouse_report.v = w_offset * -1;
  338. // adjust for diagonals
  339. if (mouse_report.x && mouse_report.y) {
  340. mouse_report.x = times_inv_sqrt2(mouse_report.x);
  341. if (mouse_report.x == 0) {
  342. mouse_report.x = 1;
  343. }
  344. mouse_report.y = times_inv_sqrt2(mouse_report.y);
  345. if (mouse_report.y == 0) {
  346. mouse_report.y = 1;
  347. }
  348. }
  349. if (mouse_report.h && mouse_report.v) {
  350. mouse_report.h = times_inv_sqrt2(mouse_report.h);
  351. mouse_report.v = times_inv_sqrt2(mouse_report.v);
  352. }
  353. }
  354. void mousekey_on(uint8_t code) {
  355. uint16_t const c_offset = c_offsets[mk_speed];
  356. uint16_t const w_offset = w_offsets[mk_speed];
  357. uint8_t const old_speed = mk_speed;
  358. if (code == KC_MS_UP)
  359. mouse_report.y = c_offset * -1;
  360. else if (code == KC_MS_DOWN)
  361. mouse_report.y = c_offset;
  362. else if (code == KC_MS_LEFT)
  363. mouse_report.x = c_offset * -1;
  364. else if (code == KC_MS_RIGHT)
  365. mouse_report.x = c_offset;
  366. else if (code == KC_MS_WH_UP)
  367. mouse_report.v = w_offset;
  368. else if (code == KC_MS_WH_DOWN)
  369. mouse_report.v = w_offset * -1;
  370. else if (code == KC_MS_WH_LEFT)
  371. mouse_report.h = w_offset * -1;
  372. else if (code == KC_MS_WH_RIGHT)
  373. mouse_report.h = w_offset;
  374. else if (IS_MOUSEKEY_BUTTON(code))
  375. mouse_report.buttons |= 1 << (code - KC_MS_BTN1);
  376. else if (code == KC_MS_ACCEL0)
  377. mk_speed = mkspd_0;
  378. else if (code == KC_MS_ACCEL1)
  379. mk_speed = mkspd_1;
  380. else if (code == KC_MS_ACCEL2)
  381. mk_speed = mkspd_2;
  382. if (mk_speed != old_speed) adjust_speed();
  383. }
  384. void mousekey_off(uint8_t code) {
  385. # ifdef MK_MOMENTARY_ACCEL
  386. uint8_t const old_speed = mk_speed;
  387. # endif
  388. if (code == KC_MS_UP && mouse_report.y < 0)
  389. mouse_report.y = 0;
  390. else if (code == KC_MS_DOWN && mouse_report.y > 0)
  391. mouse_report.y = 0;
  392. else if (code == KC_MS_LEFT && mouse_report.x < 0)
  393. mouse_report.x = 0;
  394. else if (code == KC_MS_RIGHT && mouse_report.x > 0)
  395. mouse_report.x = 0;
  396. else if (code == KC_MS_WH_UP && mouse_report.v > 0)
  397. mouse_report.v = 0;
  398. else if (code == KC_MS_WH_DOWN && mouse_report.v < 0)
  399. mouse_report.v = 0;
  400. else if (code == KC_MS_WH_LEFT && mouse_report.h < 0)
  401. mouse_report.h = 0;
  402. else if (code == KC_MS_WH_RIGHT && mouse_report.h > 0)
  403. mouse_report.h = 0;
  404. else if (IS_MOUSEKEY_BUTTON(code))
  405. mouse_report.buttons &= ~(1 << (code - KC_MS_BTN1));
  406. # ifdef MK_MOMENTARY_ACCEL
  407. else if (code == KC_MS_ACCEL0)
  408. mk_speed = mkspd_DEFAULT;
  409. else if (code == KC_MS_ACCEL1)
  410. mk_speed = mkspd_DEFAULT;
  411. else if (code == KC_MS_ACCEL2)
  412. mk_speed = mkspd_DEFAULT;
  413. if (mk_speed != old_speed) adjust_speed();
  414. # endif
  415. }
  416. #endif /* #ifndef MK_3_SPEED */
  417. void mousekey_send(void) {
  418. mousekey_debug();
  419. uint16_t time = timer_read();
  420. if (mouse_report.x || mouse_report.y) last_timer_c = time;
  421. if (mouse_report.v || mouse_report.h) last_timer_w = time;
  422. host_mouse_send(&mouse_report);
  423. }
  424. void mousekey_clear(void) {
  425. mouse_report = (report_mouse_t){};
  426. mousekey_repeat = 0;
  427. mousekey_wheel_repeat = 0;
  428. mousekey_accel = 0;
  429. }
  430. static void mousekey_debug(void) {
  431. if (!debug_mouse) return;
  432. print("mousekey [btn|x y v h](rep/acl): [");
  433. print_hex8(mouse_report.buttons);
  434. print("|");
  435. print_decs(mouse_report.x);
  436. print(" ");
  437. print_decs(mouse_report.y);
  438. print(" ");
  439. print_decs(mouse_report.v);
  440. print(" ");
  441. print_decs(mouse_report.h);
  442. print("](");
  443. print_dec(mousekey_repeat);
  444. print("/");
  445. print_dec(mousekey_accel);
  446. print(")\n");
  447. }
  448. report_mouse_t mousekey_get_report(void) {
  449. return mouse_report;
  450. }
  451. bool should_mousekey_report_send(report_mouse_t *mouse_report) {
  452. return mouse_report->x || mouse_report->y || mouse_report->v || mouse_report->h;
  453. }