diff --git a/src/utils.cpp b/src/utils.cpp index 617b7ba..cd1a112 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -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(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()