From c1c5922aae7b60b7c7d13d3769350eed9dda17ab Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Fri, 22 Feb 2019 02:22:46 +1100 Subject: Velocikey: Match RGB animation speed to typing speed (#3754) * Draft commit of typing speed RGB control * More information in the readme * 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! * Update readme.md * Update readme.md * Re-arrange typing_speed definitions (Fixes #5) (#6) * Re-arrange variable definitions to avoid including quantum.h from rgblight.c * Fix a compilation error when trying to run make test:all * Tweaks to the typing speed decay rate * Renamed to momentum; moved implementation into dedicated files * Groundwork for toggling momentum on/off (currently always on) * Add EEPROM toggle for momentum-matching * Moved momentum out of RGBLIGHT_ENABLE toggles so it's more generic * Move momentum decay task out of rgblight_task() * Fix missing momentum.h in lufa.c * Experimental LED support (untested) * Draft commit of typing speed RGB control * More information in the readme * 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! * Update readme.md * Update readme.md * Re-arrange typing_speed definitions (Fixes #5) (#6) * Re-arrange variable definitions to avoid including quantum.h from rgblight.c * Fix a compilation error when trying to run make test:all * Tweaks to the typing speed decay rate * Renamed to momentum; moved implementation into dedicated files * Groundwork for toggling momentum on/off (currently always on) * Add EEPROM toggle for momentum-matching * Moved momentum out of RGBLIGHT_ENABLE toggles so it's more generic * Move momentum decay task out of rgblight_task() * Fix missing momentum.h in lufa.c * Added documentation * Renamed feature to velocikey * Reverted readme to original state * Correct the readme title * Updated feature name in the docs * Update EECONFIG name * Add compile-time toggles for velocikey * Update feature documentation * Revert "Merge branch 'led-support' into master" This reverts commit e123ff5febf61639b9a9020748e1c2e2313460ff, reversing changes made to df111a55b9d4929182e16108b1c0ead15b16df97. * Move velocikey EECONFIG definition to depend on VELOCIKEY_ENABLE * Rename decay_task function to decelerate * Apply suggestions from code review Co-Authored-By: chrislewisdev * Re-order eeconfig definitions * Apply coding conventions * Apply #ifdef check in lufa.c * Refactored interval time checks into one functionc * Small rename * Fix unused function error for layouts not using all rgb effects * Only update EEPROM if Velocikey is enabled * Incorporate code review feedback * Small adjustment to top-end decay rate * Add Velocikey documentation to table of contents * Bring tetris:default keymap size down by disabling audio --- quantum/rgblight.c | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) (limited to 'quantum/rgblight.c') diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 45d521786e..57de56df70 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -30,6 +30,9 @@ #include "rgblight.h" #include "debug.h" #include "led_tables.h" +#ifdef VELOCIKEY_ENABLE + #include "velocikey.h" +#endif #define _RGBM_SINGLE_STATIC(sym) RGBLIGHT_MODE_ ## sym, #define _RGBM_SINGLE_DYNAMIC(sym) @@ -607,6 +610,19 @@ void rgblight_sethsv_at(uint16_t hue, uint8_t sat, uint8_t val, uint8_t index) { rgblight_setrgb_at(tmp_led.r, tmp_led.g, tmp_led.b, index); } +#if defined(RGBLIGHT_EFFECT_BREATHING) || defined(RGBLIGHT_EFFECT_RAINBOW_MOOD) || defined(RGBLIGHT_EFFECT_RAINBOW_SWIRL) \ + || defined(RGBLIGHT_EFFECT_SNAKE) || defined(RGBLIGHT_EFFECT_KNIGHT) + +static uint8_t get_interval_time(const uint8_t* default_interval_address, uint8_t velocikey_min, uint8_t velocikey_max) { + return +#ifdef VELOCIKEY_ENABLE + velocikey_enabled() ? velocikey_match_speed(velocikey_min, velocikey_max) : +#endif + pgm_read_byte(default_interval_address); +} + +#endif + void rgblight_setrgb_range(uint8_t r, uint8_t g, uint8_t b, uint8_t start, uint8_t end) { if (!rgblight_config.enable || start < 0 || start >= end || end > RGBLED_NUM) { return; } @@ -707,6 +723,7 @@ void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b) { } void rgblight_task(void) { + if (rgblight_timer_enabled) { // static light mode, do nothing here if ( 1 == 0 ) { //dummy @@ -778,7 +795,9 @@ 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])) { + uint8_t interval_time = get_interval_time(&RGBLED_RAINBOW_SWIRL_INTERVALS[interval / 2], 1, 100); + + if (timer_elapsed(last_timer) < interval_time) { return; } last_timer = timer_read(); @@ -798,7 +817,9 @@ 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])) { + uint8_t interval_time = get_interval_time(&RGBLED_RAINBOW_MOOD_INTERVALS[interval], 5, 100); + + if (timer_elapsed(last_timer) < interval_time) { return; } last_timer = timer_read(); @@ -820,7 +841,10 @@ void rgblight_effect_rainbow_swirl(uint8_t interval) { static uint16_t last_timer = 0; uint16_t hue; uint8_t i; - if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_RAINBOW_SWIRL_INTERVALS[interval / 2])) { + + uint8_t interval_time = get_interval_time(&RGBLED_RAINBOW_SWIRL_INTERVALS[interval / 2], 1, 100); + + if (timer_elapsed(last_timer) < interval_time) { return; } last_timer = timer_read(); @@ -855,7 +879,10 @@ 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])) { + + uint8_t interval_time = get_interval_time(&RGBLED_SNAKE_INTERVALS[interval / 2], 1, 200); + + if (timer_elapsed(last_timer) < interval_time) { return; } last_timer = timer_read(); @@ -892,7 +919,10 @@ const uint8_t RGBLED_KNIGHT_INTERVALS[] PROGMEM = {127, 63, 31}; 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])) { + + uint8_t interval_time = get_interval_time(&RGBLED_KNIGHT_INTERVALS[interval], 5, 100); + + if (timer_elapsed(last_timer) < interval_time) { return; } last_timer = timer_read(); -- cgit v1.2.3