Simplified tick rate and made it configurable
This commit is contained in:
parent
eb089b5f29
commit
96660dce4f
4 changed files with 7 additions and 12 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue