diff options
Diffstat (limited to 'quantum')
| -rw-r--r-- | quantum/wpm.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/quantum/wpm.c b/quantum/wpm.c index bec419a48..e711e9fe7 100644 --- a/quantum/wpm.c +++ b/quantum/wpm.c | |||
| @@ -17,6 +17,8 @@ | |||
| 17 | 17 | ||
| 18 | #include "wpm.h" | 18 | #include "wpm.h" |
| 19 | 19 | ||
| 20 | #include <math.h> | ||
| 21 | |||
| 20 | // WPM Stuff | 22 | // WPM Stuff |
| 21 | static uint8_t current_wpm = 0; | 23 | static uint8_t current_wpm = 0; |
| 22 | static uint16_t wpm_timer = 0; | 24 | static uint16_t wpm_timer = 0; |
| @@ -69,14 +71,22 @@ __attribute__((weak)) uint8_t wpm_regress_count(uint16_t keycode) { | |||
| 69 | void update_wpm(uint16_t keycode) { | 71 | void update_wpm(uint16_t keycode) { |
| 70 | if (wpm_keycode(keycode)) { | 72 | if (wpm_keycode(keycode)) { |
| 71 | if (wpm_timer > 0) { | 73 | if (wpm_timer > 0) { |
| 72 | current_wpm += ((60000 / timer_elapsed(wpm_timer) / WPM_ESTIMATED_WORD_SIZE) - current_wpm) * wpm_smoothing; | 74 | uint16_t latest_wpm = 60000 / timer_elapsed(wpm_timer) / WPM_ESTIMATED_WORD_SIZE; |
| 75 | if (latest_wpm > UINT8_MAX) { | ||
| 76 | latest_wpm = UINT8_MAX; | ||
| 77 | } | ||
| 78 | current_wpm += ceilf((latest_wpm - current_wpm) * wpm_smoothing); | ||
| 73 | } | 79 | } |
| 74 | wpm_timer = timer_read(); | 80 | wpm_timer = timer_read(); |
| 75 | } | 81 | } |
| 76 | #ifdef WPM_ALLOW_COUNT_REGRESSION | 82 | #ifdef WPM_ALLOW_COUNT_REGRESSION |
| 77 | uint8_t regress = wpm_regress_count(keycode); | 83 | uint8_t regress = wpm_regress_count(keycode); |
| 78 | if (regress) { | 84 | if (regress) { |
| 79 | current_wpm -= regress; | 85 | if (current_wpm < regress) { |
| 86 | current_wpm = 0; | ||
| 87 | } else { | ||
| 88 | current_wpm -= regress; | ||
| 89 | } | ||
| 80 | wpm_timer = timer_read(); | 90 | wpm_timer = timer_read(); |
| 81 | } | 91 | } |
| 82 | #endif | 92 | #endif |
