Skip to content

Commit e768fb8

Browse files
drashnaridingqwertyGDsouza
authored
[Keyboard] PloopyCo VIA updates (#11290)
Co-authored-by: ridingqwerty <george.g.koenig@gmail.com> Co-authored-by: Glen D'souza <gdsouza@linuxmail.org>
1 parent 9ee1282 commit e768fb8

File tree

10 files changed

+142
-114
lines changed

10 files changed

+142
-114
lines changed

keyboards/ploopyco/mouse/keymaps/drag_scroll/keymap.c

+4-39
Original file line numberDiff line numberDiff line change
@@ -17,46 +17,11 @@
1717
*/
1818
#include QMK_KEYBOARD_H
1919

20-
// used for tracking the state
21-
bool is_drag_scroll = false;
22-
23-
enum custom_keycodes {
24-
DRAG_SCROLL = PLOOPY_SAFE_RANGE,
25-
};
26-
2720

2821
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
2922
[0] = LAYOUT(/* Base */
30-
C(KC_C), KC_BTN1, KC_BTN3, KC_BTN2, C(KC_V), KC_BTN4, KC_BTN5, DPI_CONFIG)
31-
};
23+
C(KC_C), KC_BTN1, KC_BTN3, LT(1, KC_BTN2), C(KC_V), KC_BTN4, KC_BTN5, DPI_CONFIG),
24+
[1] = LAYOUT(/* Base */
25+
_______, DRAG_SCROLL, _______, _______, _______, _______, _______, RESET),
3226

33-
34-
bool 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.
54-
void 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-
}
27+
};

keyboards/ploopyco/mouse/keymaps/via/keymap.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include QMK_KEYBOARD_H
1919

2020
const 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),
2222
[1] = LAYOUT(_______, _______, _______, _______, _______, _______, _______, _______),
2323
[2] = LAYOUT(_______, _______, _______, _______, _______, _______, _______, _______),
2424
[3] = LAYOUT(_______, _______, _______, _______, _______, _______, _______, _______),

keyboards/ploopyco/mouse/mouse.c

+53-13
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,15 @@
3939
#ifndef PLOOPY_DPI_DEFAULT
4040
# define PLOOPY_DPI_DEFAULT 0
4141
#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
4248

4349
keyboard_config_t keyboard_config;
44-
uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS;
50+
uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS;
4551
#define DPI_OPTION_SIZE (sizeof(dpi_array) / sizeof(uint16_t))
4652

4753
// TODO: Implement libinput profiles
@@ -57,6 +63,7 @@ uint16_t lastScroll = 0; // Previous confirmed wheel event
5763
uint16_t lastMidClick = 0; // Stops scrollwheel from being read if it was pressed
5864
uint8_t OptLowPin = OPT_ENC1;
5965
bool debug_encoder = false;
66+
bool is_drag_scroll = false;
6067

6168
__attribute__((weak)) void process_wheel_user(report_mouse_t* mouse_report, int16_t h, int16_t v) {
6269
mouse_report->h = h;
@@ -151,17 +158,34 @@ bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
151158

152159
// Update Timer to prevent accidental scrolls
153160
if ((record->event.key.col == 1) && (record->event.key.row == 0)) {
154-
lastMidClick = timer_read();
161+
lastMidClick = timer_read();
155162
is_scroll_clicked = record->event.pressed;
156163
}
157164

158-
if (!process_record_user(keycode, record)) { return false; }
165+
if (!process_record_user(keycode, record)) {
166+
return false;
167+
}
159168

160169
if (keycode == DPI_CONFIG && record->event.pressed) {
161170
keyboard_config.dpi_config = (keyboard_config.dpi_config + 1) % DPI_OPTION_SIZE;
162171
eeconfig_update_kb(keyboard_config.raw);
163172
pmw_set_cpi(dpi_array[keyboard_config.dpi_config]);
164173
}
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+
165189
/* If Mousekeys is disabled, then use handle the mouse button
166190
* keycodes. This makes things simpler, and allows usage of
167191
* the keycodes in a consistent manner. But only do this if
@@ -223,24 +247,40 @@ void pointing_device_init(void) {
223247
opt_encoder_init();
224248
}
225249

226-
bool has_report_changed (report_mouse_t first, report_mouse_t second) {
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-
}
250+
bool 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); }
234251

235252
void pointing_device_task(void) {
236253
report_mouse_t mouse_report = pointing_device_get_report();
237254
process_wheel(&mouse_report);
238255
process_mouse(&mouse_report);
239256

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+
240264
pointing_device_set_report(mouse_report);
241-
if (has_report_changed(mouse_report, pointing_device_get_report())) {
242-
pointing_device_send();
265+
pointing_device_send();
266+
}
267+
268+
void 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);
243275
}
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;
244284
}
245285

246286
void eeconfig_init_kb(void) {

keyboards/ploopyco/mouse/mouse.h

+10
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,18 @@ typedef union {
4747
} keyboard_config_t;
4848

4949
extern keyboard_config_t keyboard_config;
50+
extern uint16_t dpi_array[];
5051

5152
enum ploopy_keycodes {
53+
#ifdef VIA_ENABLE
54+
DPI_CONFIG = USER00,
55+
#else
5256
DPI_CONFIG = SAFE_RANGE,
57+
#endif
58+
DRAG_SCROLL,
59+
#ifdef VIA_ENABLE
60+
PLOOPY_SAFE_RANGE = SAFE_RANGE,
61+
#else
5362
PLOOPY_SAFE_RANGE,
63+
#endif
5464
};

keyboards/ploopyco/mouse/rules.mk

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ BOOTLOADER = atmel-dfu
1212
#
1313
BOOTMAGIC_ENABLE = lite # Virtual DIP switch configuration
1414
EXTRAKEY_ENABLE = yes # Audio control and System control
15-
CONSOLE_ENABLE = yes # Console for debug
16-
COMMAND_ENABLE = no # Commands for debug and configuration
15+
CONSOLE_ENABLE = no # Console for debug
16+
COMMAND_ENABLE = no # Commands for debug and configuration
1717
# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
1818
SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
1919
# 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
2424
BLUETOOTH_ENABLE = no # Enable Bluetooth
2525
AUDIO_ENABLE = no # Audio output
2626
POINTING_DEVICE_ENABLE = yes
27-
MOUSEKEY_ENABLE = no # Mouse keys
27+
MOUSEKEY_ENABLE = yes # Mouse keys
2828

2929
QUANTUM_LIB_SRC += analog.c spi_master.c
3030
SRC += pmw3360.c opt_encoder.c

keyboards/ploopyco/trackball/keymaps/drag_scroll/keymap.c

-36
Original file line numberDiff line numberDiff line change
@@ -17,42 +17,6 @@
1717
*/
1818
#include QMK_KEYBOARD_H
1919

20-
// used for tracking the state
21-
bool is_drag_scroll = false;
22-
23-
enum custom_keycodes {
24-
DRAG_SCROLL = PLOOPY_SAFE_RANGE,
25-
};
26-
27-
bool 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.
47-
void 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-
}
5620

5721
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
5822
[0] = LAYOUT( /* Base */

keyboards/ploopyco/trackball/rev1/readme.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Once you have that, you'll need to [ISP Flash](https://docs.qmk.fm/#/isp_flashin
1313

1414
| Fuse | Setting |
1515
|----------|------------------|
16-
| Low | `0xDF` |
17-
| High | `0xD8` or `0x98` |
16+
| Low | `0x52` |
17+
| High | `0x99` |
1818
| Extended | `0xCB` |
1919

2020
Original (Caterina) settings:

keyboards/ploopyco/trackball/rules.mk

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ F_CPU = 8000000
99
#
1010
BOOTMAGIC_ENABLE = lite # Virtual DIP switch configuration
1111
EXTRAKEY_ENABLE = yes # Audio control and System control
12-
CONSOLE_ENABLE = yes # Console for debug
13-
COMMAND_ENABLE = no # Commands for debug and configuration
12+
CONSOLE_ENABLE = no # Console for debug
13+
COMMAND_ENABLE = no # Commands for debug and configuration
1414
# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
1515
SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
1616
# 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
2121
BLUETOOTH_ENABLE = no # Enable Bluetooth
2222
AUDIO_ENABLE = no # Audio output
2323
POINTING_DEVICE_ENABLE = yes
24-
MOUSEKEY_ENABLE = no # Mouse keys
24+
MOUSEKEY_ENABLE = yes # Mouse keys
2525

2626
QUANTUM_LIB_SRC += analog.c spi_master.c
2727
SRC += pmw3360.c opt_encoder.c

keyboards/ploopyco/trackball/trackball.c

+52-13
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,15 @@
3939
#ifndef PLOOPY_DPI_DEFAULT
4040
# define PLOOPY_DPI_DEFAULT 0
4141
#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
4248

4349
keyboard_config_t keyboard_config;
44-
uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS;
50+
uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS;
4551
#define DPI_OPTION_SIZE (sizeof(dpi_array) / sizeof(uint16_t))
4652

4753
// TODO: Implement libinput profiles
@@ -57,6 +63,7 @@ uint16_t lastScroll = 0; // Previous confirmed wheel event
5763
uint16_t lastMidClick = 0; // Stops scrollwheel from being read if it was pressed
5864
uint8_t OptLowPin = OPT_ENC1;
5965
bool debug_encoder = false;
66+
bool is_drag_scroll = false;
6067

6168
__attribute__((weak)) void process_wheel_user(report_mouse_t* mouse_report, int16_t h, int16_t v) {
6269
mouse_report->h = h;
@@ -151,18 +158,34 @@ bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
151158

152159
// Update Timer to prevent accidental scrolls
153160
if ((record->event.key.col == 1) && (record->event.key.row == 0)) {
154-
lastMidClick = timer_read();
161+
lastMidClick = timer_read();
155162
is_scroll_clicked = record->event.pressed;
156163
}
157164

158-
if (!process_record_user(keycode, record)) { return false; }
165+
if (!process_record_user(keycode, record)) {
166+
return false;
167+
}
159168

160169
if (keycode == DPI_CONFIG && record->event.pressed) {
161170
keyboard_config.dpi_config = (keyboard_config.dpi_config + 1) % DPI_OPTION_SIZE;
162171
eeconfig_update_kb(keyboard_config.raw);
163172
pmw_set_cpi(dpi_array[keyboard_config.dpi_config]);
164173
}
165174

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+
166189
/* If Mousekeys is disabled, then use handle the mouse button
167190
* keycodes. This makes things simpler, and allows usage of
168191
* the keycodes in a consistent manner. But only do this if
@@ -223,24 +246,40 @@ void pointing_device_init(void) {
223246
opt_encoder_init();
224247
}
225248

226-
bool has_report_changed (report_mouse_t first, report_mouse_t second) {
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-
}
249+
bool 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); }
234250

235251
void pointing_device_task(void) {
236252
report_mouse_t mouse_report = pointing_device_get_report();
237253
process_wheel(&mouse_report);
238254
process_mouse(&mouse_report);
239255

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+
240263
pointing_device_set_report(mouse_report);
241-
if (has_report_changed(mouse_report, pointing_device_get_report())) {
242-
pointing_device_send();
264+
pointing_device_send();
265+
}
266+
267+
void 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);
243274
}
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;
244283
}
245284

246285
void eeconfig_init_kb(void) {

0 commit comments

Comments
 (0)