Skip to content

Commit

Permalink
ploopy trackball - mousewheel accumulator for vial keymap
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiethemorris committed Aug 12, 2023
1 parent 768ea5c commit b089d64
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 4 deletions.
1 change: 1 addition & 0 deletions keyboards/ploopyco/trackball/keymaps/custom/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define NO_ACTION_ONESHOT
#define MIDI_ADVANCED

#define SCROLL_USER
#define HANDLE_DPI_CHANGE_FUNCTION
#define EXTRA_USER_KEYCODES
#define SCROLL_THRESHOLD 3
Expand Down
7 changes: 5 additions & 2 deletions keyboards/ploopyco/trackball/keymaps/vial/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
#define PLOOPY_DRAGSCROLL_INVERT 0
#define PLOOPY_DRAGSCROLL_DPI 100
#define PLOOPY_DRAGSCROLL_DENOMINATOR 10 // Number for drag scroll accumulator

#define DYNAMIC_KEYMAP_LAYER_COUNT 5

#define VIAL_KEYBOARD_UID {0x56, 0xDB, 0x30, 0x67, 0xA4, 0xD3, 0x69, 0xBC}
#define VIAL_KEYBOARD_UID {0x56, 0xDB, 0x30, 0x67, 0xA4, 0xD3, 0x69, 0xBC}

#define SCROLL_USER
#define SCROLL_THRESHOLD 3
#define SCROLL_MULTIPLIER 3
51 changes: 50 additions & 1 deletion keyboards/ploopyco/trackball/keymaps/vial/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include QMK_KEYBOARD_H
/* #include "../../trackball.h"
#include "../../trackball.h"

/*
layer_state_t layer_state_set_user(layer_state_t state) {
// Check if layer 1 is active
if (layer_state_cmp(state, 1)) {
Expand All @@ -30,6 +31,54 @@ layer_state_t layer_state_set_user(layer_state_t state) {
return state;
} */

bool wheel_layers = false;
static int scroll_accumulator = 0;

void mousewheel_updown(int dir) {
encoder_update_kb(0, dir > 0);
}

void mousewheel_accumulator(int dir) {
scroll_accumulator += dir;

if (abs(scroll_accumulator) >= SCROLL_THRESHOLD) {
// If the accumulated value reaches the threshold, multiply the effect
int multiplier = (abs(scroll_accumulator) >= SCROLL_THRESHOLD) ? SCROLL_MULTIPLIER : 1;
bool scroll_up = scroll_accumulator > 0;
for (int i = 0; i < multiplier; i++) {
encoder_update_kb(0, scroll_up);
}
scroll_accumulator = 0; // Reset the accumulator after processing
}
}

void process_wheel_user(int dir) {
if (wheel_layers) {
switch (get_highest_layer(layer_state)) {
case 0:
mousewheel_accumulator(dir);
break;
case 1:
mousewheel_updown(dir);
break;
case 2:
mousewheel_updown(dir);
break;
case 3:
mousewheel_updown(dir);
break;
case 4:
mousewheel_updown(dir);
break;
default:
mousewheel_updown(dir);
break;
}
} else {
mousewheel_accumulator(dir);
}
}

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = LAYOUT( /* Base */
KC_BTN1, KC_BTN3, KC_BTN2,
Expand Down
5 changes: 4 additions & 1 deletion keyboards/ploopyco/trackball/trackball.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,11 @@ void process_wheel(void) {
int dir = opt_encoder_handler(p1, p2);

if (dir == 0) return;
#ifdef SCROLL_USER
process_wheel_user(dir);
// encoder_update_kb(0, dir > 0);
#else
encoder_update_kb(0, dir > 0);
#endif
}

report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) {
Expand Down

0 comments on commit b089d64

Please sign in to comment.