@ -570,8 +570,25 @@ void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b) {
rgblight_setrgb ( r , g , b ) ;
}
void typing_speed_decay_task ( ) {
static uint16_t decay_timer = 0 ;
if ( timer_elapsed ( decay_timer ) > 500 | | decay_timer = = 0 ) {
if ( typing_speed > 0 ) typing_speed - = 1 ;
decay_timer = timer_read ( ) ;
}
}
uint8_t typing_speed_matched_interval ( uint8_t minValue , uint8_t maxValue ) {
return MAX ( minValue , maxValue - ( maxValue - minValue ) * ( ( float ) typing_speed / TYPING_SPEED_MAX_VALUE ) ) ;
}
void rgblight_task ( void ) {
if ( rgblight_timer_enabled ) {
typing_speed_decay_task ( ) ;
// mode = 1, static light, do nothing here
if ( rgblight_config . mode > = 2 & & rgblight_config . mode < = 5 ) {
// mode = 2 to 5, breathing mode
@ -606,7 +623,7 @@ void rgblight_effect_breathing(uint8_t interval) {
static uint16_t last_timer = 0 ;
float val ;
if ( timer_elapsed ( last_timer ) < pgm_read_byte( & RGBLED_BREATHING_INTERVALS [ interval ] ) ) {
if ( timer_elapsed ( last_timer ) < typing_speed_matched_interval( 1 , 100 ) ) {
return ;
}
last_timer = timer_read ( ) ;
@ -621,7 +638,7 @@ void rgblight_effect_rainbow_mood(uint8_t interval) {
static uint16_t current_hue = 0 ;
static uint16_t last_timer = 0 ;
if ( timer_elapsed ( last_timer ) < pgm_read_byte( & RGBLED_RAINBOW_MOOD_INTERVALS [ interval ] ) ) {
if ( timer_elapsed ( last_timer ) < typing_speed_matched_interval( 5 , 100 ) ) {
return ;
}
last_timer = timer_read ( ) ;
@ -634,16 +651,7 @@ void rgblight_effect_rainbow_swirl(uint8_t interval) {
uint16_t hue ;
uint8_t i ;
//Improvement: move this code into rgblight_task() so that the typing_speed can be used across all RGB effects, not just swirl
static uint16_t decay_timer = 0 ;
if ( timer_elapsed ( decay_timer ) > 250 | | decay_timer = = 0 ) {
if ( typing_speed > 0 ) typing_speed - = 1 ;
//Improvement(?): decay by a greater rate depending on how big typing_speed is, so you can't reach max speed just by outpacing the regular decay
decay_timer = timer_read ( ) ;
}
//Improvement: make the usage of typing speed more easily configurable, either with a pre-processor toggle or with real-time key toggles
if ( timer_elapsed ( last_timer ) < MAX ( 1 , 100 - typing_speed ) ) {
if ( timer_elapsed ( last_timer ) < typing_speed_matched_interval ( 1 , 100 ) ) {
return ;
}
last_timer = timer_read ( ) ;
@ -672,7 +680,7 @@ void rgblight_effect_snake(uint8_t interval) {
if ( interval % 2 ) {
increment = - 1 ;
}
if ( timer_elapsed ( last_timer ) < pgm_read_byte( & RGBLED_SNAKE_INTERVALS [ interval / 2 ] ) ) {
if ( timer_elapsed ( last_timer ) < typing_speed_matched_interval( 5 , 100 ) ) {
return ;
}
last_timer = timer_read ( ) ;
@ -703,7 +711,7 @@ void rgblight_effect_snake(uint8_t interval) {
}
void rgblight_effect_knight ( uint8_t interval ) {
static uint16_t last_timer = 0 ;
if ( timer_elapsed ( last_timer ) < pgm_read_byte( & RGBLED_KNIGHT_INTERVALS [ interval ] ) ) {
if ( timer_elapsed ( last_timer ) < typing_speed_matched_interval( 5 , 100 ) ) {
return ;
}
last_timer = timer_read ( ) ;