aboutsummaryrefslogtreecommitdiff
path: root/keyboards/ploopyco/mouse/mouse.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/ploopyco/mouse/mouse.c')
-rw-r--r--keyboards/ploopyco/mouse/mouse.c117
1 files changed, 24 insertions, 93 deletions
diff --git a/keyboards/ploopyco/mouse/mouse.c b/keyboards/ploopyco/mouse/mouse.c
index 0bf96a20f..1b00ef3b7 100644
--- a/keyboards/ploopyco/mouse/mouse.c
+++ b/keyboards/ploopyco/mouse/mouse.c
@@ -31,7 +31,8 @@
31# define OPT_SCALE 1 // Multiplier for wheel 31# define OPT_SCALE 1 // Multiplier for wheel
32#endif 32#endif
33#ifndef PLOOPY_DPI_OPTIONS 33#ifndef PLOOPY_DPI_OPTIONS
34# define PLOOPY_DPI_OPTIONS { 1200, 1600, 2400 } 34# define PLOOPY_DPI_OPTIONS \
35 { 1200, 1600, 2400 }
35# ifndef PLOOPY_DPI_DEFAULT 36# ifndef PLOOPY_DPI_DEFAULT
36# define PLOOPY_DPI_DEFAULT 1 37# define PLOOPY_DPI_DEFAULT 1
37# endif 38# endif
@@ -40,10 +41,10 @@
40# define PLOOPY_DPI_DEFAULT 0 41# define PLOOPY_DPI_DEFAULT 0
41#endif 42#endif
42#ifndef PLOOPY_DRAGSCROLL_DPI 43#ifndef PLOOPY_DRAGSCROLL_DPI
43# define PLOOPY_DRAGSCROLL_DPI 100 // Fixed-DPI Drag Scroll 44# define PLOOPY_DRAGSCROLL_DPI 100 // Fixed-DPI Drag Scroll
44#endif 45#endif
45#ifndef PLOOPY_DRAGSCROLL_MULTIPLIER 46#ifndef PLOOPY_DRAGSCROLL_MULTIPLIER
46# define PLOOPY_DRAGSCROLL_MULTIPLIER 0.75 // Variable-DPI Drag Scroll 47# define PLOOPY_DRAGSCROLL_MULTIPLIER 0.75 // Variable-DPI Drag Scroll
47#endif 48#endif
48 49
49keyboard_config_t keyboard_config; 50keyboard_config_t keyboard_config;
@@ -65,13 +66,7 @@ uint8_t OptLowPin = OPT_ENC1;
65bool debug_encoder = false; 66bool debug_encoder = false;
66bool is_drag_scroll = false; 67bool is_drag_scroll = false;
67 68
68__attribute__((weak)) void process_wheel_user(report_mouse_t* mouse_report, int16_t h, int16_t v) { 69void process_wheel(report_mouse_t* mouse_report) {
69 mouse_report->h = h;
70 mouse_report->v = v;
71}
72
73__attribute__((weak)) void process_wheel(report_mouse_t* mouse_report) {
74 // TODO: Replace this with interrupt driven code, polling is S L O W
75 // Lovingly ripped from the Ploopy Source 70 // Lovingly ripped from the Ploopy Source
76 71
77 // If the mouse wheel was just released, do not scroll. 72 // If the mouse wheel was just released, do not scroll.
@@ -99,56 +94,25 @@ __attribute__((weak)) void process_wheel(report_mouse_t* mouse_report) {
99 int dir = opt_encoder_handler(p1, p2); 94 int dir = opt_encoder_handler(p1, p2);
100 95
101 if (dir == 0) return; 96 if (dir == 0) return;
102 process_wheel_user(mouse_report, mouse_report->h, (int)(mouse_report->v + (dir * OPT_SCALE))); 97 mouse_report->v = (int8_t)(dir * OPT_SCALE);
103}
104
105__attribute__((weak)) void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y) {
106 mouse_report->x = x;
107 mouse_report->y = y;
108} 98}
109 99
110__attribute__((weak)) void process_mouse(report_mouse_t* mouse_report) { 100__attribute__((weak)) report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) {
111 report_pmw_t data = pmw_read_burst(); 101 process_wheel(&mouse_report);
112 if (data.isOnSurface && data.isMotion) {
113 // Reset timer if stopped moving
114 if (!data.isMotion) {
115 if (MotionStart != 0) MotionStart = 0;
116 return;
117 }
118
119 // Set timer if new motion
120 if ((MotionStart == 0) && data.isMotion) {
121 if (debug_mouse) dprintf("Starting motion.\n");
122 MotionStart = timer_read();
123 }
124 102
125 if (debug_mouse) { 103 if (is_drag_scroll) {
126 dprintf("Delt] d: %d t: %u\n", abs(data.dx) + abs(data.dy), MotionStart); 104 mouse_report.h = mouse_report.x;
127 } 105#ifdef PLOOPY_DRAGSCROLL_INVERT
128 if (debug_mouse) { 106 // Invert vertical scroll direction
129 dprintf("Pre ] X: %d, Y: %d\n", data.dx, data.dy); 107 mouse_report.v = -mouse_report.y;
130 }
131#if defined(PROFILE_LINEAR)
132 float scale = float(timer_elaspsed(MotionStart)) / 1000.0;
133 data.dx *= scale;
134 data.dy *= scale;
135#elif defined(PROFILE_INVERSE)
136 // TODO
137#else 108#else
138 // no post processing 109 mouse_report.v = mouse_report.y;
139#endif 110#endif
140 // apply multiplier 111 mouse_report.x = 0;
141 // data.dx *= mouse_multiplier; 112 mouse_report.y = 0;
142 // data.dy *= mouse_multiplier;
143
144 // Wrap to HID size
145 data.dx = constrain(data.dx, -127, 127);
146 data.dy = constrain(data.dy, -127, 127);
147 if (debug_mouse) dprintf("Cons] X: %d, Y: %d\n", data.dx, data.dy);
148 // dprintf("Elapsed:%u, X: %f Y: %\n", i, pgm_read_byte(firmware_data+i));
149
150 process_mouse_user(mouse_report, data.dx, data.dy);
151 } 113 }
114
115 return pointing_device_task_user(mouse_report);
152} 116}
153 117
154bool process_record_kb(uint16_t keycode, keyrecord_t* record) { 118bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
@@ -169,7 +133,7 @@ bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
169 if (keycode == DPI_CONFIG && record->event.pressed) { 133 if (keycode == DPI_CONFIG && record->event.pressed) {
170 keyboard_config.dpi_config = (keyboard_config.dpi_config + 1) % DPI_OPTION_SIZE; 134 keyboard_config.dpi_config = (keyboard_config.dpi_config + 1) % DPI_OPTION_SIZE;
171 eeconfig_update_kb(keyboard_config.raw); 135 eeconfig_update_kb(keyboard_config.raw);
172 pmw_set_cpi(dpi_array[keyboard_config.dpi_config]); 136 pointing_device_set_cpi(dpi_array[keyboard_config.dpi_config]);
173 } 137 }
174 138
175 if (keycode == DRAG_SCROLL) { 139 if (keycode == DRAG_SCROLL) {
@@ -180,9 +144,9 @@ bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
180 is_drag_scroll ^= 1; 144 is_drag_scroll ^= 1;
181 } 145 }
182#ifdef PLOOPY_DRAGSCROLL_FIXED 146#ifdef PLOOPY_DRAGSCROLL_FIXED
183 pmw_set_cpi(is_drag_scroll ? PLOOPY_DRAGSCROLL_DPI : dpi_array[keyboard_config.dpi_config]); 147 pointing_device_set_cpi(is_drag_scroll ? PLOOPY_DRAGSCROLL_DPI : dpi_array[keyboard_config.dpi_config]);
184#else 148#else
185 pmw_set_cpi(is_drag_scroll ? (dpi_array[keyboard_config.dpi_config] * PLOOPY_DRAGSCROLL_MULTIPLIER) : dpi_array[keyboard_config.dpi_config]); 149 pointing_device_set_cpi(is_drag_scroll ? (dpi_array[keyboard_config.dpi_config] * PLOOPY_DRAGSCROLL_MULTIPLIER) : dpi_array[keyboard_config.dpi_config]);
186#endif 150#endif
187 } 151 }
188 152
@@ -194,11 +158,7 @@ bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
194#ifndef MOUSEKEY_ENABLE 158#ifndef MOUSEKEY_ENABLE
195 if (IS_MOUSEKEY_BUTTON(keycode)) { 159 if (IS_MOUSEKEY_BUTTON(keycode)) {
196 report_mouse_t currentReport = pointing_device_get_report(); 160 report_mouse_t currentReport = pointing_device_get_report();
197 if (record->event.pressed) { 161 currentReport.buttons = pointing_device_handle_buttons(currentReport.buttons, record->event.pressed, keycode - KC_MS_BTN1);
198 currentReport.buttons |= 1 << (keycode - KC_MS_BTN1);
199 } else {
200 currentReport.buttons &= ~(1 << (keycode - KC_MS_BTN1));
201 }
202 pointing_device_set_report(currentReport); 162 pointing_device_set_report(currentReport);
203 pointing_device_send(); 163 pointing_device_send();
204 } 164 }
@@ -240,35 +200,12 @@ void keyboard_pre_init_kb(void) {
240 keyboard_pre_init_user(); 200 keyboard_pre_init_user();
241} 201}
242 202
243void pointing_device_init(void) { 203void pointing_device_init_kb(void) {
244 // initialize ball sensor 204 pointing_device_set_cpi(dpi_array[keyboard_config.dpi_config]);
245 pmw_spi_init();
246 // initialize the scroll wheel's optical encoder 205 // initialize the scroll wheel's optical encoder
247 opt_encoder_init(); 206 opt_encoder_init();
248} 207}
249 208
250
251void pointing_device_task(void) {
252 report_mouse_t mouse_report = pointing_device_get_report();
253 process_wheel(&mouse_report);
254 process_mouse(&mouse_report);
255
256 if (is_drag_scroll) {
257 mouse_report.h = mouse_report.x;
258#ifdef PLOOPY_DRAGSCROLL_INVERT
259 // Invert vertical scroll direction
260 mouse_report.v = -mouse_report.y;
261#else
262 mouse_report.v = mouse_report.y;
263#endif
264 mouse_report.x = 0;
265 mouse_report.y = 0;
266 }
267
268 pointing_device_set_report(mouse_report);
269 pointing_device_send();
270}
271
272void eeconfig_init_kb(void) { 209void eeconfig_init_kb(void) {
273 keyboard_config.dpi_config = PLOOPY_DPI_DEFAULT; 210 keyboard_config.dpi_config = PLOOPY_DPI_DEFAULT;
274 eeconfig_update_kb(keyboard_config.raw); 211 eeconfig_update_kb(keyboard_config.raw);
@@ -284,9 +221,3 @@ void matrix_init_kb(void) {
284 } 221 }
285 matrix_init_user(); 222 matrix_init_user();
286} 223}
287
288void keyboard_post_init_kb(void) {
289 pmw_set_cpi(dpi_array[keyboard_config.dpi_config]);
290
291 keyboard_post_init_user();
292}