Skip to content

Commit

Permalink
Simplified tick rate and made it configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
krikun98 committed Jan 28, 2022
1 parent eb089b5 commit 96660dc
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
4 changes: 4 additions & 0 deletions app/src/mouse/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ menuconfig ZMK_MOUSE

if ZMK_MOUSE

config ZMK_MOUSE_TICK_DURATION
int "Mouse tick duration in ms"
default 8

choice ZMK_MOUSE_WORK_QUEUE
prompt "Work queue selection for mouse events"
default ZMK_MOUSE_WORK_QUEUE_DEDICATED
Expand Down
2 changes: 1 addition & 1 deletion app/src/mouse/key_listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static int mouse_timer_ref_count = 0;

void mouse_timer_ref() {
if (mouse_timer_ref_count == 0) {
k_timer_start(&mouse_timer, K_NO_WAIT, K_MSEC(10));
k_timer_start(&mouse_timer, K_NO_WAIT, K_MSEC(CONFIG_ZMK_MOUSE_TICK_DURATION));
}
mouse_timer_ref_count += 1;
// trigger the first mouse tick event immediately
Expand Down
3 changes: 0 additions & 3 deletions app/src/mouse/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
*/

#include <kernel.h>
#include <init.h>
#include <device.h>
#include <devicetree.h>

#if IS_ENABLED(CONFIG_ZMK_MOUSE_WORK_QUEUE_DEDICATED)

Expand Down
10 changes: 2 additions & 8 deletions app/src/mouse/tick_listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ static float powf(float base, float exponent) {

struct movement_state {
int64_t start;
int64_t last_tick;
struct vector2d fractional_remainder;
};

Expand All @@ -52,8 +51,6 @@ static struct mouse_config scroll_config = (struct mouse_config){
.acceleration_exponent = 2.0,
};

static int64_t ms_since_last_tick(int64_t last_tick, int64_t now) { return now - last_tick; }

static int64_t ms_since_start(int64_t start, int64_t now) {
int64_t move_duration = now - start;
// start can be in the future if there's a delay
Expand Down Expand Up @@ -88,20 +85,17 @@ static struct vector2d update_movement(struct movement_state *state, struct mous
}
if (state->start == 0) {
state->start = now + config->delay_ms;
state->last_tick = now;
}

int64_t tick_duration = ms_since_last_tick(state->last_tick, now);
int64_t move_duration = ms_since_start(state->start, now);
move = (struct vector2d){
.x = speed(config, max_speed.x, move_duration) * tick_duration / 1000,
.y = speed(config, max_speed.y, move_duration) * tick_duration / 1000,
.x = speed(config, max_speed.x, move_duration) * CONFIG_ZMK_MOUSE_TICK_DURATION / 1000,
.y = speed(config, max_speed.y, move_duration) * CONFIG_ZMK_MOUSE_TICK_DURATION / 1000,
};

track_remainder(&(move.x), &state->fractional_remainder.x);
track_remainder(&(move.y), &state->fractional_remainder.y);

state->last_tick = now;
return move;
}

Expand Down

0 comments on commit 96660dc

Please sign in to comment.