7 #define MIN(a,b) (((a)<(b))?(a):(b))
10 #define MAX(a,b) (((a)>(b))?(a):(b))
13 #define TYPING_SPEED_MAX_VALUE 200
14 uint8_t typing_speed = 0;
16 bool velocikey_enabled(void) {
17 return eeprom_read_byte(EECONFIG_VELOCIKEY) == 1;
20 void velocikey_toggle(void) {
21 if (velocikey_enabled())
22 eeprom_update_byte(EECONFIG_VELOCIKEY, 0);
24 eeprom_update_byte(EECONFIG_VELOCIKEY, 1);
27 void velocikey_accelerate(void) {
28 if (typing_speed < TYPING_SPEED_MAX_VALUE) typing_speed += (TYPING_SPEED_MAX_VALUE / 100);
31 void velocikey_decelerate(void) {
32 static uint16_t decay_timer = 0;
34 if (timer_elapsed(decay_timer) > 500 || decay_timer == 0) {
35 if (typing_speed > 0) typing_speed -= 1;
36 //Decay a little faster at half of max speed
37 if (typing_speed > TYPING_SPEED_MAX_VALUE / 2) typing_speed -= 1;
38 //Decay even faster at 3/4 of max speed
39 if (typing_speed > TYPING_SPEED_MAX_VALUE / 4 * 3) typing_speed -= 2;
40 decay_timer = timer_read();
44 uint8_t velocikey_match_speed(uint8_t minValue, uint8_t maxValue) {
45 return MAX(minValue, maxValue - (maxValue - minValue) * ((float)typing_speed / TYPING_SPEED_MAX_VALUE));