smoothing calcWPM

This commit is contained in:
Martin Brodbeck 2024-03-06 10:53:16 +01:00
parent 0e92c502b3
commit 27d300f227
1 changed files with 15 additions and 1 deletions

View File

@ -8,9 +8,23 @@
uint8_t calcWPM(float percent, uint8_t wpmMin, uint8_t wpmMax)
{
static float lastPercent {0};
static float lastResult {0};
auto wpm = (percent * (wpmMax - wpmMin) / 100) + wpmMin;
uint8_t result = static_cast<uint8_t>(std::round(wpm));
return result;
float amountChanged = std::abs(percent - lastPercent);
// Only change WPM if poti value change was big enough
// (Preventing rapid WPM jumps back and forth.)
if (amountChanged > 0.6) {
lastPercent = percent;
lastResult = result;
return result;
} else {
return lastResult;
};
}
float potiRead()