Support all RGB animation modes (Fixes #1)

* Added support for all RGB light modes to use typing speed

Except christmas lights because that is seizure-inducing at high speeds!

* Introduced a value range specific to each RGB mode

Because some modes are a little too much when running at full speed!
pull/3754/head
Chris Lewis 7 years ago committed by Chris Lewis
parent c8b160b410
commit 4d15b2d785

@ -197,7 +197,7 @@ bool process_record_quantum(keyrecord_t *record) {
keypos_t key = record->event.key;
uint16_t keycode;
if (typing_speed < 100) typing_speed += 1;
if (typing_speed < TYPING_SPEED_MAX_VALUE) typing_speed += 1;
#if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
/* TODO: Use store_or_get_action() or a similar function. */

@ -58,6 +58,7 @@
extern uint32_t default_layer_state;
//Used in rgblight.c to match RGB animation to typing speed
extern uint8_t typing_speed;
#define TYPING_SPEED_MAX_VALUE 100
#ifndef NO_ACTION_LAYER
extern uint32_t layer_state;

@ -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();

@ -168,4 +168,7 @@ void rgblight_effect_christmas(void);
void rgblight_effect_rgbtest(void);
void rgblight_effect_alternating(void);
void typing_speed_decay_task(void);
uint8_t typing_speed_matched_interval(uint8_t minValue, uint8_t maxValue);
#endif

Loading…
Cancel
Save