Preparations for new ledstrip animations

This commit is contained in:
CommanderRedYT
2021-09-30 16:20:09 +02:00
parent a03f0ffdb9
commit 65a64e4e2a
5 changed files with 60 additions and 16 deletions

View File

@@ -32,4 +32,16 @@ class LedstripAnimationBlinkBothAction : public virtual ActionInterface
public: public:
void triggered() override { blinkAnimation = LEDSTRIP_ANIMATION_BLINKBOTH; } 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; }
};
} }

View File

@@ -31,6 +31,8 @@ namespace {
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_BLINKLEFT>, LedstripAnimationBlinkLeftAction>>(); constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_BLINKLEFT>, LedstripAnimationBlinkLeftAction>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_BLINKRIGHT>, LedstripAnimationBlinkRightAction>>(); constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_BLINKRIGHT>, LedstripAnimationBlinkRightAction>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_BLINKBOTH>, LedstripAnimationBlinkBothAction>>(); constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_BLINKBOTH>, LedstripAnimationBlinkBothAction>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_BETTERRAINBOW>, LedstripAnimationBetterRainbowAction>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_SPEEDSYNCANIMATION>, LedstripAnimationSyncToSpeedAction>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<LedstripMenu>, StaticMenuItemIcon<&espgui::icons::back>>>(); constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<LedstripMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
} }
}; };

View File

@@ -1,5 +1,4 @@
#pragma once #pragma once
#ifdef FEATURE_LEDSTRIP #ifdef FEATURE_LEDSTRIP
// 3rdparty lib includes // 3rdparty lib includes
#include <FastLED.h> #include <FastLED.h>
@@ -17,6 +16,9 @@ uint8_t gHue = 0;
int16_t blinkAnimation = LEDSTRIP_ANIMATION_DEFAULT; int16_t blinkAnimation = LEDSTRIP_ANIMATION_DEFAULT;
void showDefaultLedstrip(); void showDefaultLedstrip();
void showAnimation();
void showBetterRainbow();
void showSpeedSyncAnimation();
void initLedStrip() void initLedStrip()
{ {
@@ -38,18 +40,17 @@ void updateLedStrip()
auto color = CRGB{255, 255, 0}; auto color = CRGB{255, 255, 0};
const auto center = (std::begin(leds) + (leds.size() / 2) + settings.ledstrip.centerOffset); const auto center = (std::begin(leds) + (leds.size() / 2) + settings.ledstrip.centerOffset);
#ifdef LEDSTRIP_WRONG_DIRECTION #ifndef LEDSTRIP_WRONG_DIRECTION
if(blinkAnimation == LEDSTRIP_ANIMATION_BLINKLEFT){ if (blinkAnimation != LEDSTRIP_ANIMATION_BLINKRIGHT)
blinkAnimation = LEDSTRIP_ANIMATION_BLINKRIGHT; std::fill(center - settings.ledstrip.bigOffset, center - settings.ledstrip.smallOffset, color);
} else if(blinkAnimation == LEDSTRIP_ANIMATION_BLINKRIGHT){ if (blinkAnimation != LEDSTRIP_ANIMATION_BLINKLEFT)
blinkAnimation = LEDSTRIP_ANIMATION_BLINKLEFT; std::fill(center + settings.ledstrip.smallOffset, center + settings.ledstrip.bigOffset, color);
} #else
#endif
if (blinkAnimation != LEDSTRIP_ANIMATION_BLINKLEFT) if (blinkAnimation != LEDSTRIP_ANIMATION_BLINKLEFT)
std::fill(center - settings.ledstrip.bigOffset, center - settings.ledstrip.smallOffset, color); std::fill(center - settings.ledstrip.bigOffset, center - settings.ledstrip.smallOffset, color);
if (blinkAnimation != LEDSTRIP_ANIMATION_BLINKRIGHT) if (blinkAnimation != LEDSTRIP_ANIMATION_BLINKRIGHT)
std::fill(center + settings.ledstrip.smallOffset, center + settings.ledstrip.bigOffset, color); std::fill(center + settings.ledstrip.smallOffset, center + settings.ledstrip.bigOffset, color);
#endif
} }
} }
else else
@@ -77,12 +78,12 @@ void updateLedStrip()
} }
else else
{ {
showDefaultLedstrip(); showAnimation();
} }
} }
else else
{ {
showDefaultLedstrip(); showAnimation();
} }
} }
@@ -90,6 +91,31 @@ void updateLedStrip()
FastLED.show(); 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() void showDefaultLedstrip()
{ {
if (settings.ledstrip.enableLedAnimation) if (settings.ledstrip.enableLedAnimation)

View File

@@ -6,3 +6,5 @@
#define LEDSTRIP_ANIMATION_BLINKLEFT 1 #define LEDSTRIP_ANIMATION_BLINKLEFT 1
#define LEDSTRIP_ANIMATION_BLINKRIGHT 2 #define LEDSTRIP_ANIMATION_BLINKRIGHT 2
#define LEDSTRIP_ANIMATION_BLINKBOTH 3 #define LEDSTRIP_ANIMATION_BLINKBOTH 3
#define LEDSTRIP_ANIMATION_BETTERRAINBOW 4
#define LEDSTRIP_ANIMATION_SPEEDSYNCANIMATION 5

View File

@@ -256,6 +256,8 @@ constexpr char TEXT_ANIMATION_DEFAULTRAINBOW[] = "Default Rainbow";
constexpr char TEXT_ANIMATION_BLINKLEFT[] = "Blink Left"; constexpr char TEXT_ANIMATION_BLINKLEFT[] = "Blink Left";
constexpr char TEXT_ANIMATION_BLINKRIGHT[] = "Blink Right"; constexpr char TEXT_ANIMATION_BLINKRIGHT[] = "Blink Right";
constexpr char TEXT_ANIMATION_BLINKBOTH[] = "Blink Both"; constexpr char TEXT_ANIMATION_BLINKBOTH[] = "Blink Both";
constexpr char TEXT_ANIMATION_BETTERRAINBOW[] = "Better Rainbow";
constexpr char TEXT_ANIMATION_SPEEDSYNCANIMATION[] = "Speed Sync";
//LockscreenSettingsMenu //LockscreenSettingsMenu
constexpr char TEXT_LOCKSCREENSETTINGS[] = "Lockscreen Settings"; constexpr char TEXT_LOCKSCREENSETTINGS[] = "Lockscreen Settings";