smoothing calcWPM
This commit is contained in:
parent
0e92c502b3
commit
27d300f227
1 changed files with 15 additions and 1 deletions
|
@ -8,9 +8,23 @@
|
||||||
|
|
||||||
uint8_t calcWPM(float percent, uint8_t wpmMin, uint8_t wpmMax)
|
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;
|
auto wpm = (percent * (wpmMax - wpmMin) / 100) + wpmMin;
|
||||||
uint8_t result = static_cast<uint8_t>(std::round(wpm));
|
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()
|
float potiRead()
|
||||||
|
|
Loading…
Reference in a new issue