separate led blink and animation type

This commit is contained in:
Peter Poetzi
2021-09-30 21:03:06 +02:00
parent 8aacd3d4f8
commit 21ba6b4d97
9 changed files with 114 additions and 68 deletions

View File

@ -12,36 +12,18 @@ namespace {
class LedstripAnimationDefaultRainbowAction : public virtual ActionInterface class LedstripAnimationDefaultRainbowAction : public virtual ActionInterface
{ {
public: public:
void triggered() override { blinkAnimation = LEDSTRIP_ANIMATION_DEFAULTRAINBOW; } void triggered() override { animation_type = LEDSTRIP_ANIMATION_TYPE_DEFAULTRAINBOW; }
};
class LedstripAnimationBlinkLeftAction : public virtual ActionInterface
{
public:
void triggered() override { blinkAnimation = LEDSTRIP_ANIMATION_BLINKLEFT; }
};
class LedstripAnimationBlinkRightAction : public virtual ActionInterface
{
public:
void triggered() override { blinkAnimation = LEDSTRIP_ANIMATION_BLINKRIGHT; }
};
class LedstripAnimationBlinkBothAction : public virtual ActionInterface
{
public:
void triggered() override { blinkAnimation = LEDSTRIP_ANIMATION_BLINKBOTH; }
}; };
class LedstripAnimationBetterRainbowAction : public virtual ActionInterface class LedstripAnimationBetterRainbowAction : public virtual ActionInterface
{ {
public: public:
void triggered() override { blinkAnimation = LEDSTRIP_ANIMATION_BETTERRAINBOW; } void triggered() override { animation_type = LEDSTRIP_ANIMATION_TYPE_BETTERRAINBOW; }
}; };
class LedstripAnimationSyncToSpeedAction : public virtual ActionInterface class LedstripAnimationSyncToSpeedAction : public virtual ActionInterface
{ {
public: public:
void triggered() override { blinkAnimation = LEDSTRIP_ANIMATION_SPEEDSYNCANIMATION; } void triggered() override { animation_type = LEDSTRIP_ANIMATION_TYPE_SPEEDSYNCANIMATION; }
}; };
} }

View File

@ -0,0 +1,35 @@
#pragma once
#include "actioninterface.h"
#include "utils.h"
#include "globals.h"
#include "ledstrip.h"
#include "ledstripdefines.h"
using namespace espgui;
namespace {
class LedstripAnimationBlinkNoneAction : public virtual ActionInterface
{
public:
void triggered() override { blinkAnimation = LEDSTRIP_OVERWRITE_NONE; }
};
class LedstripAnimationBlinkLeftAction : public virtual ActionInterface
{
public:
void triggered() override { blinkAnimation = LEDSTRIP_OVERWRITE_BLINKLEFT; }
};
class LedstripAnimationBlinkRightAction : public virtual ActionInterface
{
public:
void triggered() override { blinkAnimation = LEDSTRIP_OVERWRITE_BLINKRIGHT; }
};
class LedstripAnimationBlinkBothAction : public virtual ActionInterface
{
public:
void triggered() override { blinkAnimation = LEDSTRIP_OVERWRITE_BLINKBOTH; }
};
}

View File

@ -143,14 +143,14 @@ public:
if(!pressed)return; if(!pressed)return;
#ifdef FEATURE_LEDSTRIP #ifdef FEATURE_LEDSTRIP
if(blinkAnimation == LEDSTRIP_ANIMATION_DEFAULTRAINBOW){ //transition from off to left if(blinkAnimation == LEDSTRIP_OVERWRITE_NONE){ //transition from off to left
blinkAnimation = LEDSTRIP_ANIMATION_BLINKLEFT; blinkAnimation = LEDSTRIP_OVERWRITE_BLINKLEFT;
} }
else if(blinkAnimation == LEDSTRIP_ANIMATION_BLINKRIGHT){ // transition to warning else if(blinkAnimation == LEDSTRIP_OVERWRITE_BLINKRIGHT){ // transition to warning
blinkAnimation = LEDSTRIP_ANIMATION_BLINKBOTH; blinkAnimation = LEDSTRIP_OVERWRITE_BLINKBOTH;
} }
else{ // transition to off else{ // transition to off
blinkAnimation = 0; blinkAnimation = LEDSTRIP_OVERWRITE_NONE;
} }
#endif #endif
} }
@ -158,14 +158,14 @@ public:
static void blinkRightButton(bool pressed){ static void blinkRightButton(bool pressed){
if(!pressed)return; if(!pressed)return;
#ifdef FEATURE_LEDSTRIP #ifdef FEATURE_LEDSTRIP
if(blinkAnimation == LEDSTRIP_ANIMATION_DEFAULTRAINBOW){ //transition from off to right if(blinkAnimation == LEDSTRIP_OVERWRITE_NONE){ //transition from off to right
blinkAnimation = LEDSTRIP_ANIMATION_BLINKRIGHT; blinkAnimation = LEDSTRIP_OVERWRITE_BLINKRIGHT;
} }
else if(blinkAnimation == LEDSTRIP_ANIMATION_BLINKLEFT){ // transition to warning else if(blinkAnimation == LEDSTRIP_OVERWRITE_BLINKLEFT){ // transition to warning
blinkAnimation = LEDSTRIP_ANIMATION_BLINKBOTH; blinkAnimation = LEDSTRIP_OVERWRITE_BLINKBOTH;
} }
else{ // transition to off else{ // transition to off
blinkAnimation = 0; blinkAnimation = LEDSTRIP_OVERWRITE_NONE;
} }
#endif #endif
} }

View File

@ -6,6 +6,7 @@
#include "actions/toggleboolaction.h" #include "actions/toggleboolaction.h"
#include "actions/switchscreenaction.h" #include "actions/switchscreenaction.h"
#include "ledstripselectanimationmenu.h" #include "ledstripselectanimationmenu.h"
#include "ledstripselectblinkmenu.h"
#include "texts.h" #include "texts.h"
#include "icons/back.h" #include "icons/back.h"
#include "checkboxicon.h" #include "checkboxicon.h"
@ -28,16 +29,6 @@ namespace {
class LedstripMenu; class LedstripMenu;
class LedstripSelectAnimationMenu; class LedstripSelectAnimationMenu;
struct BlinkAnimationAccessor : public RefAccessor<int16_t> { int16_t &getRef() const override { return blinkAnimation; } };
using BlinkAnimationChangeScreen = makeComponent<
ChangeValueDisplay<int16_t>,
StaticText<TEXT_BLINKANIMATION>,
BlinkAnimationAccessor,
BackActionInterface<SwitchScreenAction<LedstripMenu>>,
SwitchScreenAction<LedstripMenu>
>;
using LedsCountChangeScreen = makeComponent< using LedsCountChangeScreen = makeComponent<
ChangeValueDisplay<int16_t>, ChangeValueDisplay<int16_t>,
StaticText<TEXT_LEDSCOUNT>, StaticText<TEXT_LEDSCOUNT>,
@ -86,10 +77,10 @@ class LedstripMenu :
public: public:
LedstripMenu() LedstripMenu()
{ {
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_LEDANIMATION>, ToggleBoolAction, CheckboxIcon, EnableLedAnimationAccessor>>(); constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_LEDANIMATION>, ToggleBoolAction, CheckboxIcon, EnableLedAnimationAccessor>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BRAKELIGHTS>, ToggleBoolAction, CheckboxIcon, EnableBrakeLightsAccessor>>(); constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BRAKELIGHTS>, ToggleBoolAction, CheckboxIcon, EnableBrakeLightsAccessor>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_SELECTANIMATION>, SwitchScreenAction<LedstripSelectAnimationMenu>>>(); constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_SELECTANIMATION>, SwitchScreenAction<LedstripSelectAnimationMenu>>>();
// constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_BLINKANIMATION, BlinkAnimationAccessor>, SwitchScreenAction<BlinkAnimationChangeScreen>>>(); constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BLINKANIMATION>, SwitchScreenAction<LedstripSelectBlinkMenu>>>();
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_LEDSCOUNT, LedsCountAccessor>, SwitchScreenAction<LedsCountChangeScreen>>>(); constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_LEDSCOUNT, LedsCountAccessor>, SwitchScreenAction<LedsCountChangeScreen>>>();
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_CENTEROFFSET, CenterOffsetAccessor>, SwitchScreenAction<CenterOffsetChangeScreen>>>(); constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_CENTEROFFSET, CenterOffsetAccessor>, SwitchScreenAction<CenterOffsetChangeScreen>>>();
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_SMALLOFFSET, SmallOffsetAccessor>, SwitchScreenAction<SmallOffsetChangeScreen>>>(); constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_SMALLOFFSET, SmallOffsetAccessor>, SwitchScreenAction<SmallOffsetChangeScreen>>>();

View File

@ -28,9 +28,6 @@ namespace {
LedstripSelectAnimationMenu() LedstripSelectAnimationMenu()
{ {
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_DEFAULTRAINBOW>, LedstripAnimationDefaultRainbowAction>>(); 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_BETTERRAINBOW>, LedstripAnimationBetterRainbowAction>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_SPEEDSYNCANIMATION>, LedstripAnimationSyncToSpeedAction>>(); 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

@ -0,0 +1,37 @@
#pragma once
// Local includes
#include "menudisplay.h"
#include "utils.h"
#include "menuitem.h"
#include "ledstrip.h"
#include "ledstripselectanimationmenu.h"
#include "icons/back.h"
#include "texts.h"
#include "actions/dummyaction.h"
#include "actions/ledstripblinkactions.h"
#include "actions/switchscreenaction.h"
using namespace espgui;
namespace {
class LedstripMenu;
}
namespace {
class LedstripSelectBlinkMenu :
public MenuDisplay,
public StaticText<TEXT_BLINKANIMATION>,
public BackActionInterface<SwitchScreenAction<LedstripMenu>>
{
public:
LedstripSelectBlinkMenu()
{
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_BLINKNONE>, LedstripAnimationBlinkNoneAction>>();
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>>>();
}
};
} // Namespace

View File

@ -13,7 +13,8 @@ namespace {
std::vector<CRGB> leds; std::vector<CRGB> leds;
uint8_t gHue = 0; uint8_t gHue = 0;
int16_t blinkAnimation = LEDSTRIP_ANIMATION_DEFAULT; int16_t blinkAnimation = LEDSTRIP_OVERWRITE_NONE;
int16_t animation_type = LEDSTRIP_ANIMATION_TYPE_DEFAULTRAINBOW;
void showDefaultLedstrip(); void showDefaultLedstrip();
void showAnimation(); void showAnimation();
@ -31,7 +32,7 @@ void updateLedStrip()
{ {
EVERY_N_MILLISECONDS( 20 ) { gHue++; } EVERY_N_MILLISECONDS( 20 ) { gHue++; }
if (cpputils::is_in(blinkAnimation, LEDSTRIP_ANIMATION_BLINKLEFT, LEDSTRIP_ANIMATION_BLINKRIGHT, LEDSTRIP_ANIMATION_BLINKBOTH)) if (cpputils::is_in(blinkAnimation, LEDSTRIP_OVERWRITE_BLINKLEFT, LEDSTRIP_OVERWRITE_BLINKRIGHT, LEDSTRIP_OVERWRITE_BLINKBOTH))
{ {
std::fill(std::begin(leds), std::end(leds), CRGB{0, 0, 0}); std::fill(std::begin(leds), std::end(leds), CRGB{0, 0, 0});
@ -40,15 +41,15 @@ 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);
#ifndef LEDSTRIP_WRONG_DIRECTION #ifdef LEDSTRIP_WRONG_DIRECTION
if (blinkAnimation != LEDSTRIP_ANIMATION_BLINKRIGHT) if (blinkAnimation != LEDSTRIP_OVERWRITE_BLINKRIGHT)
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_BLINKLEFT) if (blinkAnimation != LEDSTRIP_OVERWRITE_BLINKLEFT)
std::fill(center + settings.ledstrip.smallOffset, center + settings.ledstrip.bigOffset, color); std::fill(center + settings.ledstrip.smallOffset, center + settings.ledstrip.bigOffset, color);
#else #else
if (blinkAnimation != LEDSTRIP_ANIMATION_BLINKLEFT) if (blinkAnimation != LEDSTRIP_OVERWRITE_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_OVERWRITE_BLINKRIGHT)
std::fill(center + settings.ledstrip.smallOffset, center + settings.ledstrip.bigOffset, color); std::fill(center + settings.ledstrip.smallOffset, center + settings.ledstrip.bigOffset, color);
#endif #endif
} }
@ -92,9 +93,9 @@ void updateLedStrip()
} }
void showAnimation() { void showAnimation() {
if (blinkAnimation == LEDSTRIP_ANIMATION_DEFAULTRAINBOW) showDefaultLedstrip(); if (animation_type == LEDSTRIP_ANIMATION_TYPE_DEFAULTRAINBOW) showDefaultLedstrip();
else if (blinkAnimation == LEDSTRIP_ANIMATION_BETTERRAINBOW) showBetterRainbow(); else if (animation_type == LEDSTRIP_ANIMATION_TYPE_BETTERRAINBOW) showBetterRainbow();
else if (blinkAnimation == LEDSTRIP_ANIMATION_SPEEDSYNCANIMATION) showSpeedSyncAnimation(); else if (animation_type == LEDSTRIP_ANIMATION_TYPE_SPEEDSYNCANIMATION) showSpeedSyncAnimation();
else showDefaultLedstrip(); else showDefaultLedstrip();
} }

View File

@ -3,13 +3,12 @@
* This file contains a few defines, so you don't have to remember which ledstrip animation is which number * This file contains a few defines, so you don't have to remember which ledstrip animation is which number
*/ */
#define LEDSTRIP_ANIMATION_DEFAULTRAINBOW 0 #define LEDSTRIP_OVERWRITE_NONE 0
#define LEDSTRIP_ANIMATION_BLINKLEFT 1 #define LEDSTRIP_OVERWRITE_BLINKLEFT 1
#define LEDSTRIP_ANIMATION_BLINKRIGHT 2 #define LEDSTRIP_OVERWRITE_BLINKRIGHT 2
#define LEDSTRIP_ANIMATION_BLINKBOTH 3 #define LEDSTRIP_OVERWRITE_BLINKBOTH 3
#define LEDSTRIP_ANIMATION_BETTERRAINBOW 4
#define LEDSTRIP_ANIMATION_SPEEDSYNCANIMATION 5
#ifndef LEDSTRIP_ANIMATION_DEFAULT
#define LEDSTRIP_ANIMATION_DEFAULT LEDSTRIP_ANIMATION_DEFAULTRAINBOW #define LEDSTRIP_ANIMATION_TYPE_DEFAULTRAINBOW 0
#endif #define LEDSTRIP_ANIMATION_TYPE_BETTERRAINBOW 1
#define LEDSTRIP_ANIMATION_TYPE_SPEEDSYNCANIMATION 2

View File

@ -243,6 +243,7 @@ constexpr char TEXT_LEDSTRIP[] = "Ledstrip";
constexpr char TEXT_LEDANIMATION[] = "LED Animation"; constexpr char TEXT_LEDANIMATION[] = "LED Animation";
constexpr char TEXT_BRAKELIGHTS[] = "Brake Lights"; constexpr char TEXT_BRAKELIGHTS[] = "Brake Lights";
constexpr char TEXT_BLINKANIMATION[] = "Blink animation"; constexpr char TEXT_BLINKANIMATION[] = "Blink animation";
constexpr char TEXT_ANIMATION_TYPE[] = "Blink animation";
constexpr char TEXT_LEDSCOUNT[] = "LEDs Count"; constexpr char TEXT_LEDSCOUNT[] = "LEDs Count";
constexpr char TEXT_CENTEROFFSET[] = "Center Offset"; constexpr char TEXT_CENTEROFFSET[] = "Center Offset";
constexpr char TEXT_SMALLOFFSET[] = "Small Offset"; constexpr char TEXT_SMALLOFFSET[] = "Small Offset";
@ -253,11 +254,14 @@ constexpr char TEXT_LEDSTRIP_MILLIAMP[] = "Ledstrip 0.1A";
//LedstripSelectAnimationMenu //LedstripSelectAnimationMenu
constexpr char TEXT_SELECTANIMATION[] = "Select Animation"; constexpr char TEXT_SELECTANIMATION[] = "Select Animation";
constexpr char TEXT_ANIMATION_DEFAULTRAINBOW[] = "Default Rainbow"; constexpr char TEXT_ANIMATION_DEFAULTRAINBOW[] = "Default Rainbow";
constexpr char TEXT_ANIMATION_BETTERRAINBOW[] = "Better Rainbow";
constexpr char TEXT_ANIMATION_SPEEDSYNCANIMATION[] = "Speed Sync";
//LedstripSelectBlinkMenu
constexpr char TEXT_ANIMATION_BLINKNONE[] = "Blink Off";
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";