Fixed ledstrip animationType

This commit is contained in:
2022-01-03 21:00:16 +01:00
parent 64a6c14d82
commit a3e719bd81
8 changed files with 31 additions and 19 deletions

View File

@ -6,12 +6,21 @@
// local includes
#include "ledstrip.h"
#include "ledstripdefines.h"
#include "newsettings.h"
#include "bobbyerrorhandler.h"
#ifdef FEATURE_LEDSTRIP
template<LedstripAnimation type>
class LedStripSetAnimationAction : public virtual espgui::ActionInterface
{
public:
void triggered() override { animation_type = type; }
void triggered() override;
};
template<LedstripAnimation type>
void LedStripSetAnimationAction<type>::triggered()
{
if (auto result = configs.write_config(configs.ledstrip.animationType, type); !result)
BobbyErrorHandler{}.errorOccured(std::move(result).error());
}
#endif

View File

@ -10,3 +10,4 @@
IMPLEMENT_NVS_GET_SET_ENUM(OtaAnimationModes)
IMPLEMENT_NVS_GET_SET_ENUM(HandbremseMode)
IMPLEMENT_NVS_GET_SET_ENUM(LedstripAnimation)

View File

@ -6,3 +6,4 @@
INSTANTIATE_CONFIGWRAPPER_TEMPLATES(OtaAnimationModes)
INSTANTIATE_CONFIGWRAPPER_TEMPLATES(HandbremseMode)
INSTANTIATE_CONFIGWRAPPER_TEMPLATES(LedstripAnimation)

View File

@ -7,6 +7,7 @@
#include "icons/back.h"
#include "ledstripdefines.h"
#include "ledstripmenu.h"
#include "newsettings.h"
#ifdef FEATURE_LEDSTRIP
namespace {
@ -52,7 +53,8 @@ namespace {
std::string CurrentSelectedAnimationText::text() const
{
switch (animation_type) {
switch (configs.ledstrip.animationType.value)
{
case LedstripAnimation::DefaultRainbow:
return TEXT_ANIMATION_DEFAULTRAINBOW;
case LedstripAnimation::BetterRainbow:

View File

@ -18,12 +18,10 @@ std::vector<CRGB> leds;
uint8_t gHue = 0;
uint16_t blinkAnimation = LEDSTRIP_OVERWRITE_NONE;
LedstripAnimation animation_type = LedstripAnimation::DefaultRainbow;
void initLedStrip()
{
animation_type = LedstripAnimation(configs.ledstrip.animationType.value);
leds.resize(configs.ledstrip.ledsCount.value);
FastLED.addLeds<NEOPIXEL, PINS_LEDSTRIP>(&*std::begin(leds), leds.size())
.setCorrection(TypicalSMD5050);
@ -202,11 +200,14 @@ void showAnimation()
#endif
)
{
if (animation_type == LedstripAnimation::DefaultRainbow) showDefaultLedstrip();
else if (animation_type == LedstripAnimation::BetterRainbow) showBetterRainbow();
else if (animation_type == LedstripAnimation::SpeedSync) showSpeedSyncAnimation();
else if (animation_type == LedstripAnimation::CustomColor) showCustomColor();
else showDefaultLedstrip();
switch (configs.ledstrip.animationType.value)
{
case LedstripAnimation::DefaultRainbow: showDefaultLedstrip(); break;
case LedstripAnimation::BetterRainbow: showBetterRainbow(); break;
case LedstripAnimation::SpeedSync: showSpeedSyncAnimation(); break;
case LedstripAnimation::CustomColor: showCustomColor(); break;
default: showDefaultLedstrip();
}
}
#ifdef FEATURE_OTA
else if (asyncOtaTaskStarted && configs.ledstrip.otaMode.value != OtaAnimationModes::None)

View File

@ -16,6 +16,13 @@
x(ColorChangeAll)
DECLARE_TYPESAFE_ENUM(OtaAnimationModes, : uint8_t, OtaAnimationModesValues)
#define LedstripAnimationValues(x) \
x(DefaultRainbow) \
x(BetterRainbow) \
x(SpeedSync) \
x(CustomColor)
DECLARE_TYPESAFE_ENUM(LedstripAnimation, : uint8_t, LedstripAnimationValues)
#ifdef FEATURE_LEDSTRIP
enum Bobbycar_Side
{
@ -33,7 +40,6 @@ extern std::vector<CRGB> leds;
extern uint8_t gHue;
extern uint16_t blinkAnimation;
extern LedstripAnimation animation_type;
void showDefaultLedstrip();
void showAnimation();

View File

@ -14,13 +14,5 @@
#endif
#define LEDSTRIP_OVERWRITE_BLINKBOTH 3
enum LedstripAnimation : uint8_t
{
DefaultRainbow,
BetterRainbow,
SpeedSync,
CustomColor
};
#define BLINK_LEFT_EXPR blinkAnimation != LEDSTRIP_OVERWRITE_BLINKRIGHT
#define BLINK_RIGHT_EXPR blinkAnimation != LEDSTRIP_OVERWRITE_BLINKLEFT

View File

@ -236,7 +236,7 @@ public:
ConfigWrapper<int16_t> smallOffset {4, DoReset, {}, "smallOffset" };
ConfigWrapper<int16_t> bigOffset {10, DoReset, {}, "bigOffset" };
ConfigWrapper<bool> enableBeepWhenBlink {true, DoReset, {}, "beepwhenblink" };
ConfigWrapper<int16_t> animationType {1, DoReset, {}, "animationType" };
ConfigWrapper<LedstripAnimation> animationType{LedstripAnimation::DefaultRainbow, DoReset, {}, "animationType" };
ConfigWrapper<bool> enableFullBlink {true, DoReset, {}, "fullblink" };
ConfigWrapper<bool> enableStVO {true, DoReset, {}, "ledstvo" };
ConfigWrapper<int16_t> stvoFrontOffset {0, DoReset, {}, "ledstvofoff" };