summaryrefslogtreecommitdiff
path: root/keyboards/ploopyco/trackball
diff options
context:
space:
mode:
authorDrashna Jaelre <drashna@live.com>2021-11-29 08:23:29 -0800
committerGitHub <noreply@github.com>2021-11-29 08:23:29 -0800
commit62e01928cd4d978d275eb28992866ddf0d39922f (patch)
treea516ac7d57d9f1845274ebcbbbb90c9ae33b4980 /keyboards/ploopyco/trackball
parent285afa3a8a2c3ae6ad4efffecdc96108f1b2fadc (diff)
[Keyboard] Ploopy improvements (#15348)
Diffstat (limited to 'keyboards/ploopyco/trackball')
-rw-r--r--keyboards/ploopyco/trackball/rules.mk3
-rw-r--r--keyboards/ploopyco/trackball/trackball.c30
-rw-r--r--keyboards/ploopyco/trackball/trackball.h3
3 files changed, 30 insertions, 6 deletions
diff --git a/keyboards/ploopyco/trackball/rules.mk b/keyboards/ploopyco/trackball/rules.mk
index d118581523..ea34c0f1d3 100644
--- a/keyboards/ploopyco/trackball/rules.mk
+++ b/keyboards/ploopyco/trackball/rules.mk
@@ -22,6 +22,9 @@ POINTING_DEVICE_ENABLE = yes
POINTING_DEVICE_DRIVER = pmw3360
MOUSEKEY_ENABLE = yes # Mouse keys
+ENCODER_ENABLE := no
+OPTS_DEF += -DENCODER_ENABLE
+
QUANTUM_LIB_SRC += analog.c
SRC += opt_encoder.c
diff --git a/keyboards/ploopyco/trackball/trackball.c b/keyboards/ploopyco/trackball/trackball.c
index da4bbf224e..25b36574a5 100644
--- a/keyboards/ploopyco/trackball/trackball.c
+++ b/keyboards/ploopyco/trackball/trackball.c
@@ -31,7 +31,8 @@
# define OPT_SCALE 1 // Multiplier for wheel
#endif
#ifndef PLOOPY_DPI_OPTIONS
-# define PLOOPY_DPI_OPTIONS { 1200, 1600, 2400 }
+# define PLOOPY_DPI_OPTIONS \
+ { 1200, 1600, 2400 }
# ifndef PLOOPY_DPI_DEFAULT
# define PLOOPY_DPI_DEFAULT 1
# endif
@@ -40,10 +41,10 @@
# define PLOOPY_DPI_DEFAULT 0
#endif
#ifndef PLOOPY_DRAGSCROLL_DPI
-# define PLOOPY_DRAGSCROLL_DPI 100 // Fixed-DPI Drag Scroll
+# define PLOOPY_DRAGSCROLL_DPI 100 // Fixed-DPI Drag Scroll
#endif
#ifndef PLOOPY_DRAGSCROLL_MULTIPLIER
-# define PLOOPY_DRAGSCROLL_MULTIPLIER 0.75 // Variable-DPI Drag Scroll
+# define PLOOPY_DRAGSCROLL_MULTIPLIER 0.75 // Variable-DPI Drag Scroll
#endif
keyboard_config_t keyboard_config;
@@ -65,7 +66,24 @@ uint8_t OptLowPin = OPT_ENC1;
bool debug_encoder = false;
bool is_drag_scroll = false;
-void process_wheel(report_mouse_t* mouse_report) {
+__attribute__((weak)) bool encoder_update_user(uint8_t index, bool clockwise) { return true; }
+
+bool encoder_update_kb(uint8_t index, bool clockwise) {
+ if (!encoder_update_user(index, clockwise)) {
+ return false;
+ }
+#ifdef MOUSEKEY_ENABLE
+ tap_code(clockwise ? KC_WH_U : KC_WH_D);
+#else
+ mouse_report_t mouse_report = pointing_device_get_report();
+ mouse_report.v = clockwise ? 1 : -1;
+ pointing_device_set_report(mouse_report);
+ pointing_device_send();
+#endif
+ return true;
+}
+
+void process_wheel(void) {
// TODO: Replace this with interrupt driven code, polling is S L O W
// Lovingly ripped from the Ploopy Source
@@ -94,11 +112,11 @@ void process_wheel(report_mouse_t* mouse_report) {
int dir = opt_encoder_handler(p1, p2);
if (dir == 0) return;
- mouse_report->v = (int8_t)(dir * OPT_SCALE);
+ encoder_update_kb(0, dir == 1);
}
report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) {
- process_wheel(&mouse_report);
+ process_wheel();
if (is_drag_scroll) {
mouse_report.h = mouse_report.x;
diff --git a/keyboards/ploopyco/trackball/trackball.h b/keyboards/ploopyco/trackball/trackball.h
index 52d955325b..add2deb291 100644
--- a/keyboards/ploopyco/trackball/trackball.h
+++ b/keyboards/ploopyco/trackball/trackball.h
@@ -61,3 +61,6 @@ enum ploopy_keycodes {
PLOOPY_SAFE_RANGE,
#endif
};
+
+bool encoder_update_user(uint8_t index, bool clockwise);
+bool encoder_update_kb(uint8_t index, bool clockwise);