keymap.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* Copyright 2021 Colin Lam (Ploopy Corporation)
  2. * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
  3. * Copyright 2019 Sunjun Kim
  4. * Copyright 2019 Hiroyuki Okada
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include QMK_KEYBOARD_H
  20. // safe range starts at `PLOOPY_SAFE_RANGE` instead.
  21. uint8_t scroll_enabled = 0;
  22. uint8_t lock_state = 0;
  23. int16_t delta_x = 0;
  24. int16_t delta_y = 0;
  25. void process_mouse_user(report_mouse_t *mouse_report, int16_t x, int16_t y) {
  26. if (scroll_enabled) {
  27. delta_x += x;
  28. delta_y += y;
  29. if (delta_x > 60) {
  30. mouse_report->h = 1;
  31. delta_x = 0;
  32. } else if (delta_x < -60) {
  33. mouse_report->h = -1;
  34. delta_x = 0;
  35. }
  36. if (delta_y > 15) {
  37. mouse_report->v = -1;
  38. delta_y = 0;
  39. } else if (delta_y < -15) {
  40. mouse_report->v = 1;
  41. delta_y = 0;
  42. }
  43. } else {
  44. mouse_report->x = x;
  45. mouse_report->y = y;
  46. }
  47. }
  48. void keyboard_post_init_user(void) {
  49. lock_state = host_keyboard_led_state().num_lock;
  50. }
  51. bool led_update_user(led_t led_state) {
  52. static uint8_t lock_count = 0;
  53. static uint16_t scroll_timer = 0;
  54. if (timer_elapsed(scroll_timer) > 25) {
  55. scroll_timer = timer_read();
  56. lock_count = 0;
  57. }
  58. if (led_state.num_lock != lock_state) {
  59. lock_count++;
  60. if (lock_count == 2) {
  61. scroll_enabled = !scroll_enabled;
  62. lock_count = 0;
  63. delta_x = 0;
  64. delta_y = 0;
  65. }
  66. }
  67. lock_state = led_state.num_lock;
  68. return true;
  69. }