|
| 1 | +/* Copyright 2021 Colin Lam (Ploopy Corporation) |
| 2 | + * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <[email protected]> |
| 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 | + |
| 21 | +// safe range starts at `PLOOPY_SAFE_RANGE` instead. |
| 22 | +uint8_t scroll_enabled = 0; |
| 23 | +uint8_t lock_state = 0; |
| 24 | +int16_t delta_x = 0; |
| 25 | +int16_t delta_y = 0; |
| 26 | + |
| 27 | +void process_mouse_user(report_mouse_t *mouse_report, int16_t x, int16_t y) { |
| 28 | + if (scroll_enabled) { |
| 29 | + delta_x += x; |
| 30 | + delta_y += y; |
| 31 | + |
| 32 | + if (delta_x > 60) { |
| 33 | + mouse_report->h = 1; |
| 34 | + delta_x = 0; |
| 35 | + } else if (delta_x < -60) { |
| 36 | + mouse_report->h = -1; |
| 37 | + delta_x = 0; |
| 38 | + } |
| 39 | + |
| 40 | + if (delta_y > 15) { |
| 41 | + mouse_report->v = -1; |
| 42 | + delta_y = 0; |
| 43 | + } else if (delta_y < -15) { |
| 44 | + mouse_report->v = 1; |
| 45 | + delta_y = 0; |
| 46 | + } |
| 47 | + } else { |
| 48 | + mouse_report->x = x; |
| 49 | + mouse_report->y = y; |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +void keyboard_post_init_user(void) { |
| 54 | + lock_state = host_keyboard_led_state().num_lock; |
| 55 | +} |
| 56 | + |
| 57 | +bool led_update_user(led_t led_state) { |
| 58 | + static uint8_t lock_count = 0; |
| 59 | + static uint16_t scroll_timer = 0; |
| 60 | + |
| 61 | + if (timer_elapsed(scroll_timer) > 25) { |
| 62 | + scroll_timer = timer_read(); |
| 63 | + lock_count = 0; |
| 64 | + } |
| 65 | + |
| 66 | + if (led_state.num_lock != lock_state) { |
| 67 | + lock_count++; |
| 68 | + |
| 69 | + if (lock_count == 2) { |
| 70 | + scroll_enabled = !scroll_enabled; |
| 71 | + lock_count = 0; |
| 72 | + delta_x = 0; |
| 73 | + delta_y = 0; |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + lock_state = led_state.num_lock; |
| 78 | + return true; |
| 79 | +} |
0 commit comments