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

Minor carry timeout, formula letters, fixes and doc nitpicks #10

Open
wants to merge 11 commits into
base: maccel-dev
Choose a base branch
from
15 changes: 11 additions & 4 deletions maccel/maccel.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,22 @@
#ifndef MACCEL_LIMIT
# define MACCEL_LIMIT 0.2 // (M) lower limit of accel curve (minimum acceleration factor)
#endif
#ifndef MACCEL_CPI_THROTTLE_MS
# define MACCEL_CPI_THROTTLE_MS 200 // milliseconds to wait between requesting the device's current DPI
#endif
#ifndef MACCEL_LIMIT_UPPER
# define MACCEL_LIMIT_UPPER 1 // upper limit of accel curve, recommended to leave at 1; adjust DPI setting instead.
#endif
#ifndef MACCEL_CPI_THROTTLE_MS
# define MACCEL_CPI_THROTTLE_MS 200 // milliseconds to wait between requesting the device's current DPI
#endif
burkfers marked this conversation as resolved.
Show resolved Hide resolved
#ifndef MACCEL_ROUNDING_CARRY_TIMEOUT_MS
# define MACCEL_ROUNDING_CARRY_TIMEOUT_MS 300 // Elapsed time after which quantization error gets reset.
#endif
/**
* Scale acceleration curve's v-input so that its params are not uncannily small
* and floats do not overflow in the accel formula (eg. `exp(709.8)` for doubles).
* Eventually the accel formula is calculated as if the pointer reports @ 1000 CPI,
* but "counts" are expressed as float (vs integer for the hw "counts").
*/
#define MACCEL_MAGNIFICATION_DPI 1000.0

maccel_config_t g_maccel_config = {
// clang-format off
Expand Down Expand Up @@ -125,7 +132,7 @@ report_mouse_t pointing_device_task_maccel(report_mouse_t mouse_report) {
device_cpi = pointing_device_get_cpi();
}
// calculate dpi correction factor (for normalizing velocity range across different user dpi settings)
const float dpi_correction = (float)1000.0f / device_cpi;
const float dpi_correction = (float)MACCEL_MAGNIFICATION_DPI / device_cpi;
Copy link
Owner

@burkfers burkfers Mar 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quote @Wimads:

explain x1000 factor: don't accept I don't think this should be turned into a variable, and thus also doesn't require any extra explanation. It scales the v.in range to equivalent of DPI 1000, but that is a fairly arbitrary number - might as well have set it to 20000, and the curve would still work the same. The only thing it would affect is the usable range of the main variables, which is enough to discourage people from playing around with it imho.

I approve of turning a magic number into a preprocessor constant. However, it should have a more meaningful name, for example MACCEL_CPI_EQUIVALENT_SCALE. Something that implies this is the dpi-equivalence we're scaling to.
Further comments should not be placed to discourage modification, as it's not intended as a user-tunable parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will rename it into MACCEL_MAGNIFICATION_CPI_EQUIVALENT and add the trimmed-down description proposed in discord along with a discouragement admonition:

Scale acceleration curve's V-input @ 1000 CPI so that its parameters
are not uncannily small and/or formula floats overflow.
Any modified value will invalidate curve parameters.

Copy link
Collaborator

@Wimads Wimads Mar 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why magnification? I don't understand that wording in this context. Its normalizing (or scaling if you prefer) v-in to an equivalent of 1000 CPI. So MACCEL_CPI_EQUIVALENT_SCALE as burkfers suggested makes more sense to me. Or MACCEL_NORMALIZING_CPI_EQUIVALENT perhaps.

As for the comment, something like this covers my intention better I think:
// Normalizing input velocity to an equivalent of CPI=1000, for consistent accel behavior across different CPI settings.
// Modifying CPI_EQUIVALENT will invalidate the curve parameters.
^^ which should then replace this existing comment:
// calculate dpi correction factor (for normalizing velocity range across different user dpi settings)

// calculate euclidean distance moved (sqrt(x^2 + y^2))
const float distance = sqrtf(mouse_report.x * mouse_report.x + mouse_report.y * mouse_report.y);
// calculate delta velocity: dv = distance/dt
Expand Down