Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use unsigned integer for kinetic speed #21151

Merged
merged 1 commit into from
Jun 7, 2023

Commits on Jun 7, 2023

  1. Use unsigned integer for kinetic speed

    The current kinetic mouse key function uses resource intensive
    floating point to compute the quadratic curve speed. But the
    result is returned as an unsigned 8-bit integer value. The code
    line where fractional accuracy is important is at the division of
    `speed = (uint8_t)(speed / (1000.0f / mk_interval));`
    
    This change uses 16-bit integers for the quadratic calculation
    variables, which are less resource-intensive. The output acceleration
    curve is almost unchanged with the default `MOUSEKEY_INTERVAL` value.
    
    Truncation is used to round division output to an integer. With
    higher `MOUSEKEY_INTERVAL` values, rounding appears more accurate
    using 16-bit integer versus floating point. Example:
    
    `mk_interval = 30`
    
    | speed | (uint8_t)(speed / (1000.0f / mk_interval)) | (uint8_t)(speed / (1000U / mk_interval)) |
    |------|----|----|
    |  292 |  8 |  9 |
    |  484 | 14 | 15 |
    | 1060 | 31 | 32 |
    | 1660 | 49 | 50 |
    filterpaper committed Jun 7, 2023
    Configuration menu
    Copy the full SHA
    1b2b209 View commit details
    Browse the repository at this point in the history