diff options
author | Albert Y <76888457+filterpaper@users.noreply.github.com> | 2023-06-08 04:12:49 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-07 13:12:49 -0700 |
commit | fd1e638c28128601725e84eb4739128301ecfb3c (patch) | |
tree | 8f7b185ddc83ab3ef328f901b7d8fa41916f345b | |
parent | a02230f6fc71cad91820a4754aae9223a5ccdf20 (diff) |
Use unsigned integer for mousekey kinetic speed (#21151)
-rw-r--r-- | quantum/mousekey.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/quantum/mousekey.c b/quantum/mousekey.c index df8aa613be..ede055dc8f 100644 --- a/quantum/mousekey.c +++ b/quantum/mousekey.c @@ -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 @@ -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; } |