aboutsummaryrefslogtreecommitdiff
path: root/keyboards/ploopyco
diff options
context:
space:
mode:
authorDrashna Jaelre <drashna@live.com>2021-02-14 20:09:24 -0800
committerGitHub <noreply@github.com>2021-02-14 20:09:24 -0800
commite768fb83bdf1bc292cefc9f3f70cb1597c3108fc (patch)
tree923d17e5a01a8553e2d4b7b60f6b21540424023b /keyboards/ploopyco
parent9ee12820197f38f6618b78f92481f3ffd2d8b7e5 (diff)
downloadqmk_firmware-e768fb83bdf1bc292cefc9f3f70cb1597c3108fc.tar.gz
qmk_firmware-e768fb83bdf1bc292cefc9f3f70cb1597c3108fc.zip
[Keyboard] PloopyCo VIA updates (#11290)
Co-authored-by: ridingqwerty <george.g.koenig@gmail.com> Co-authored-by: Glen D'souza <gdsouza@linuxmail.org>
Diffstat (limited to 'keyboards/ploopyco')
-rw-r--r--keyboards/ploopyco/mouse/keymaps/drag_scroll/keymap.c43
-rw-r--r--keyboards/ploopyco/mouse/keymaps/via/keymap.c2
-rw-r--r--keyboards/ploopyco/mouse/mouse.c66
-rw-r--r--keyboards/ploopyco/mouse/mouse.h10
-rw-r--r--keyboards/ploopyco/mouse/rules.mk6
-rw-r--r--keyboards/ploopyco/trackball/keymaps/drag_scroll/keymap.c36
-rw-r--r--keyboards/ploopyco/trackball/rev1/readme.md4
-rw-r--r--keyboards/ploopyco/trackball/rules.mk6
-rw-r--r--keyboards/ploopyco/trackball/trackball.c65
-rw-r--r--keyboards/ploopyco/trackball/trackball.h18
10 files changed, 142 insertions, 114 deletions
diff --git a/keyboards/ploopyco/mouse/keymaps/drag_scroll/keymap.c b/keyboards/ploopyco/mouse/keymaps/drag_scroll/keymap.c
index 438e2406f..da328fff0 100644
--- a/keyboards/ploopyco/mouse/keymaps/drag_scroll/keymap.c
+++ b/keyboards/ploopyco/mouse/keymaps/drag_scroll/keymap.c
@@ -17,46 +17,11 @@
17 */ 17 */
18#include QMK_KEYBOARD_H 18#include QMK_KEYBOARD_H
19 19
20// used for tracking the state
21bool is_drag_scroll = false;
22
23enum custom_keycodes {
24 DRAG_SCROLL = PLOOPY_SAFE_RANGE,
25};
26
27 20
28const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { 21const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
29 [0] = LAYOUT(/* Base */ 22 [0] = LAYOUT(/* Base */
30 C(KC_C), KC_BTN1, KC_BTN3, KC_BTN2, C(KC_V), KC_BTN4, KC_BTN5, DPI_CONFIG) 23 C(KC_C), KC_BTN1, KC_BTN3, LT(1, KC_BTN2), C(KC_V), KC_BTN4, KC_BTN5, DPI_CONFIG),
31}; 24 [1] = LAYOUT(/* Base */
25 _______, DRAG_SCROLL, _______, _______, _______, _______, _______, RESET),
32 26
33 27};
34bool process_record_user(uint16_t keycode, keyrecord_t *record) {
35 switch (keycode) {
36 case DRAG_SCROLL:
37 if (record->event.pressed) {
38 // this toggles the state each time you tap it
39 is_drag_scroll ^= 1;
40 }
41 break;
42 }
43 return true;
44}
45
46// The real magic is here.
47// This function is called to translate the processed sensor movement
48// from the mouse sensor and translates it into x and y movement for
49// the mouse report. Normally. So if "drag scroll" is toggled on,
50// moving the ball scrolls instead. You could remove the x or y here
51// to only scroll in one direction, if you wanted, as well. In fact,
52// there is no reason that you need to send this to the mouse report.
53// You could have it register a key, instead.
54void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y) {
55 if (is_drag_scroll) {
56 mouse_report->h = x;
57 mouse_report->v = y;
58 } else {
59 mouse_report->x = x;
60 mouse_report->y = y;
61 }
62}
diff --git a/keyboards/ploopyco/mouse/keymaps/via/keymap.c b/keyboards/ploopyco/mouse/keymaps/via/keymap.c
index cd8b7f6c6..dd5e7eb5a 100644
--- a/keyboards/ploopyco/mouse/keymaps/via/keymap.c
+++ b/keyboards/ploopyco/mouse/keymaps/via/keymap.c
@@ -18,7 +18,7 @@
18#include QMK_KEYBOARD_H 18#include QMK_KEYBOARD_H
19 19
20const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { 20const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
21 [0] = LAYOUT(C(KC_C), KC_BTN1, KC_BTN3, KC_BTN2, C(KC_V), KC_BTN4, KC_BTN5, C(KC_Z)), 21 [0] = LAYOUT(C(KC_C), KC_BTN1, KC_BTN3, KC_BTN2, C(KC_V), KC_BTN4, KC_BTN5, DPI_CONFIG),
22 [1] = LAYOUT(_______, _______, _______, _______, _______, _______, _______, _______), 22 [1] = LAYOUT(_______, _______, _______, _______, _______, _______, _______, _______),
23 [2] = LAYOUT(_______, _______, _______, _______, _______, _______, _______, _______), 23 [2] = LAYOUT(_______, _______, _______, _______, _______, _______, _______, _______),
24 [3] = LAYOUT(_______, _______, _______, _______, _______, _______, _______, _______), 24 [3] = LAYOUT(_______, _______, _______, _______, _______, _______, _______, _______),
diff --git a/keyboards/ploopyco/mouse/mouse.c b/keyboards/ploopyco/mouse/mouse.c
index 788a0a1f0..1a1e5648b 100644
--- a/keyboards/ploopyco/mouse/mouse.c
+++ b/keyboards/ploopyco/mouse/mouse.c
@@ -39,9 +39,15 @@
39#ifndef PLOOPY_DPI_DEFAULT 39#ifndef PLOOPY_DPI_DEFAULT
40# define PLOOPY_DPI_DEFAULT 0 40# define PLOOPY_DPI_DEFAULT 0
41#endif 41#endif
42#ifndef PLOOPY_DRAGSCROLL_DPI
43# define PLOOPY_DRAGSCROLL_DPI 100 // Fixed-DPI Drag Scroll
44#endif
45#ifndef PLOOPY_DRAGSCROLL_MULTIPLIER
46# define PLOOPY_DRAGSCROLL_MULTIPLIER 0.75 // Variable-DPI Drag Scroll
47#endif
42 48
43keyboard_config_t keyboard_config; 49keyboard_config_t keyboard_config;
44uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS; 50uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS;
45#define DPI_OPTION_SIZE (sizeof(dpi_array) / sizeof(uint16_t)) 51#define DPI_OPTION_SIZE (sizeof(dpi_array) / sizeof(uint16_t))
46 52
47// TODO: Implement libinput profiles 53// TODO: Implement libinput profiles
@@ -57,6 +63,7 @@ uint16_t lastScroll = 0; // Previous confirmed wheel event
57uint16_t lastMidClick = 0; // Stops scrollwheel from being read if it was pressed 63uint16_t lastMidClick = 0; // Stops scrollwheel from being read if it was pressed
58uint8_t OptLowPin = OPT_ENC1; 64uint8_t OptLowPin = OPT_ENC1;
59bool debug_encoder = false; 65bool debug_encoder = false;
66bool is_drag_scroll = false;
60 67
61__attribute__((weak)) void process_wheel_user(report_mouse_t* mouse_report, int16_t h, int16_t v) { 68__attribute__((weak)) void process_wheel_user(report_mouse_t* mouse_report, int16_t h, int16_t v) {
62 mouse_report->h = h; 69 mouse_report->h = h;
@@ -151,17 +158,34 @@ bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
151 158
152 // Update Timer to prevent accidental scrolls 159 // Update Timer to prevent accidental scrolls
153 if ((record->event.key.col == 1) && (record->event.key.row == 0)) { 160 if ((record->event.key.col == 1) && (record->event.key.row == 0)) {
154 lastMidClick = timer_read(); 161 lastMidClick = timer_read();
155 is_scroll_clicked = record->event.pressed; 162 is_scroll_clicked = record->event.pressed;
156 } 163 }
157 164
158 if (!process_record_user(keycode, record)) { return false; } 165 if (!process_record_user(keycode, record)) {
166 return false;
167 }
159 168
160 if (keycode == DPI_CONFIG && record->event.pressed) { 169 if (keycode == DPI_CONFIG && record->event.pressed) {
161 keyboard_config.dpi_config = (keyboard_config.dpi_config + 1) % DPI_OPTION_SIZE; 170 keyboard_config.dpi_config = (keyboard_config.dpi_config + 1) % DPI_OPTION_SIZE;
162 eeconfig_update_kb(keyboard_config.raw); 171 eeconfig_update_kb(keyboard_config.raw);
163 pmw_set_cpi(dpi_array[keyboard_config.dpi_config]); 172 pmw_set_cpi(dpi_array[keyboard_config.dpi_config]);
164 } 173 }
174
175 if (keycode == DRAG_SCROLL) {
176#ifndef PLOOPY_DRAGSCROLL_MOMENTARY
177 if (record->event.pressed)
178#endif
179 {
180 is_drag_scroll ^= 1;
181 }
182#ifdef PLOOPY_DRAGSCROLL_FIXED
183 pmw_set_cpi(is_drag_scroll ? PLOOPY_DRAGSCROLL_DPI : dpi_array[keyboard_config.dpi_config]);
184#else
185 pmw_set_cpi(is_drag_scroll ? (dpi_array[keyboard_config.dpi_config] * PLOOPY_DRAGSCROLL_MULTIPLIER) : dpi_array[keyboard_config.dpi_config]);
186#endif
187 }
188
165/* If Mousekeys is disabled, then use handle the mouse button 189/* If Mousekeys is disabled, then use handle the mouse button
166 * keycodes. This makes things simpler, and allows usage of 190 * keycodes. This makes things simpler, and allows usage of
167 * the keycodes in a consistent manner. But only do this if 191 * the keycodes in a consistent manner. But only do this if
@@ -223,24 +247,40 @@ void pointing_device_init(void) {
223 opt_encoder_init(); 247 opt_encoder_init();
224} 248}
225 249
226bool has_report_changed (report_mouse_t first, report_mouse_t second) { 250bool has_report_changed(report_mouse_t new, report_mouse_t old) { return (new.buttons != old.buttons) || (new.x && new.x != old.x) || (new.y && new.y != old.y) || (new.h && new.h != old.h) || (new.v && new.v != old.v); }
227 return !(
228 (!first.buttons && first.buttons == second.buttons) &&
229 (!first.x && first.x == second.x) &&
230 (!first.y && first.y == second.y) &&
231 (!first.h && first.h == second.h) &&
232 (!first.v && first.v == second.v) );
233}
234 251
235void pointing_device_task(void) { 252void pointing_device_task(void) {
236 report_mouse_t mouse_report = pointing_device_get_report(); 253 report_mouse_t mouse_report = pointing_device_get_report();
237 process_wheel(&mouse_report); 254 process_wheel(&mouse_report);
238 process_mouse(&mouse_report); 255 process_mouse(&mouse_report);
239 256
257 if (is_drag_scroll) {
258 mouse_report.h = mouse_report.x;
259 mouse_report.v = mouse_report.y;
260 mouse_report.x = 0;
261 mouse_report.y = 0;
262 }
263
240 pointing_device_set_report(mouse_report); 264 pointing_device_set_report(mouse_report);
241 if (has_report_changed(mouse_report, pointing_device_get_report())) { 265 pointing_device_send();
242 pointing_device_send(); 266}
267
268void pointing_device_send(void) {
269 static report_mouse_t old_report = {};
270 report_mouse_t mouseReport = pointing_device_get_report();
271
272 // If you need to do other things, like debugging, this is the place to do it.
273 if (has_report_changed(mouseReport, old_report)) {
274 host_mouse_send(&mouseReport);
243 } 275 }
276
277 // send it and 0 it out except for buttons, so those stay until they are explicity over-ridden using update_pointing_device
278 mouseReport.x = 0;
279 mouseReport.y = 0;
280 mouseReport.v = 0;
281 mouseReport.h = 0;
282 pointing_device_set_report(mouseReport);
283 old_report = mouseReport;
244} 284}
245 285
246void eeconfig_init_kb(void) { 286void eeconfig_init_kb(void) {
diff --git a/keyboards/ploopyco/mouse/mouse.h b/keyboards/ploopyco/mouse/mouse.h
index f80449c18..5d49d2f2d 100644
--- a/keyboards/ploopyco/mouse/mouse.h
+++ b/keyboards/ploopyco/mouse/mouse.h
@@ -47,8 +47,18 @@ typedef union {
47} keyboard_config_t; 47} keyboard_config_t;
48 48
49extern keyboard_config_t keyboard_config; 49extern keyboard_config_t keyboard_config;
50extern uint16_t dpi_array[];
50 51
51enum ploopy_keycodes { 52enum ploopy_keycodes {
53#ifdef VIA_ENABLE
54 DPI_CONFIG = USER00,
55#else
52 DPI_CONFIG = SAFE_RANGE, 56 DPI_CONFIG = SAFE_RANGE,
57#endif
58 DRAG_SCROLL,
59#ifdef VIA_ENABLE
60 PLOOPY_SAFE_RANGE = SAFE_RANGE,
61#else
53 PLOOPY_SAFE_RANGE, 62 PLOOPY_SAFE_RANGE,
63#endif
54}; 64};
diff --git a/keyboards/ploopyco/mouse/rules.mk b/keyboards/ploopyco/mouse/rules.mk
index 863f335c8..f998672f1 100644
--- a/keyboards/ploopyco/mouse/rules.mk
+++ b/keyboards/ploopyco/mouse/rules.mk
@@ -12,8 +12,8 @@ BOOTLOADER = atmel-dfu
12# 12#
13BOOTMAGIC_ENABLE = lite # Virtual DIP switch configuration 13BOOTMAGIC_ENABLE = lite # Virtual DIP switch configuration
14EXTRAKEY_ENABLE = yes # Audio control and System control 14EXTRAKEY_ENABLE = yes # Audio control and System control
15CONSOLE_ENABLE = yes # Console for debug 15CONSOLE_ENABLE = no # Console for debug
16COMMAND_ENABLE = no # Commands for debug and configuration 16COMMAND_ENABLE = no # Commands for debug and configuration
17# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE 17# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
18SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend 18SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
19# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work 19# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
@@ -24,7 +24,7 @@ UNICODE_ENABLE = no # Unicode
24BLUETOOTH_ENABLE = no # Enable Bluetooth 24BLUETOOTH_ENABLE = no # Enable Bluetooth
25AUDIO_ENABLE = no # Audio output 25AUDIO_ENABLE = no # Audio output
26POINTING_DEVICE_ENABLE = yes 26POINTING_DEVICE_ENABLE = yes
27MOUSEKEY_ENABLE = no # Mouse keys 27MOUSEKEY_ENABLE = yes # Mouse keys
28 28
29QUANTUM_LIB_SRC += analog.c spi_master.c 29QUANTUM_LIB_SRC += analog.c spi_master.c
30SRC += pmw3360.c opt_encoder.c 30SRC += pmw3360.c opt_encoder.c
diff --git a/keyboards/ploopyco/trackball/keymaps/drag_scroll/keymap.c b/keyboards/ploopyco/trackball/keymaps/drag_scroll/keymap.c
index 7784bc855..fbf07935c 100644
--- a/keyboards/ploopyco/trackball/keymaps/drag_scroll/keymap.c
+++ b/keyboards/ploopyco/trackball/keymaps/drag_scroll/keymap.c
@@ -17,42 +17,6 @@
17 */ 17 */
18#include QMK_KEYBOARD_H 18#include QMK_KEYBOARD_H
19 19
20// used for tracking the state
21bool is_drag_scroll = false;
22
23enum custom_keycodes {
24 DRAG_SCROLL = PLOOPY_SAFE_RANGE,
25};
26
27bool process_record_user(uint16_t keycode, keyrecord_t *record) {
28 switch (keycode) {
29 case DRAG_SCROLL:
30 if (record->event.pressed) {
31 // this toggles the state each time you tap it
32 is_drag_scroll ^= 1;
33 }
34 break;
35 }
36 return true;
37}
38
39// The real magic is here.
40// This function is called to translate the processed sensor movement
41// from the mouse sensor and translates it into x and y movement for
42// the mouse report. Normally. So if "drag scroll" is toggled on,
43// moving the ball scrolls instead. You could remove the x or y here
44// to only scroll in one direction, if you wanted, as well. In fact,
45// there is no reason that you need to send this to the mouse report.
46// You could have it register a key, instead.
47void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y) {
48 if (is_drag_scroll) {
49 mouse_report->h = x;
50 mouse_report->v = y;
51 } else {
52 mouse_report->x = x;
53 mouse_report->y = y;
54 }
55}
56 20
57const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { 21const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
58 [0] = LAYOUT( /* Base */ 22 [0] = LAYOUT( /* Base */
diff --git a/keyboards/ploopyco/trackball/rev1/readme.md b/keyboards/ploopyco/trackball/rev1/readme.md
index c0b022372..a824c4690 100644
--- a/keyboards/ploopyco/trackball/rev1/readme.md
+++ b/keyboards/ploopyco/trackball/rev1/readme.md
@@ -13,8 +13,8 @@ Once you have that, you'll need to [ISP Flash](https://docs.qmk.fm/#/isp_flashin
13 13
14| Fuse | Setting | 14| Fuse | Setting |
15|----------|------------------| 15|----------|------------------|
16| Low | `0xDF` | 16| Low | `0x52` |
17| High | `0xD8` or `0x98` | 17| High | `0x99` |
18| Extended | `0xCB` | 18| Extended | `0xCB` |
19 19
20Original (Caterina) settings: 20Original (Caterina) settings:
diff --git a/keyboards/ploopyco/trackball/rules.mk b/keyboards/ploopyco/trackball/rules.mk
index 4ec870e65..e1eb998fe 100644
--- a/keyboards/ploopyco/trackball/rules.mk
+++ b/keyboards/ploopyco/trackball/rules.mk
@@ -9,8 +9,8 @@ F_CPU = 8000000
9# 9#
10BOOTMAGIC_ENABLE = lite # Virtual DIP switch configuration 10BOOTMAGIC_ENABLE = lite # Virtual DIP switch configuration
11EXTRAKEY_ENABLE = yes # Audio control and System control 11EXTRAKEY_ENABLE = yes # Audio control and System control
12CONSOLE_ENABLE = yes # Console for debug 12CONSOLE_ENABLE = no # Console for debug
13COMMAND_ENABLE = no # Commands for debug and configuration 13COMMAND_ENABLE = no # Commands for debug and configuration
14# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE 14# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
15SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend 15SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
16# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work 16# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
@@ -21,7 +21,7 @@ UNICODE_ENABLE = no # Unicode
21BLUETOOTH_ENABLE = no # Enable Bluetooth 21BLUETOOTH_ENABLE = no # Enable Bluetooth
22AUDIO_ENABLE = no # Audio output 22AUDIO_ENABLE = no # Audio output
23POINTING_DEVICE_ENABLE = yes 23POINTING_DEVICE_ENABLE = yes
24MOUSEKEY_ENABLE = no # Mouse keys 24MOUSEKEY_ENABLE = yes # Mouse keys
25 25
26QUANTUM_LIB_SRC += analog.c spi_master.c 26QUANTUM_LIB_SRC += analog.c spi_master.c
27SRC += pmw3360.c opt_encoder.c 27SRC += pmw3360.c opt_encoder.c
diff --git a/keyboards/ploopyco/trackball/trackball.c b/keyboards/ploopyco/trackball/trackball.c
index 94f284346..f59f9788f 100644
--- a/keyboards/ploopyco/trackball/trackball.c
+++ b/keyboards/ploopyco/trackball/trackball.c
@@ -39,9 +39,15 @@
39#ifndef PLOOPY_DPI_DEFAULT 39#ifndef PLOOPY_DPI_DEFAULT
40# define PLOOPY_DPI_DEFAULT 0 40# define PLOOPY_DPI_DEFAULT 0
41#endif 41#endif
42#ifndef PLOOPY_DRAGSCROLL_DPI
43# define PLOOPY_DRAGSCROLL_DPI 100 // Fixed-DPI Drag Scroll
44#endif
45#ifndef PLOOPY_DRAGSCROLL_MULTIPLIER
46# define PLOOPY_DRAGSCROLL_MULTIPLIER 0.75 // Variable-DPI Drag Scroll
47#endif
42 48
43keyboard_config_t keyboard_config; 49keyboard_config_t keyboard_config;
44uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS; 50uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS;
45#define DPI_OPTION_SIZE (sizeof(dpi_array) / sizeof(uint16_t)) 51#define DPI_OPTION_SIZE (sizeof(dpi_array) / sizeof(uint16_t))
46 52
47// TODO: Implement libinput profiles 53// TODO: Implement libinput profiles
@@ -57,6 +63,7 @@ uint16_t lastScroll = 0; // Previous confirmed wheel event
57uint16_t lastMidClick = 0; // Stops scrollwheel from being read if it was pressed 63uint16_t lastMidClick = 0; // Stops scrollwheel from being read if it was pressed
58uint8_t OptLowPin = OPT_ENC1; 64uint8_t OptLowPin = OPT_ENC1;
59bool debug_encoder = false; 65bool debug_encoder = false;
66bool is_drag_scroll = false;
60 67
61__attribute__((weak)) void process_wheel_user(report_mouse_t* mouse_report, int16_t h, int16_t v) { 68__attribute__((weak)) void process_wheel_user(report_mouse_t* mouse_report, int16_t h, int16_t v) {
62 mouse_report->h = h; 69 mouse_report->h = h;
@@ -151,11 +158,13 @@ bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
151 158
152 // Update Timer to prevent accidental scrolls 159 // Update Timer to prevent accidental scrolls
153 if ((record->event.key.col == 1) && (record->event.key.row == 0)) { 160 if ((record->event.key.col == 1) && (record->event.key.row == 0)) {
154 lastMidClick = timer_read(); 161 lastMidClick = timer_read();
155 is_scroll_clicked = record->event.pressed; 162 is_scroll_clicked = record->event.pressed;
156 } 163 }
157 164
158 if (!process_record_user(keycode, record)) { return false; } 165 if (!process_record_user(keycode, record)) {
166 return false;
167 }
159 168
160 if (keycode == DPI_CONFIG && record->event.pressed) { 169 if (keycode == DPI_CONFIG && record->event.pressed) {
161 keyboard_config.dpi_config = (keyboard_config.dpi_config + 1) % DPI_OPTION_SIZE; 170 keyboard_config.dpi_config = (keyboard_config.dpi_config + 1) % DPI_OPTION_SIZE;
@@ -163,6 +172,20 @@ bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
163 pmw_set_cpi(dpi_array[keyboard_config.dpi_config]); 172 pmw_set_cpi(dpi_array[keyboard_config.dpi_config]);
164 } 173 }
165 174
175 if (keycode == DRAG_SCROLL) {
176#ifndef PLOOPY_DRAGSCROLL_MOMENTARY
177 if (record->event.pressed)
178#endif
179 {
180 is_drag_scroll ^= 1;
181 }
182#ifdef PLOOPY_DRAGSCROLL_FIXED
183 pmw_set_cpi(is_drag_scroll ? PLOOPY_DRAGSCROLL_DPI : dpi_array[keyboard_config.dpi_config]);
184#else
185 pmw_set_cpi(is_drag_scroll ? (dpi_array[keyboard_config.dpi_config] * PLOOPY_DRAGSCROLL_MULTIPLIER) : dpi_array[keyboard_config.dpi_config]);
186#endif
187 }
188
166/* If Mousekeys is disabled, then use handle the mouse button 189/* If Mousekeys is disabled, then use handle the mouse button
167 * keycodes. This makes things simpler, and allows usage of 190 * keycodes. This makes things simpler, and allows usage of
168 * the keycodes in a consistent manner. But only do this if 191 * the keycodes in a consistent manner. But only do this if
@@ -223,24 +246,40 @@ void pointing_device_init(void) {
223 opt_encoder_init(); 246 opt_encoder_init();
224} 247}
225 248
226bool has_report_changed (report_mouse_t first, report_mouse_t second) { 249bool has_report_changed(report_mouse_t new, report_mouse_t old) { return (new.buttons != old.buttons) || (new.x && new.x != old.x) || (new.y && new.y != old.y) || (new.h && new.h != old.h) || (new.v && new.v != old.v); }
227 return !(
228 (!first.buttons && first.buttons == second.buttons) &&
229 (!first.x && first.x == second.x) &&
230 (!first.y && first.y == second.y) &&
231 (!first.h && first.h == second.h) &&
232 (!first.v && first.v == second.v) );
233}
234 250
235void pointing_device_task(void) { 251void pointing_device_task(void) {
236 report_mouse_t mouse_report = pointing_device_get_report(); 252 report_mouse_t mouse_report = pointing_device_get_report();
237 process_wheel(&mouse_report); 253 process_wheel(&mouse_report);
238 process_mouse(&mouse_report); 254 process_mouse(&mouse_report);
239 255
256 if (is_drag_scroll) {
257 mouse_report.h = mouse_report.x;
258 mouse_report.v = mouse_report.y;
259 mouse_report.x = 0;
260 mouse_report.y = 0;
261 }
262
240 pointing_device_set_report(mouse_report); 263 pointing_device_set_report(mouse_report);
241 if (has_report_changed(mouse_report, pointing_device_get_report())) { 264 pointing_device_send();
242 pointing_device_send(); 265}
266
267void pointing_device_send(void) {
268 static report_mouse_t old_report = {};
269 report_mouse_t mouseReport = pointing_device_get_report();
270
271 // If you need to do other things, like debugging, this is the place to do it.
272 if (has_report_changed(mouseReport, old_report)) {
273 host_mouse_send(&mouseReport);
243 } 274 }
275
276 // send it and 0 it out except for buttons, so those stay until they are explicity over-ridden using update_pointing_device
277 mouseReport.x = 0;
278 mouseReport.y = 0;
279 mouseReport.v = 0;
280 mouseReport.h = 0;
281 pointing_device_set_report(mouseReport);
282 old_report = mouseReport;
244} 283}
245 284
246void eeconfig_init_kb(void) { 285void eeconfig_init_kb(void) {
diff --git a/keyboards/ploopyco/trackball/trackball.h b/keyboards/ploopyco/trackball/trackball.h
index c58be6c84..fd2bf465a 100644
--- a/keyboards/ploopyco/trackball/trackball.h
+++ b/keyboards/ploopyco/trackball/trackball.h
@@ -45,15 +45,25 @@ void process_wheel_user(report_mouse_t* mouse_report, int16_t h, int16_t v);
45 { {BL, BM, BR, BF, BB}, } 45 { {BL, BM, BR, BF, BB}, }
46 46
47typedef union { 47typedef union {
48 uint32_t raw; 48 uint32_t raw;
49 struct { 49 struct {
50 uint8_t dpi_config; 50 uint8_t dpi_config;
51 }; 51 };
52} keyboard_config_t; 52} keyboard_config_t;
53 53
54extern keyboard_config_t keyboard_config; 54extern keyboard_config_t keyboard_config;
55extern uint16_t dpi_array[];
55 56
56enum ploopy_keycodes { 57enum ploopy_keycodes {
58#ifdef VIA_ENABLE
59 DPI_CONFIG = USER00,
60#else
57 DPI_CONFIG = SAFE_RANGE, 61 DPI_CONFIG = SAFE_RANGE,
62#endif
63 DRAG_SCROLL,
64#ifdef VIA_ENABLE
65 PLOOPY_SAFE_RANGE = SAFE_RANGE,
66#else
58 PLOOPY_SAFE_RANGE, 67 PLOOPY_SAFE_RANGE,
68#endif
59}; 69};