diff options
author | Drashna Jaelre <drashna@live.com> | 2020-10-26 23:09:11 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-27 17:09:11 +1100 |
commit | 33074bcbadbafa3a359efda5a45a9412e4eca7d2 (patch) | |
tree | 5682dd93d88aa91a91b2e111f1b2a1e5604d7633 /keyboards/ploopyco/trackball/trackball.c | |
parent | 555b1640b26fa09ea5f6b5bc7ea07dc654a326f9 (diff) |
[Keyboard] Bug fixes and improvements to PloopyCo devices (#10573)
Co-authored-by: Ryan <fauxpark@gmail.com>
Diffstat (limited to 'keyboards/ploopyco/trackball/trackball.c')
-rw-r--r-- | keyboards/ploopyco/trackball/trackball.c | 64 |
1 files changed, 55 insertions, 9 deletions
diff --git a/keyboards/ploopyco/trackball/trackball.c b/keyboards/ploopyco/trackball/trackball.c index 6a9bffbffe..7b7b680271 100644 --- a/keyboards/ploopyco/trackball/trackball.c +++ b/keyboards/ploopyco/trackball/trackball.c @@ -16,7 +16,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include QMK_KEYBOARD_H +#include "trackball.h" #ifndef OPT_DEBOUNCE # define OPT_DEBOUNCE 5 // (ms) Time between scroll events @@ -30,6 +30,19 @@ #ifndef OPT_SCALE # define OPT_SCALE 1 // Multiplier for wheel #endif +#ifndef PLOOPY_DPI_OPTIONS +# define PLOOPY_DPI_OPTIONS { 1200, 1600, 2400 } +# ifndef PLOOPY_DPI_DEFAULT +# define PLOOPY_DPI_DEFAULT 1 +# endif +#endif +#ifndef PLOOPY_DPI_DEFAULT +# define PLOOPY_DPI_DEFAULT 0 +#endif + +keyboard_config_t keyboard_config; +uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS; +#define DPI_OPTION_SIZE (sizeof(dpi_array) / sizeof(uint16_t)) // TODO: Implement libinput profiles // https://wayland.freedesktop.org/libinput/doc/latest/pointer-acceleration.html @@ -132,16 +145,24 @@ __attribute__((weak)) void process_mouse(report_mouse_t* mouse_report) { } bool process_record_kb(uint16_t keycode, keyrecord_t* record) { - if (debug_mouse) { - dprintf("KL: kc: %u, col: %u, row: %u, pressed: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed); + if (true) { + xprintf("KL: kc: %u, col: %u, row: %u, pressed: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed); } // Update Timer to prevent accidental scrolls - if ((record->event.key.col == 2) && (record->event.key.row == 0)) { + if ((record->event.key.col == 1) && (record->event.key.row == 0)) { lastMidClick = timer_read(); is_scroll_clicked = record->event.pressed; } + 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; + eeconfig_update_kb(keyboard_config.raw); + pmw_set_cpi(dpi_array[keyboard_config.dpi_config]); + } + /* 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 @@ -174,10 +195,11 @@ bool process_record_kb(uint16_t keycode, keyrecord_t* record) { currentReport.buttons &= ~MOUSE_BTN5; } pointing_device_set_report(currentReport); + pointing_device_send(); } #endif - return process_record_user(keycode, record); + return true; } // Hardware Setup @@ -190,10 +212,6 @@ void keyboard_pre_init_kb(void) { setPinInput(OPT_ENC1); setPinInput(OPT_ENC2); - // This is the debug LED. - setPinOutput(F7); - writePin(F7, debug_enable); - /* Ground all output pins connected to ground. This provides additional * pathways to ground. If you're messing with this, know this: driving ANY * of these pins high will cause a short. On the MCU. Ka-blooey. @@ -206,6 +224,13 @@ void keyboard_pre_init_kb(void) { writePinLow(unused_pins[i]); } #endif + + // This is the debug LED. +#if defined(DEBUG_LED_PIN) + setPinOutput(DEBUG_LED_PIN); + writePin(DEBUG_LED_PIN, debug_enable); +#endif + keyboard_pre_init_user(); } @@ -235,3 +260,24 @@ void pointing_device_task(void) { pointing_device_send(); } } + +void eeconfig_init_kb(void) { + keyboard_config.dpi_config = PLOOPY_DPI_DEFAULT; + eeconfig_update_kb(keyboard_config.raw); +} + +void matrix_init_kb(void) { + // is safe to just read DPI setting since matrix init + // comes before pointing device init. + keyboard_config.raw = eeconfig_read_kb(); + if (keyboard_config.dpi_config > DPI_OPTION_SIZE) { + eeconfig_init_kb(); + } + matrix_init_user(); +} + +void keyboard_post_init_kb(void) { + pmw_set_cpi(dpi_array[keyboard_config.dpi_config]); + + keyboard_post_init_user(); +} |