Skip to content

Commit

Permalink
Tweaks and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ReFil committed Feb 27, 2024
1 parent 01b7ac6 commit 998511f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
4 changes: 0 additions & 4 deletions app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,6 @@ config ZMK_TRACKPAD
bool "Enable ZMK trackpad emulation"
default n

config ZMK_TRACKPAD_MOUSE_MODE
bool "Enable optional additional mouse emulation"
default n

config ZMK_TRACKPAD_REVERSE_SCROLL
bool "Reverse scroll direction of trackpad in mosue mode"
default n
Expand Down
4 changes: 4 additions & 0 deletions app/include/zmk/trackpad.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ struct zmk_trackpad_finger_data_t {
uint16_t x, y;
};

void zmk_trackpad_set_enabled(bool enabled);

bool zmk_trackpad_get_enabled();

void zmk_trackpad_set_mouse_mode(bool mouse_mode);

void zmk_trackpad_selective_set(uint8_t selective);
Expand Down
18 changes: 16 additions & 2 deletions app/src/trackpad.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ static bool mousemode;
static bool surface_mode;
static bool button_mode;

static bool enabled;

static int8_t xDelta, yDelta, scrollDelta;

static struct zmk_ptp_finger fingers[CONFIG_ZMK_TRACKPAD_MAX_FINGERS];
static struct zmk_ptp_finger fingers[5];
static const struct zmk_ptp_finger empty_finger = {0};

#if IS_ENABLED(CONFIG_ZMK_TRACKPAD_WORK_QUEUE_DEDICATED)
K_THREAD_STACK_DEFINE(trackpad_work_stack_area, CONFIG_ZMK_TRACKPAD_DEDICATED_THREAD_STACK_SIZE);
Expand All @@ -42,6 +45,10 @@ struct k_work_q *zmk_trackpad_work_q() {
#endif
}

void zmk_trackpad_set_enabled(bool enabled) {}

bool zmk_trackpad_get_enabled() { return enabled; }

static void handle_trackpad_ptp(const struct device *dev, const struct sensor_trigger *trig) {
int ret = sensor_sample_fetch(dev);
if (ret < 0) {
Expand Down Expand Up @@ -88,11 +95,17 @@ static void zmk_trackpad_tick(struct k_work *work) {
for (int i = 0; i < CONFIG_ZMK_TRACKPAD_MAX_FINGERS; i++)
if (contacts_to_send & BIT(i)) {
LOG_DBG("Trackpad sendy thing trigd %d", i);
zmk_hid_ptp_set(fingers[i], present_contacts, scantime, btns);
zmk_hid_ptp_set(fingers[i], present_contacts, scantime, button_mode ? btns : 0);
zmk_endpoints_send_ptp_report();
contacts_to_send &= !BIT(i);
return;
}
} else if (contacts_to_send && !surface_mode) {
// report buttons only
LOG_DBG("Trackpad button thing trigd");
zmk_hid_ptp_set(empty_finger, present_contacts, scantime, button_mode ? btns : 0);
zmk_endpoints_send_ptp_report();
contacts_to_send = 0;
}
}

Expand Down Expand Up @@ -177,6 +190,7 @@ static int trackpad_init() {
button_mode = true;
surface_mode = true;
zmk_trackpad_set_mouse_mode(true);
enabled = true;
return 0;
}

Expand Down

0 comments on commit 998511f

Please sign in to comment.