aboutsummaryrefslogtreecommitdiff
path: root/quantum/velocikey.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/velocikey.c')
-rw-r--r--quantum/velocikey.c36
1 files changed, 16 insertions, 20 deletions
diff --git a/quantum/velocikey.c b/quantum/velocikey.c
index 550c3b70a..6b7f82d95 100644
--- a/quantum/velocikey.c
+++ b/quantum/velocikey.c
@@ -4,23 +4,21 @@
4#include "eeprom.h" 4#include "eeprom.h"
5 5
6#ifndef MIN 6#ifndef MIN
7#define MIN(a,b) (((a)<(b))?(a):(b)) 7# define MIN(a, b) (((a) < (b)) ? (a) : (b))
8#endif 8#endif
9#ifndef MAX 9#ifndef MAX
10#define MAX(a,b) (((a)>(b))?(a):(b)) 10# define MAX(a, b) (((a) > (b)) ? (a) : (b))
11#endif 11#endif
12 12
13#define TYPING_SPEED_MAX_VALUE 200 13#define TYPING_SPEED_MAX_VALUE 200
14uint8_t typing_speed = 0; 14uint8_t typing_speed = 0;
15 15
16bool velocikey_enabled(void) { 16bool velocikey_enabled(void) { return eeprom_read_byte(EECONFIG_VELOCIKEY) == 1; }
17 return eeprom_read_byte(EECONFIG_VELOCIKEY) == 1;
18}
19 17
20void velocikey_toggle(void) { 18void velocikey_toggle(void) {
21 if (velocikey_enabled()) 19 if (velocikey_enabled())
22 eeprom_update_byte(EECONFIG_VELOCIKEY, 0); 20 eeprom_update_byte(EECONFIG_VELOCIKEY, 0);
23 else 21 else
24 eeprom_update_byte(EECONFIG_VELOCIKEY, 1); 22 eeprom_update_byte(EECONFIG_VELOCIKEY, 1);
25} 23}
26 24
@@ -29,18 +27,16 @@ void velocikey_accelerate(void) {
29} 27}
30 28
31void velocikey_decelerate(void) { 29void velocikey_decelerate(void) {
32 static uint16_t decay_timer = 0; 30 static uint16_t decay_timer = 0;
33 31
34 if (timer_elapsed(decay_timer) > 500 || decay_timer == 0) { 32 if (timer_elapsed(decay_timer) > 500 || decay_timer == 0) {
35 if (typing_speed > 0) typing_speed -= 1; 33 if (typing_speed > 0) typing_speed -= 1;
36 //Decay a little faster at half of max speed 34 // Decay a little faster at half of max speed
37 if (typing_speed > TYPING_SPEED_MAX_VALUE / 2) typing_speed -= 1; 35 if (typing_speed > TYPING_SPEED_MAX_VALUE / 2) typing_speed -= 1;
38 //Decay even faster at 3/4 of max speed 36 // Decay even faster at 3/4 of max speed
39 if (typing_speed > TYPING_SPEED_MAX_VALUE / 4 * 3) typing_speed -= 2; 37 if (typing_speed > TYPING_SPEED_MAX_VALUE / 4 * 3) typing_speed -= 2;
40 decay_timer = timer_read(); 38 decay_timer = timer_read();
41 } 39 }
42} 40}
43 41
44uint8_t velocikey_match_speed(uint8_t minValue, uint8_t maxValue) { 42uint8_t velocikey_match_speed(uint8_t minValue, uint8_t maxValue) { return MAX(minValue, maxValue - (maxValue - minValue) * ((float)typing_speed / TYPING_SPEED_MAX_VALUE)); }
45 return MAX(minValue, maxValue - (maxValue - minValue) * ((float)typing_speed / TYPING_SPEED_MAX_VALUE));
46}