[Keyboard] Ploopy improvements (#15348)
This commit is contained in:
parent
285afa3a8a
commit
62e01928cd
9 changed files with 109 additions and 44 deletions
|
@ -66,7 +66,24 @@ uint8_t OptLowPin = OPT_ENC1;
|
||||||
bool debug_encoder = false;
|
bool debug_encoder = false;
|
||||||
bool is_drag_scroll = 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) {
|
||||||
// Lovingly ripped from the Ploopy Source
|
// Lovingly ripped from the Ploopy Source
|
||||||
|
|
||||||
// If the mouse wheel was just released, do not scroll.
|
// If the mouse wheel was just released, do not scroll.
|
||||||
|
@ -94,11 +111,11 @@ void process_wheel(report_mouse_t* mouse_report) {
|
||||||
int dir = opt_encoder_handler(p1, p2);
|
int dir = opt_encoder_handler(p1, p2);
|
||||||
|
|
||||||
if (dir == 0) return;
|
if (dir == 0) return;
|
||||||
mouse_report->v = (int8_t)(dir * OPT_SCALE);
|
encoder_update_kb(0, dir == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((weak)) report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) {
|
report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) {
|
||||||
process_wheel(&mouse_report);
|
process_wheel();
|
||||||
|
|
||||||
if (is_drag_scroll) {
|
if (is_drag_scroll) {
|
||||||
mouse_report.h = mouse_report.x;
|
mouse_report.h = mouse_report.x;
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
#define OPT_ENC1_MUX 0
|
#define OPT_ENC1_MUX 0
|
||||||
#define OPT_ENC2_MUX 4
|
#define OPT_ENC2_MUX 4
|
||||||
|
|
||||||
void process_wheel(report_mouse_t* mouse_report);
|
void process_wheel(void);
|
||||||
|
|
||||||
#define LAYOUT(BLL, BL, BM, BR, BRR, BF, BB, BDPI) \
|
#define LAYOUT(BLL, BL, BM, BR, BRR, BF, BB, BDPI) \
|
||||||
{ {BL, BM, BR, BF, BB, BRR, BLL, BDPI}, }
|
{ {BL, BM, BR, BF, BB, BRR, BLL, BDPI}, }
|
||||||
|
@ -56,3 +56,6 @@ enum ploopy_keycodes {
|
||||||
PLOOPY_SAFE_RANGE,
|
PLOOPY_SAFE_RANGE,
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool encoder_update_user(uint8_t index, bool clockwise);
|
||||||
|
bool encoder_update_kb(uint8_t index, bool clockwise);
|
||||||
|
|
|
@ -25,5 +25,8 @@ POINTING_DEVICE_ENABLE = yes
|
||||||
POINTING_DEVICE_DRIVER = pmw3360
|
POINTING_DEVICE_DRIVER = pmw3360
|
||||||
MOUSEKEY_ENABLE = yes # Mouse keys
|
MOUSEKEY_ENABLE = yes # Mouse keys
|
||||||
|
|
||||||
|
ENCODER_ENABLE := no
|
||||||
|
OPTS_DEF += -DENCODER_ENABLE
|
||||||
|
|
||||||
QUANTUM_LIB_SRC += analog.c
|
QUANTUM_LIB_SRC += analog.c
|
||||||
SRC += opt_encoder.c
|
SRC += opt_encoder.c
|
||||||
|
|
|
@ -22,6 +22,9 @@ POINTING_DEVICE_ENABLE = yes
|
||||||
POINTING_DEVICE_DRIVER = pmw3360
|
POINTING_DEVICE_DRIVER = pmw3360
|
||||||
MOUSEKEY_ENABLE = yes # Mouse keys
|
MOUSEKEY_ENABLE = yes # Mouse keys
|
||||||
|
|
||||||
|
ENCODER_ENABLE := no
|
||||||
|
OPTS_DEF += -DENCODER_ENABLE
|
||||||
|
|
||||||
QUANTUM_LIB_SRC += analog.c
|
QUANTUM_LIB_SRC += analog.c
|
||||||
SRC += opt_encoder.c
|
SRC += opt_encoder.c
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,8 @@
|
||||||
# define OPT_SCALE 1 // Multiplier for wheel
|
# define OPT_SCALE 1 // Multiplier for wheel
|
||||||
#endif
|
#endif
|
||||||
#ifndef PLOOPY_DPI_OPTIONS
|
#ifndef PLOOPY_DPI_OPTIONS
|
||||||
# define PLOOPY_DPI_OPTIONS { 1200, 1600, 2400 }
|
# define PLOOPY_DPI_OPTIONS \
|
||||||
|
{ 1200, 1600, 2400 }
|
||||||
# ifndef PLOOPY_DPI_DEFAULT
|
# ifndef PLOOPY_DPI_DEFAULT
|
||||||
# define PLOOPY_DPI_DEFAULT 1
|
# define PLOOPY_DPI_DEFAULT 1
|
||||||
# endif
|
# endif
|
||||||
|
@ -65,7 +66,24 @@ uint8_t OptLowPin = OPT_ENC1;
|
||||||
bool debug_encoder = false;
|
bool debug_encoder = false;
|
||||||
bool is_drag_scroll = 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
|
// TODO: Replace this with interrupt driven code, polling is S L O W
|
||||||
// Lovingly ripped from the Ploopy Source
|
// 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);
|
int dir = opt_encoder_handler(p1, p2);
|
||||||
|
|
||||||
if (dir == 0) return;
|
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) {
|
report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) {
|
||||||
process_wheel(&mouse_report);
|
process_wheel();
|
||||||
|
|
||||||
if (is_drag_scroll) {
|
if (is_drag_scroll) {
|
||||||
mouse_report.h = mouse_report.x;
|
mouse_report.h = mouse_report.x;
|
||||||
|
|
|
@ -61,3 +61,6 @@ enum ploopy_keycodes {
|
||||||
PLOOPY_SAFE_RANGE,
|
PLOOPY_SAFE_RANGE,
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool encoder_update_user(uint8_t index, bool clockwise);
|
||||||
|
bool encoder_update_kb(uint8_t index, bool clockwise);
|
||||||
|
|
|
@ -20,7 +20,10 @@ RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow
|
||||||
AUDIO_ENABLE = no # Audio output
|
AUDIO_ENABLE = no # Audio output
|
||||||
POINTING_DEVICE_ENABLE = yes
|
POINTING_DEVICE_ENABLE = yes
|
||||||
POINTING_DEVICE_DRIVER = adns5050
|
POINTING_DEVICE_DRIVER = adns5050
|
||||||
MOUSEKEY_ENABLE = no # Mouse keys
|
MOUSEKEY_ENABLE = yes # Mouse keys
|
||||||
|
|
||||||
|
ENCODER_ENABLE := no
|
||||||
|
OPTS_DEF += -DENCODER_ENABLE
|
||||||
|
|
||||||
QUANTUM_LIB_SRC += analog.c
|
QUANTUM_LIB_SRC += analog.c
|
||||||
SRC += opt_encoder.c
|
SRC += opt_encoder.c
|
||||||
|
|
|
@ -67,14 +67,29 @@ uint8_t OptLowPin = OPT_ENC1;
|
||||||
bool debug_encoder = false;
|
bool debug_encoder = false;
|
||||||
bool is_drag_scroll = 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) {
|
||||||
// If the mouse wheel was just released, do not scroll.
|
// If the mouse wheel was just released, do not scroll.
|
||||||
if (timer_elapsed(lastMidClick) < SCROLL_BUTT_DEBOUNCE)
|
if (timer_elapsed(lastMidClick) < SCROLL_BUTT_DEBOUNCE) return;
|
||||||
return;
|
|
||||||
|
|
||||||
// Limit the number of scrolls per unit time.
|
// Limit the number of scrolls per unit time.
|
||||||
if (timer_elapsed(lastScroll) < OPT_DEBOUNCE)
|
if (timer_elapsed(lastScroll) < OPT_DEBOUNCE) return;
|
||||||
return;
|
|
||||||
|
|
||||||
// Don't scroll if the middle button is depressed.
|
// Don't scroll if the middle button is depressed.
|
||||||
if (is_scroll_clicked) {
|
if (is_scroll_clicked) {
|
||||||
|
@ -87,15 +102,12 @@ void process_wheel(report_mouse_t* mouse_report) {
|
||||||
uint16_t p1 = adc_read(OPT_ENC1_MUX);
|
uint16_t p1 = adc_read(OPT_ENC1_MUX);
|
||||||
uint16_t p2 = adc_read(OPT_ENC2_MUX);
|
uint16_t p2 = adc_read(OPT_ENC2_MUX);
|
||||||
|
|
||||||
if (debug_encoder)
|
if (debug_encoder) dprintf("OPT1: %d, OPT2: %d\n", p1, p2);
|
||||||
dprintf("OPT1: %d, OPT2: %d\n", p1, p2);
|
|
||||||
|
|
||||||
uint8_t dir = opt_encoder_handler(p1, p2);
|
uint8_t dir = opt_encoder_handler(p1, p2);
|
||||||
|
|
||||||
if (dir == 0)
|
if (dir == 0) return;
|
||||||
return;
|
encoder_update_kb(0, dir == 1);
|
||||||
|
|
||||||
mouse_report->v = (int8_t)(dir * OPT_SCALE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pointing_device_init_kb(void) {
|
void pointing_device_init_kb(void) {
|
||||||
|
@ -106,6 +118,7 @@ void pointing_device_init_kb(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) {
|
report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) {
|
||||||
|
process_wheel();
|
||||||
|
|
||||||
if (is_drag_scroll) {
|
if (is_drag_scroll) {
|
||||||
mouse_report.h = mouse_report.x;
|
mouse_report.h = mouse_report.x;
|
||||||
|
@ -131,8 +144,7 @@ bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
|
||||||
is_scroll_clicked = record->event.pressed;
|
is_scroll_clicked = record->event.pressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!process_record_user(keycode, record))
|
if (!process_record_user(keycode, record)) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
if (keycode == DPI_CONFIG && record->event.pressed) {
|
if (keycode == DPI_CONFIG && record->event.pressed) {
|
||||||
keyboard_config.dpi_config = (keyboard_config.dpi_config + 1) % DPI_OPTION_SIZE;
|
keyboard_config.dpi_config = (keyboard_config.dpi_config + 1) % DPI_OPTION_SIZE;
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
#define OPT_ENC1_MUX 0
|
#define OPT_ENC1_MUX 0
|
||||||
#define OPT_ENC2_MUX 4
|
#define OPT_ENC2_MUX 4
|
||||||
|
|
||||||
void process_wheel(report_mouse_t* mouse_report);
|
void process_wheel(void);
|
||||||
|
|
||||||
#define LAYOUT(BL, BM, BR, BF, BB) \
|
#define LAYOUT(BL, BM, BR, BF, BB) \
|
||||||
{ {BL, BM, BR, BF, BB}, }
|
{ {BL, BM, BR, BF, BB}, }
|
||||||
|
@ -56,3 +56,6 @@ enum ploopy_keycodes {
|
||||||
PLOOPY_SAFE_RANGE,
|
PLOOPY_SAFE_RANGE,
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool encoder_update_user(uint8_t index, bool clockwise);
|
||||||
|
bool encoder_update_kb(uint8_t index, bool clockwise);
|
||||||
|
|
Loading…
Reference in a new issue