mirror of
https://github.com/qmk/qmk_firmware.git
synced 2025-07-15 20:31:27 +00:00
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!
This commit is contained in:
parent
876cb7a14f
commit
5f2b065dad
@ -194,7 +194,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. */
|
||||
|
@ -57,6 +57,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;
|
||||
|
@ -569,8 +569,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
|
||||
@ -603,7 +620,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();
|
||||
@ -618,7 +635,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();
|
||||
@ -631,16 +648,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();
|
||||
@ -669,7 +677,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();
|
||||
@ -700,7 +708,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();
|
||||
|
@ -167,4 +167,7 @@ void rgblight_effect_knight(uint8_t interval);
|
||||
void rgblight_effect_christmas(void);
|
||||
void rgblight_effect_rgbtest(void);
|
||||
|
||||
void typing_speed_decay_task(void);
|
||||
uint8_t typing_speed_matched_interval(uint8_t minValue, uint8_t maxValue);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user