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:
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

@ -27,11 +27,13 @@ namespace {
public:
LedstripSelectAnimationMenu()
{
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_DEFAULTRAINBOW>, LedstripAnimationDefaultRainbowAction>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_BLINKLEFT>, LedstripAnimationBlinkLeftAction>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_BLINKRIGHT>, LedstripAnimationBlinkRightAction>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_BLINKBOTH>, LedstripAnimationBlinkBothAction>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<LedstripMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_DEFAULTRAINBOW>, LedstripAnimationDefaultRainbowAction>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_BLINKLEFT>, LedstripAnimationBlinkLeftAction>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_BLINKRIGHT>, LedstripAnimationBlinkRightAction>>();
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>>>();
}
};
} // Namespace

View File

@ -1,5 +1,4 @@
#pragma once
#ifdef FEATURE_LEDSTRIP
// 3rdparty lib includes
#include <FastLED.h>
@ -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)

View File

@ -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

View File

@ -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";