From 08ce3783cbb9e8a2adbeea56f64d2a1bf6e3bc8e Mon Sep 17 00:00:00 2001 From: Danil Tolkachev Date: Sat, 4 Jan 2025 01:00:30 +0300 Subject: [PATCH] wip --- keyboards/ergohaven/ergohaven_pointing.c | 36 ++++++++++++++----- keyboards/ergohaven/ergohaven_pointing.h | 8 ++++- .../hpd/keymaps/v2_enc_ball/config.h | 4 +-- .../hpd/keymaps/v2_enc_ball/keymap.c | 17 +++++---- .../hpd/keymaps/v2_enc_ball/vial.json | 29 +++++++++++++++ 5 files changed, 77 insertions(+), 17 deletions(-) diff --git a/keyboards/ergohaven/ergohaven_pointing.c b/keyboards/ergohaven/ergohaven_pointing.c index a90cd0a7fe1..397f3e25eaa 100644 --- a/keyboards/ergohaven/ergohaven_pointing.c +++ b/keyboards/ergohaven/ergohaven_pointing.c @@ -3,9 +3,27 @@ pointing_mode_t pointing_mode = POINTING_MODE_NORMAL; -static int32_t scroll_divisor = 32; -static int32_t accumulated_h = 0; -static int32_t accumulated_v = 0; +static int32_t accumulated_h = 0; +static int32_t accumulated_v = 0; + +static int32_t sens[4] = {1, 2, 16, 32}; + +void set_sniper_sens(int32_t s) { + sens[POINTING_MODE_SNIPER] = s; +} + +void set_scroll_sens(int32_t s) { + sens[POINTING_MODE_SCROLL] = s; +} + +void set_text_sens(int32_t s) { + sens[POINTING_MODE_TEXT] = s; +} + +void pointing_device_init_user(void) { + set_auto_mouse_layer(5); + set_auto_mouse_enable(true); +} bool is_mouse_active = false; @@ -34,7 +52,7 @@ bool process_record_pointing(uint16_t keycode, keyrecord_t *record) { static uint16_t press_timer = 0; static pointing_mode_t prev_pointing_mode = POINTING_MODE_NORMAL; - const pointing_mode_t NEW_MODE = (keycode == EH_SCR) ? POINTING_MODE_SCROLL : ((keycode == EH_TXT) ? POINTING_MODE_TEXT : POINTING_MODE_SNIPER); + const pointing_mode_t NEW_MODE = POINTING_MODE_SNIPER + (keycode - EH_SNP); if (record->event.pressed) { prev_pointing_mode = pointing_mode; @@ -58,15 +76,17 @@ bool process_record_pointing(uint16_t keycode, keyrecord_t *record) { report_mouse_t pointing_device_task_user(report_mouse_t mrpt) { is_mouse_active = abs(mrpt.x) > 1 || abs(mrpt.y) > 1 || mrpt.buttons; + int32_t divisor = sens[pointing_mode]; + if (pointing_mode != POINTING_MODE_NORMAL) { accumulated_h += mrpt.x; accumulated_v += mrpt.y; - int shift_x = accumulated_h / scroll_divisor; - int shift_y = accumulated_v / scroll_divisor; + int shift_x = accumulated_h / divisor; + int shift_y = accumulated_v / divisor; - accumulated_h -= shift_x * scroll_divisor; - accumulated_v -= shift_y * scroll_divisor; + accumulated_h -= shift_x * divisor; + accumulated_v -= shift_y * divisor; mrpt.x = 0; mrpt.y = 0; diff --git a/keyboards/ergohaven/ergohaven_pointing.h b/keyboards/ergohaven/ergohaven_pointing.h index cff058f1ba2..8433a9812a7 100644 --- a/keyboards/ergohaven/ergohaven_pointing.h +++ b/keyboards/ergohaven/ergohaven_pointing.h @@ -4,7 +4,7 @@ #include "ergohaven.h" typedef enum { - POINTING_MODE_NORMAL, + POINTING_MODE_NORMAL = 0, POINTING_MODE_SNIPER, POINTING_MODE_SCROLL, POINTING_MODE_TEXT, @@ -17,3 +17,9 @@ enum { }; bool process_record_pointing(uint16_t keycode, keyrecord_t *record); + +void set_scroll_sens(int32_t sens); + +void set_sniper_sens(int32_t sens); + +void set_text_sens(int32_t sens); diff --git a/keyboards/ergohaven/hpd/keymaps/v2_enc_ball/config.h b/keyboards/ergohaven/hpd/keymaps/v2_enc_ball/config.h index 87512402de7..0440a752afc 100644 --- a/keyboards/ergohaven/hpd/keymaps/v2_enc_ball/config.h +++ b/keyboards/ergohaven/hpd/keymaps/v2_enc_ball/config.h @@ -44,7 +44,7 @@ #define POINTING_DEVICE_TASK_THROTTLE_MS 10 #define POINTING_DEVICE_INVERT_X -#define VIA_EEPROM_LAYOUT_OPTIONS_SIZE 1 -#define VIA_EEPROM_LAYOUT_OPTIONS_DEFAULT 0x00000004 +#define VIA_EEPROM_LAYOUT_OPTIONS_SIZE 2 +#define VIA_EEPROM_LAYOUT_OPTIONS_DEFAULT 0x0000035d #define POINTING_DEVICE_AUTO_MOUSE_ENABLE diff --git a/keyboards/ergohaven/hpd/keymaps/v2_enc_ball/keymap.c b/keyboards/ergohaven/hpd/keymaps/v2_enc_ball/keymap.c index 5348875ab4f..1eec1b356b8 100755 --- a/keyboards/ergohaven/hpd/keymaps/v2_enc_ball/keymap.c +++ b/keyboards/ergohaven/hpd/keymaps/v2_enc_ball/keymap.c @@ -1,5 +1,6 @@ #include QMK_KEYBOARD_H #include "ergohaven.h" +#include "ergohaven_pointing.h" // clang-format off const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { @@ -50,13 +51,19 @@ const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = { typedef union { uint32_t raw; struct { + uint8_t text_mode : 3; + uint8_t scroll_mode : 3; + uint8_t sniper_mode : 2; uint8_t dpi_mode : 4; }; } vial_config_t; static vial_config_t vial_config; -const int DPI_TABLE[15] = {100, 200, 300, 400, 500, 600, 800, 1000, 1200, 1600, 2000, 2500, 3200, 4000, 5000}; +const int DPI_TABLE[15] = {100, 200, 300, 400, 500, 600, 800, 1000, 1200, 1600, 2000, 2500, 3200, 4000, 5000}; +const int32_t SNIPER_TABLE[15] = {2, 3, 4, 5}; +const int32_t SCROLL_TABLE[15] = {6, 8, 11, 16, 23, 32, 45, 64}; +const int32_t TEXT_TABLE[15] = {6, 8, 11, 16, 23, 32, 45, 64}; int get_dpi(uint8_t dpi_mode) { if (dpi_mode < ARRAY_SIZE(DPI_TABLE)) @@ -65,15 +72,13 @@ int get_dpi(uint8_t dpi_mode) { return DPI_TABLE[0]; } -void pointing_device_init_user(void) { - set_auto_mouse_layer(5); - set_auto_mouse_enable(true); -} - void via_set_layout_options_kb(uint32_t value) { dprintf("via_set_layout_options_kb %lx\n", value); vial_config.raw = value; pointing_device_set_cpi(get_dpi(vial_config.dpi_mode)); + set_scroll_sens(SCROLL_TABLE[vial_config.scroll_mode]); + set_sniper_sens(SNIPER_TABLE[vial_config.sniper_mode]); + set_text_sens(TEXT_TABLE[vial_config.text_mode]); } void keyboard_post_init_user(void) { diff --git a/keyboards/ergohaven/hpd/keymaps/v2_enc_ball/vial.json b/keyboards/ergohaven/hpd/keymaps/v2_enc_ball/vial.json index fef9782faae..3e9f1584d13 100755 --- a/keyboards/ergohaven/hpd/keymaps/v2_enc_ball/vial.json +++ b/keyboards/ergohaven/hpd/keymaps/v2_enc_ball/vial.json @@ -27,6 +27,35 @@ "3200", "4000", "5000" + ], + [ + "Sniper sens", + "1/2", + "1/3", + "1/4", + "1/5" + ], + [ + "Scroll sens", + "1/6", + "1/8", + "1/11", + "1/16", + "1/23", + "1/32", + "1/45", + "1/64" + ], + [ + "Text sens", + "1/6", + "1/8", + "1/11", + "1/16", + "1/23", + "1/32", + "1/45", + "1/64" ] ], "keymap":[