From fae1b8706aa290cc8c1d48f70fd2280eaa919ef1 Mon Sep 17 00:00:00 2001 From: acheronfail Date: Thu, 15 Aug 2024 22:01:06 +0930 Subject: [PATCH] LEDs: add rainbow effects Setting the headlights to Solid with white, and then setting the taillights to Rainbow Cycle allows users to replicate the "Mullet" effect from the Float package. Using Rainbow Cycle on the front and the back replicates the "Rave" effect from the Float package. Also added an RGB Fade effect which smoothly transitions between colors. Feature: Add the Rainbow Cycle and RGB Fade LED effects. --- src/conf/datatypes.h | 2 ++ src/conf/settings.xml | 10 ++++++++++ src/leds.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/src/conf/datatypes.h b/src/conf/datatypes.h index 14a39bf..bbd276a 100644 --- a/src/conf/datatypes.h +++ b/src/conf/datatypes.h @@ -86,6 +86,8 @@ typedef enum { LED_MODE_STROBE, LED_MODE_KNIGHT_RIDER, LED_MODE_FELONY, + LED_MODE_RAINBOW_CYCLE, + LED_MODE_RGB_FADE, } LedMode; typedef enum { diff --git a/src/conf/settings.xml b/src/conf/settings.xml index 5ea47bb..81ff86a 100644 --- a/src/conf/settings.xml +++ b/src/conf/settings.xml @@ -2255,6 +2255,8 @@ p, li { white-space: pre-wrap; } Strobe Knight Rider Felony + Rainbow Cycle + RGB Fade Front Brightness @@ -2417,6 +2419,8 @@ p, li { white-space: pre-wrap; } Strobe Knight Rider Felony + Rainbow Cycle + RGB Fade Rear Brightness @@ -2579,6 +2583,8 @@ p, li { white-space: pre-wrap; } Strobe Knight Rider Felony + Rainbow Cycle + RGB Fade Headlights Brightness @@ -2743,6 +2749,8 @@ p, li { white-space: pre-wrap; } Strobe Knight Rider Felony + Rainbow Cycle + RGB Fade Taillights Brightness @@ -3035,6 +3043,8 @@ p, li { white-space: pre-wrap; } Strobe Knight Rider Felony + Rainbow Cycle + RGB Fade Status Idle Brightness diff --git a/src/leds.c b/src/leds.c index a7dae68..b682226 100644 --- a/src/leds.c +++ b/src/leds.c @@ -308,6 +308,32 @@ static void anim_felony(Leds *leds, const LedStrip *strip, const LedBar *bar, fl } } +static const uint32_t rainbow_cycle_colors[] = { + 0x00FFFF00, + 0x0000FF00, + 0x0000FFFF, + 0x000000FF, + 0x00FF00FF, + 0x00FF0000, +}; +static const uint8_t rainbow_cycle_colors_len = + sizeof(rainbow_cycle_colors) / sizeof(rainbow_cycle_colors[0]); + +static void anim_rainbow_cycle(Leds *leds, const LedStrip *strip, float time) { + uint8_t color_idx = (uint8_t) (time / 0.1f) % rainbow_cycle_colors_len; + strip_set_color(leds, strip, rainbow_cycle_colors[color_idx], strip->brightness, 1.0f); +} + +static void anim_rgb_fade(Leds *leds, const LedStrip *strip, float time) { + strip_set_color( + leds, + strip, + color_wheel((uint8_t) floorf(fmodf(time, 4.0f) * 255.0f)), + strip->brightness, + 1.0f + ); +} + static void led_strip_animate(Leds *leds, const LedStrip *strip, const LedBar *bar, float time) { time *= bar->speed; @@ -330,6 +356,12 @@ static void led_strip_animate(Leds *leds, const LedStrip *strip, const LedBar *b case LED_MODE_FELONY: anim_felony(leds, strip, bar, time); break; + case LED_MODE_RAINBOW_CYCLE: + anim_rainbow_cycle(leds, strip, time); + break; + case LED_MODE_RGB_FADE: + anim_rgb_fade(leds, strip, time); + break; } }