Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
danil-tolkachev committed Jan 3, 2025
1 parent 660492a commit 08ce378
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 17 deletions.
36 changes: 28 additions & 8 deletions keyboards/ergohaven/ergohaven_pointing.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion keyboards/ergohaven/ergohaven_pointing.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
4 changes: 2 additions & 2 deletions keyboards/ergohaven/hpd/keymaps/v2_enc_ball/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 11 additions & 6 deletions keyboards/ergohaven/hpd/keymaps/v2_enc_ball/keymap.c
Original file line number Diff line number Diff line change
@@ -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] = {
Expand Down Expand Up @@ -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))
Expand All @@ -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) {
Expand Down
29 changes: 29 additions & 0 deletions keyboards/ergohaven/hpd/keymaps/v2_enc_ball/vial.json
Original file line number Diff line number Diff line change
Expand Up @@ -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":[
Expand Down

0 comments on commit 08ce378

Please sign in to comment.