From 65a64e4e2a617e7f7f9e7eb916b29ddb810ee758 Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Thu, 30 Sep 2021 16:20:09 +0200 Subject: [PATCH] Preparations for new ledstrip animations --- main/actions/ledstripanimationactions.h | 12 +++++ .../menus/ledstripselectanimationmenu.h | 12 +++-- main/ledstrip.h | 48 ++++++++++++++----- main/ledstripdefines.h | 2 + main/texts.h | 2 + 5 files changed, 60 insertions(+), 16 deletions(-) diff --git a/main/actions/ledstripanimationactions.h b/main/actions/ledstripanimationactions.h index 00b80ea..781b0c7 100644 --- a/main/actions/ledstripanimationactions.h +++ b/main/actions/ledstripanimationactions.h @@ -32,4 +32,16 @@ class LedstripAnimationBlinkBothAction : public virtual ActionInterface public: void triggered() override { blinkAnimation = LEDSTRIP_ANIMATION_BLINKBOTH; } }; + +class LedstripAnimationBetterRainbowAction : public virtual ActionInterface +{ +public: + void triggered() override { blinkAnimation = LEDSTRIP_ANIMATION_BETTERRAINBOW; } +}; + +class LedstripAnimationSyncToSpeedAction : public virtual ActionInterface +{ +public: + void triggered() override { blinkAnimation = LEDSTRIP_ANIMATION_SPEEDSYNCANIMATION; } +}; } diff --git a/main/displays/menus/ledstripselectanimationmenu.h b/main/displays/menus/ledstripselectanimationmenu.h index 1548ed0..b7f4a52 100644 --- a/main/displays/menus/ledstripselectanimationmenu.h +++ b/main/displays/menus/ledstripselectanimationmenu.h @@ -27,11 +27,13 @@ namespace { public: LedstripSelectAnimationMenu() { - constructMenuItem, LedstripAnimationDefaultRainbowAction>>(); - constructMenuItem, LedstripAnimationBlinkLeftAction>>(); - constructMenuItem, LedstripAnimationBlinkRightAction>>(); - constructMenuItem, LedstripAnimationBlinkBothAction>>(); - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); + constructMenuItem, LedstripAnimationDefaultRainbowAction>>(); + constructMenuItem, LedstripAnimationBlinkLeftAction>>(); + constructMenuItem, LedstripAnimationBlinkRightAction>>(); + constructMenuItem, LedstripAnimationBlinkBothAction>>(); + constructMenuItem, LedstripAnimationBetterRainbowAction>>(); + constructMenuItem, LedstripAnimationSyncToSpeedAction>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); } }; } // Namespace diff --git a/main/ledstrip.h b/main/ledstrip.h index 662724e..1d93e0f 100644 --- a/main/ledstrip.h +++ b/main/ledstrip.h @@ -1,5 +1,4 @@ #pragma once - #ifdef FEATURE_LEDSTRIP // 3rdparty lib includes #include @@ -17,6 +16,9 @@ uint8_t gHue = 0; int16_t blinkAnimation = LEDSTRIP_ANIMATION_DEFAULT; void showDefaultLedstrip(); +void showAnimation(); +void showBetterRainbow(); +void showSpeedSyncAnimation(); void initLedStrip() { @@ -38,18 +40,17 @@ void updateLedStrip() auto color = CRGB{255, 255, 0}; const auto center = (std::begin(leds) + (leds.size() / 2) + settings.ledstrip.centerOffset); - #ifdef LEDSTRIP_WRONG_DIRECTION - if(blinkAnimation == LEDSTRIP_ANIMATION_BLINKLEFT){ - blinkAnimation = LEDSTRIP_ANIMATION_BLINKRIGHT; - } else if(blinkAnimation == LEDSTRIP_ANIMATION_BLINKRIGHT){ - blinkAnimation = LEDSTRIP_ANIMATION_BLINKLEFT; - } - #endif - +#ifndef LEDSTRIP_WRONG_DIRECTION + if (blinkAnimation != LEDSTRIP_ANIMATION_BLINKRIGHT) + std::fill(center - settings.ledstrip.bigOffset, center - settings.ledstrip.smallOffset, color); + if (blinkAnimation != LEDSTRIP_ANIMATION_BLINKLEFT) + std::fill(center + settings.ledstrip.smallOffset, center + settings.ledstrip.bigOffset, color); +#else if (blinkAnimation != LEDSTRIP_ANIMATION_BLINKLEFT) std::fill(center - settings.ledstrip.bigOffset, center - settings.ledstrip.smallOffset, color); if (blinkAnimation != LEDSTRIP_ANIMATION_BLINKRIGHT) std::fill(center + settings.ledstrip.smallOffset, center + settings.ledstrip.bigOffset, color); +#endif } } else @@ -77,12 +78,12 @@ void updateLedStrip() } else { - showDefaultLedstrip(); + showAnimation(); } } else { - showDefaultLedstrip(); + showAnimation(); } } @@ -90,6 +91,31 @@ void updateLedStrip() FastLED.show(); } +void showAnimation() { + if (blinkAnimation == LEDSTRIP_ANIMATION_DEFAULT) showDefaultLedstrip(); + else if (blinkAnimation == LEDSTRIP_ANIMATION_BETTERRAINBOW) showBetterRainbow(); + else if (blinkAnimation == LEDSTRIP_ANIMATION_SPEEDSYNCANIMATION) showSpeedSyncAnimation(); + else showDefaultLedstrip(); +} + +void showBetterRainbow() { + if (settings.ledstrip.enableLedAnimation) + { + //fill_rainbow(); // Will implement later + } + else + std::fill(std::begin(leds), std::end(leds), CRGB{0, 0, 0}); +} + +void showSpeedSyncAnimation() { + if (settings.ledstrip.enableLedAnimation) + { + // Code that shows static animation relative to the ground + } + else + std::fill(std::begin(leds), std::end(leds), CRGB{0, 0, 0}); +} + void showDefaultLedstrip() { if (settings.ledstrip.enableLedAnimation) diff --git a/main/ledstripdefines.h b/main/ledstripdefines.h index 36e368d..c4efa87 100644 --- a/main/ledstripdefines.h +++ b/main/ledstripdefines.h @@ -6,3 +6,5 @@ #define LEDSTRIP_ANIMATION_BLINKLEFT 1 #define LEDSTRIP_ANIMATION_BLINKRIGHT 2 #define LEDSTRIP_ANIMATION_BLINKBOTH 3 +#define LEDSTRIP_ANIMATION_BETTERRAINBOW 4 +#define LEDSTRIP_ANIMATION_SPEEDSYNCANIMATION 5 diff --git a/main/texts.h b/main/texts.h index 155b7db..45ca6fd 100644 --- a/main/texts.h +++ b/main/texts.h @@ -256,6 +256,8 @@ constexpr char TEXT_ANIMATION_DEFAULTRAINBOW[] = "Default Rainbow"; constexpr char TEXT_ANIMATION_BLINKLEFT[] = "Blink Left"; constexpr char TEXT_ANIMATION_BLINKRIGHT[] = "Blink Right"; constexpr char TEXT_ANIMATION_BLINKBOTH[] = "Blink Both"; +constexpr char TEXT_ANIMATION_BETTERRAINBOW[] = "Better Rainbow"; +constexpr char TEXT_ANIMATION_SPEEDSYNCANIMATION[] = "Speed Sync"; //LockscreenSettingsMenu constexpr char TEXT_LOCKSCREENSETTINGS[] = "Lockscreen Settings";