Skip to content

Commit

Permalink
Use unsigned integer for mousekey kinetic speed (qmk#21151)
Browse files Browse the repository at this point in the history
  • Loading branch information
filterpaper authored Jun 7, 2023
1 parent a02230f commit fd1e638
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions quantum/mousekey.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ uint8_t mk_time_to_max = MOUSEKEY_TIME_TO_MAX;
uint8_t mk_wheel_delay = MOUSEKEY_WHEEL_DELAY / 10;
/* milliseconds between repeated motion events (0-255) */
# ifdef MK_KINETIC_SPEED
float mk_wheel_interval = 1000.0f / MOUSEKEY_WHEEL_INITIAL_MOVEMENTS;
uint16_t mk_wheel_interval = 1000U / MOUSEKEY_WHEEL_INITIAL_MOVEMENTS;
# else
uint8_t mk_wheel_interval = MOUSEKEY_WHEEL_INTERVAL;
# endif
Expand Down Expand Up @@ -190,37 +190,37 @@ const uint16_t mk_decelerated_speed = MOUSEKEY_DECELERATED_SPEED;
const uint16_t mk_initial_speed = MOUSEKEY_INITIAL_SPEED;

static uint8_t move_unit(void) {
float speed = mk_initial_speed;
uint16_t speed = mk_initial_speed;

if (mousekey_accel & ((1 << 0) | (1 << 2))) {
speed = mousekey_accel & (1 << 2) ? mk_accelerated_speed : mk_decelerated_speed;
} else if (mousekey_repeat && mouse_timer) {
const float time_elapsed = timer_elapsed(mouse_timer) / 50;
speed = mk_initial_speed + MOUSEKEY_MOVE_DELTA * time_elapsed + MOUSEKEY_MOVE_DELTA * 0.5 * time_elapsed * time_elapsed;
const uint16_t time_elapsed = timer_elapsed(mouse_timer) / 50;
speed = mk_initial_speed + MOUSEKEY_MOVE_DELTA * time_elapsed + MOUSEKEY_MOVE_DELTA * 0.5 * time_elapsed * time_elapsed;

speed = speed > mk_base_speed ? mk_base_speed : speed;
}

/* convert speed to USB mouse speed 1 to 127 */
speed = (uint8_t)(speed / (1000.0f / mk_interval));
speed = (uint8_t)(speed / (1000U / mk_interval));
speed = speed < 1 ? 1 : speed;

return speed > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : speed;
}

static uint8_t wheel_unit(void) {
float speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS;
uint16_t speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS;

if (mousekey_accel & ((1 << 0) | (1 << 2))) {
speed = mousekey_accel & (1 << 2) ? MOUSEKEY_WHEEL_ACCELERATED_MOVEMENTS : MOUSEKEY_WHEEL_DECELERATED_MOVEMENTS;
} else if (mousekey_wheel_repeat && mouse_timer) {
if (mk_wheel_interval != MOUSEKEY_WHEEL_BASE_MOVEMENTS) {
const float time_elapsed = timer_elapsed(mouse_timer) / 50;
speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS + 1 * time_elapsed + 1 * 0.5 * time_elapsed * time_elapsed;
const uint16_t time_elapsed = timer_elapsed(mouse_timer) / 50;
speed = MOUSEKEY_WHEEL_INITIAL_MOVEMENTS + 1 * time_elapsed + 1 * 0.5 * time_elapsed * time_elapsed;
}
speed = speed > MOUSEKEY_WHEEL_BASE_MOVEMENTS ? MOUSEKEY_WHEEL_BASE_MOVEMENTS : speed;
}
mk_wheel_interval = 1000.0f / speed;
mk_wheel_interval = 1000U / speed;

return (uint8_t)speed > MOUSEKEY_WHEEL_INITIAL_MOVEMENTS ? 2 : 1;
}
Expand Down

0 comments on commit fd1e638

Please sign in to comment.