Skip to content

Commit

Permalink
Merge pull request qmk#5 from ankostis/readable-formula
Browse files Browse the repository at this point in the history
refact: alias maccel letters for readable formula
  • Loading branch information
burkfers committed Mar 6, 2024
2 parents be0bb2b + df20161 commit fdc7413
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion maccel/maccel.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@ report_mouse_t pointing_device_task_maccel(report_mouse_t mouse_report) {
// correct raw velocity for dpi
const float velocity = dpi_correction * velocity_raw;
// calculate mouse acceleration factor: f(dv) = c - ((c-1) / ((1 + e^(x(x - b)) * a/z)))
const float maccel_factor = g_maccel_config.limit - (g_maccel_config.limit - 1) / powf(1 + expf(g_maccel_config.takeoff * (velocity - g_maccel_config.offset)), g_maccel_config.growth_rate / g_maccel_config.takeoff);
const float k = g_maccel_config.takeoff;
const float g = g_maccel_config.growth_rate;
const float s = g_maccel_config.offset;
const float m = g_maccel_config.limit;
// acceleration factor: y(x) = M - (M - 1) / {1 + e^[K(x - S)]}^(G/K)
// Generalised Sigmoid Function, see https://www.desmos.com/calculator/xkhejelty8
const float maccel_factor = m - (m - 1) / powf(1 + expf(k * (velocity - s)), g / k);
// calculate accelerated delta X and Y values and clamp:
const mouse_xy_report_t x = CONSTRAIN_REPORT(mouse_report.x * maccel_factor);
const mouse_xy_report_t y = CONSTRAIN_REPORT(mouse_report.y * maccel_factor);
Expand Down

0 comments on commit fdc7413

Please sign in to comment.