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
{
public:
void triggered() override { blinkAnimation = LEDSTRIP_ANIMATION_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; }
void triggered() override { animation_type = LEDSTRIP_ANIMATION_TYPE_DEFAULTRAINBOW; }
};
class LedstripAnimationBetterRainbowAction : public virtual ActionInterface
{
public:
void triggered() override { blinkAnimation = LEDSTRIP_ANIMATION_BETTERRAINBOW; }
void triggered() override { animation_type = LEDSTRIP_ANIMATION_TYPE_BETTERRAINBOW; }
};
class LedstripAnimationSyncToSpeedAction : public virtual ActionInterface
{
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;
#ifdef FEATURE_LEDSTRIP
if(blinkAnimation == LEDSTRIP_ANIMATION_DEFAULTRAINBOW){ //transition from off to left
blinkAnimation = LEDSTRIP_ANIMATION_BLINKLEFT;
if(blinkAnimation == LEDSTRIP_OVERWRITE_NONE){ //transition from off to left
blinkAnimation = LEDSTRIP_OVERWRITE_BLINKLEFT;
}
else if(blinkAnimation == LEDSTRIP_ANIMATION_BLINKRIGHT){ // transition to warning
blinkAnimation = LEDSTRIP_ANIMATION_BLINKBOTH;
else if(blinkAnimation == LEDSTRIP_OVERWRITE_BLINKRIGHT){ // transition to warning
blinkAnimation = LEDSTRIP_OVERWRITE_BLINKBOTH;
}
else{ // transition to off
blinkAnimation = 0;
blinkAnimation = LEDSTRIP_OVERWRITE_NONE;
}
#endif
}
@ -158,14 +158,14 @@ public:
static void blinkRightButton(bool pressed){
if(!pressed)return;
#ifdef FEATURE_LEDSTRIP
if(blinkAnimation == LEDSTRIP_ANIMATION_DEFAULTRAINBOW){ //transition from off to right
blinkAnimation = LEDSTRIP_ANIMATION_BLINKRIGHT;
if(blinkAnimation == LEDSTRIP_OVERWRITE_NONE){ //transition from off to right
blinkAnimation = LEDSTRIP_OVERWRITE_BLINKRIGHT;
}
else if(blinkAnimation == LEDSTRIP_ANIMATION_BLINKLEFT){ // transition to warning
blinkAnimation = LEDSTRIP_ANIMATION_BLINKBOTH;
else if(blinkAnimation == LEDSTRIP_OVERWRITE_BLINKLEFT){ // transition to warning
blinkAnimation = LEDSTRIP_OVERWRITE_BLINKBOTH;
}
else{ // transition to off
blinkAnimation = 0;
blinkAnimation = LEDSTRIP_OVERWRITE_NONE;
}
#endif
}

View File

@ -6,6 +6,7 @@
#include "actions/toggleboolaction.h"
#include "actions/switchscreenaction.h"
#include "ledstripselectanimationmenu.h"
#include "ledstripselectblinkmenu.h"
#include "texts.h"
#include "icons/back.h"
#include "checkboxicon.h"
@ -28,16 +29,6 @@ namespace {
class LedstripMenu;
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<
ChangeValueDisplay<int16_t>,
StaticText<TEXT_LEDSCOUNT>,
@ -86,10 +77,10 @@ class LedstripMenu :
public:
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_SELECTANIMATION>, SwitchScreenAction<LedstripSelectAnimationMenu>>>();
// constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_BLINKANIMATION, BlinkAnimationAccessor>, SwitchScreenAction<BlinkAnimationChangeScreen>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_SELECTANIMATION>, SwitchScreenAction<LedstripSelectAnimationMenu>>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BLINKANIMATION>, SwitchScreenAction<LedstripSelectBlinkMenu>>>();
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_LEDSCOUNT, LedsCountAccessor>, SwitchScreenAction<LedsCountChangeScreen>>>();
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_CENTEROFFSET, CenterOffsetAccessor>, SwitchScreenAction<CenterOffsetChangeScreen>>>();
constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_SMALLOFFSET, SmallOffsetAccessor>, SwitchScreenAction<SmallOffsetChangeScreen>>>();

View File

@ -28,9 +28,6 @@ namespace {
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_ANIMATION_BETTERRAINBOW>, LedstripAnimationBetterRainbowAction>>();
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_SPEEDSYNCANIMATION>, LedstripAnimationSyncToSpeedAction>>();
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;
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 showAnimation();
@ -31,7 +32,7 @@ void updateLedStrip()
{
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});
@ -40,15 +41,15 @@ void updateLedStrip()
auto color = CRGB{255, 255, 0};
const auto center = (std::begin(leds) + (leds.size() / 2) + settings.ledstrip.centerOffset);
#ifndef LEDSTRIP_WRONG_DIRECTION
if (blinkAnimation != LEDSTRIP_ANIMATION_BLINKRIGHT)
#ifdef LEDSTRIP_WRONG_DIRECTION
if (blinkAnimation != LEDSTRIP_OVERWRITE_BLINKRIGHT)
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);
#else
if (blinkAnimation != LEDSTRIP_ANIMATION_BLINKLEFT)
if (blinkAnimation != LEDSTRIP_OVERWRITE_BLINKLEFT)
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);
#endif
}
@ -92,9 +93,9 @@ void updateLedStrip()
}
void showAnimation() {
if (blinkAnimation == LEDSTRIP_ANIMATION_DEFAULTRAINBOW) showDefaultLedstrip();
else if (blinkAnimation == LEDSTRIP_ANIMATION_BETTERRAINBOW) showBetterRainbow();
else if (blinkAnimation == LEDSTRIP_ANIMATION_SPEEDSYNCANIMATION) showSpeedSyncAnimation();
if (animation_type == LEDSTRIP_ANIMATION_TYPE_DEFAULTRAINBOW) showDefaultLedstrip();
else if (animation_type == LEDSTRIP_ANIMATION_TYPE_BETTERRAINBOW) showBetterRainbow();
else if (animation_type == LEDSTRIP_ANIMATION_TYPE_SPEEDSYNCANIMATION) showSpeedSyncAnimation();
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
*/
#define LEDSTRIP_ANIMATION_DEFAULTRAINBOW 0
#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
#define LEDSTRIP_OVERWRITE_NONE 0
#define LEDSTRIP_OVERWRITE_BLINKLEFT 1
#define LEDSTRIP_OVERWRITE_BLINKRIGHT 2
#define LEDSTRIP_OVERWRITE_BLINKBOTH 3
#ifndef LEDSTRIP_ANIMATION_DEFAULT
#define LEDSTRIP_ANIMATION_DEFAULT LEDSTRIP_ANIMATION_DEFAULTRAINBOW
#endif
#define LEDSTRIP_ANIMATION_TYPE_DEFAULTRAINBOW 0
#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_BRAKELIGHTS[] = "Brake Lights";
constexpr char TEXT_BLINKANIMATION[] = "Blink animation";
constexpr char TEXT_ANIMATION_TYPE[] = "Blink animation";
constexpr char TEXT_LEDSCOUNT[] = "LEDs Count";
constexpr char TEXT_CENTEROFFSET[] = "Center Offset";
constexpr char TEXT_SMALLOFFSET[] = "Small Offset";
@ -253,11 +254,14 @@ constexpr char TEXT_LEDSTRIP_MILLIAMP[] = "Ledstrip 0.1A";
//LedstripSelectAnimationMenu
constexpr char TEXT_SELECTANIMATION[] = "Select Animation";
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_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";