summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQMK Bot <hello@qmk.fm>2021-08-03 21:40:39 +0000
committerQMK Bot <hello@qmk.fm>2021-08-03 21:40:39 +0000
commitc48d9c2b2aaae7bb77e6e3a23d5126f63a47be4f (patch)
tree5aed15fe545a6175d4ef9a79b7a37d07b8943a1a
parent982b782ce30e421f2ad3034bc86efdec58c2ea88 (diff)
parent2b097d670a9fa458b8d059f824a0cbbd5b6c6659 (diff)
Merge remote-tracking branch 'origin/master' into develop
-rw-r--r--quantum/wpm.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/quantum/wpm.c b/quantum/wpm.c
index bec419a48e..e711e9fe73 100644
--- a/quantum/wpm.c
+++ b/quantum/wpm.c
@@ -17,6 +17,8 @@
#include "wpm.h"
+#include <math.h>
+
// WPM Stuff
static uint8_t current_wpm = 0;
static uint16_t wpm_timer = 0;
@@ -69,14 +71,22 @@ __attribute__((weak)) uint8_t wpm_regress_count(uint16_t keycode) {
void update_wpm(uint16_t keycode) {
if (wpm_keycode(keycode)) {
if (wpm_timer > 0) {
- current_wpm += ((60000 / timer_elapsed(wpm_timer) / WPM_ESTIMATED_WORD_SIZE) - current_wpm) * wpm_smoothing;
+ uint16_t latest_wpm = 60000 / timer_elapsed(wpm_timer) / WPM_ESTIMATED_WORD_SIZE;
+ if (latest_wpm > UINT8_MAX) {
+ latest_wpm = UINT8_MAX;
+ }
+ current_wpm += ceilf((latest_wpm - current_wpm) * wpm_smoothing);
}
wpm_timer = timer_read();
}
#ifdef WPM_ALLOW_COUNT_REGRESSION
uint8_t regress = wpm_regress_count(keycode);
if (regress) {
- current_wpm -= regress;
+ if (current_wpm < regress) {
+ current_wpm = 0;
+ } else {
+ current_wpm -= regress;
+ }
wpm_timer = timer_read();
}
#endif