diff options
Diffstat (limited to 'keyboards/ploopyco/trackball')
-rw-r--r-- | keyboards/ploopyco/trackball/keymaps/drag_scroll/keymap.c | 36 | ||||
-rw-r--r-- | keyboards/ploopyco/trackball/rev1/readme.md | 4 | ||||
-rw-r--r-- | keyboards/ploopyco/trackball/rules.mk | 6 | ||||
-rw-r--r-- | keyboards/ploopyco/trackball/trackball.c | 65 | ||||
-rw-r--r-- | keyboards/ploopyco/trackball/trackball.h | 18 |
5 files changed, 71 insertions, 58 deletions
diff --git a/keyboards/ploopyco/trackball/keymaps/drag_scroll/keymap.c b/keyboards/ploopyco/trackball/keymaps/drag_scroll/keymap.c index 7784bc8553..fbf07935c8 100644 --- a/keyboards/ploopyco/trackball/keymaps/drag_scroll/keymap.c +++ b/keyboards/ploopyco/trackball/keymaps/drag_scroll/keymap.c @@ -17,42 +17,6 @@ */ #include QMK_KEYBOARD_H -// used for tracking the state -bool is_drag_scroll = false; - -enum custom_keycodes { - DRAG_SCROLL = PLOOPY_SAFE_RANGE, -}; - -bool process_record_user(uint16_t keycode, keyrecord_t *record) { - switch (keycode) { - case DRAG_SCROLL: - if (record->event.pressed) { - // this toggles the state each time you tap it - is_drag_scroll ^= 1; - } - break; - } - return true; -} - -// The real magic is here. -// This function is called to translate the processed sensor movement -// from the mouse sensor and translates it into x and y movement for -// the mouse report. Normally. So if "drag scroll" is toggled on, -// moving the ball scrolls instead. You could remove the x or y here -// to only scroll in one direction, if you wanted, as well. In fact, -// there is no reason that you need to send this to the mouse report. -// You could have it register a key, instead. -void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y) { - if (is_drag_scroll) { - mouse_report->h = x; - mouse_report->v = y; - } else { - mouse_report->x = x; - mouse_report->y = y; - } -} const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [0] = LAYOUT( /* Base */ diff --git a/keyboards/ploopyco/trackball/rev1/readme.md b/keyboards/ploopyco/trackball/rev1/readme.md index c0b0223723..a824c4690e 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 | Fuse | Setting | |----------|------------------| -| Low | `0xDF` | -| High | `0xD8` or `0x98` | +| Low | `0x52` | +| High | `0x99` | | Extended | `0xCB` | Original (Caterina) settings: diff --git a/keyboards/ploopyco/trackball/rules.mk b/keyboards/ploopyco/trackball/rules.mk index 4ec870e659..e1eb998fe0 100644 --- a/keyboards/ploopyco/trackball/rules.mk +++ b/keyboards/ploopyco/trackball/rules.mk @@ -9,8 +9,8 @@ F_CPU = 8000000 # BOOTMAGIC_ENABLE = lite # Virtual DIP switch configuration EXTRAKEY_ENABLE = yes # Audio control and System control -CONSOLE_ENABLE = yes # Console for debug -COMMAND_ENABLE = no # Commands for debug and configuration +CONSOLE_ENABLE = no # Console for debug +COMMAND_ENABLE = no # Commands for debug and configuration # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend # 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 BLUETOOTH_ENABLE = no # Enable Bluetooth AUDIO_ENABLE = no # Audio output POINTING_DEVICE_ENABLE = yes -MOUSEKEY_ENABLE = no # Mouse keys +MOUSEKEY_ENABLE = yes # Mouse keys QUANTUM_LIB_SRC += analog.c spi_master.c SRC += pmw3360.c opt_encoder.c diff --git a/keyboards/ploopyco/trackball/trackball.c b/keyboards/ploopyco/trackball/trackball.c index 94f2843460..f59f9788f9 100644 --- a/keyboards/ploopyco/trackball/trackball.c +++ b/keyboards/ploopyco/trackball/trackball.c @@ -39,9 +39,15 @@ #ifndef PLOOPY_DPI_DEFAULT # define PLOOPY_DPI_DEFAULT 0 #endif +#ifndef PLOOPY_DRAGSCROLL_DPI +# define PLOOPY_DRAGSCROLL_DPI 100 // Fixed-DPI Drag Scroll +#endif +#ifndef PLOOPY_DRAGSCROLL_MULTIPLIER +# define PLOOPY_DRAGSCROLL_MULTIPLIER 0.75 // Variable-DPI Drag Scroll +#endif keyboard_config_t keyboard_config; -uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS; +uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS; #define DPI_OPTION_SIZE (sizeof(dpi_array) / sizeof(uint16_t)) // TODO: Implement libinput profiles @@ -57,6 +63,7 @@ uint16_t lastScroll = 0; // Previous confirmed wheel event uint16_t lastMidClick = 0; // Stops scrollwheel from being read if it was pressed uint8_t OptLowPin = OPT_ENC1; bool debug_encoder = false; +bool is_drag_scroll = false; __attribute__((weak)) void process_wheel_user(report_mouse_t* mouse_report, int16_t h, int16_t v) { mouse_report->h = h; @@ -151,11 +158,13 @@ bool process_record_kb(uint16_t keycode, keyrecord_t* record) { // Update Timer to prevent accidental scrolls if ((record->event.key.col == 1) && (record->event.key.row == 0)) { - lastMidClick = timer_read(); + lastMidClick = timer_read(); is_scroll_clicked = record->event.pressed; } - if (!process_record_user(keycode, record)) { return false; } + if (!process_record_user(keycode, record)) { + return false; + } if (keycode == DPI_CONFIG && record->event.pressed) { 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) { pmw_set_cpi(dpi_array[keyboard_config.dpi_config]); } + if (keycode == DRAG_SCROLL) { +#ifndef PLOOPY_DRAGSCROLL_MOMENTARY + if (record->event.pressed) +#endif + { + is_drag_scroll ^= 1; + } +#ifdef PLOOPY_DRAGSCROLL_FIXED + pmw_set_cpi(is_drag_scroll ? PLOOPY_DRAGSCROLL_DPI : dpi_array[keyboard_config.dpi_config]); +#else + pmw_set_cpi(is_drag_scroll ? (dpi_array[keyboard_config.dpi_config] * PLOOPY_DRAGSCROLL_MULTIPLIER) : dpi_array[keyboard_config.dpi_config]); +#endif + } + /* If Mousekeys is disabled, then use handle the mouse button * keycodes. This makes things simpler, and allows usage of * the keycodes in a consistent manner. But only do this if @@ -223,24 +246,40 @@ void pointing_device_init(void) { opt_encoder_init(); } -bool has_report_changed (report_mouse_t first, report_mouse_t second) { - return !( - (!first.buttons && first.buttons == second.buttons) && - (!first.x && first.x == second.x) && - (!first.y && first.y == second.y) && - (!first.h && first.h == second.h) && - (!first.v && first.v == second.v) ); -} +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); } void pointing_device_task(void) { report_mouse_t mouse_report = pointing_device_get_report(); process_wheel(&mouse_report); process_mouse(&mouse_report); + if (is_drag_scroll) { + mouse_report.h = mouse_report.x; + mouse_report.v = mouse_report.y; + mouse_report.x = 0; + mouse_report.y = 0; + } + pointing_device_set_report(mouse_report); - if (has_report_changed(mouse_report, pointing_device_get_report())) { - pointing_device_send(); + pointing_device_send(); +} + +void pointing_device_send(void) { + static report_mouse_t old_report = {}; + report_mouse_t mouseReport = pointing_device_get_report(); + + // If you need to do other things, like debugging, this is the place to do it. + if (has_report_changed(mouseReport, old_report)) { + host_mouse_send(&mouseReport); } + + // send it and 0 it out except for buttons, so those stay until they are explicity over-ridden using update_pointing_device + mouseReport.x = 0; + mouseReport.y = 0; + mouseReport.v = 0; + mouseReport.h = 0; + pointing_device_set_report(mouseReport); + old_report = mouseReport; } void eeconfig_init_kb(void) { diff --git a/keyboards/ploopyco/trackball/trackball.h b/keyboards/ploopyco/trackball/trackball.h index c58be6c84a..fd2bf465a5 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); { {BL, BM, BR, BF, BB}, } typedef union { - uint32_t raw; - struct { - uint8_t dpi_config; - }; + uint32_t raw; + struct { + uint8_t dpi_config; + }; } keyboard_config_t; extern keyboard_config_t keyboard_config; +extern uint16_t dpi_array[]; enum ploopy_keycodes { +#ifdef VIA_ENABLE + DPI_CONFIG = USER00, +#else DPI_CONFIG = SAFE_RANGE, +#endif + DRAG_SCROLL, +#ifdef VIA_ENABLE + PLOOPY_SAFE_RANGE = SAFE_RANGE, +#else PLOOPY_SAFE_RANGE, +#endif }; |