From a3e719bd81a5db165f4c4dd86c95965ba01ea875 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Mon, 3 Jan 2022 21:00:16 +0100 Subject: [PATCH] Fixed ledstrip animationType --- main/actions/ledstripanimationactions.h | 11 ++++++++++- main/configutils_bobby.h | 1 + main/configwrapper_bobby.cpp | 1 + .../menus/ledstripselectanimationmenu.cpp | 4 +++- main/ledstrip.cpp | 15 ++++++++------- main/ledstrip.h | 8 +++++++- main/ledstripdefines.h | 8 -------- main/newsettings.h | 2 +- 8 files changed, 31 insertions(+), 19 deletions(-) diff --git a/main/actions/ledstripanimationactions.h b/main/actions/ledstripanimationactions.h index 3dd39ad..ce0ab14 100644 --- a/main/actions/ledstripanimationactions.h +++ b/main/actions/ledstripanimationactions.h @@ -6,12 +6,21 @@ // local includes #include "ledstrip.h" #include "ledstripdefines.h" +#include "newsettings.h" +#include "bobbyerrorhandler.h" #ifdef FEATURE_LEDSTRIP template class LedStripSetAnimationAction : public virtual espgui::ActionInterface { public: - void triggered() override { animation_type = type; } + void triggered() override; }; + +template +void LedStripSetAnimationAction::triggered() +{ + if (auto result = configs.write_config(configs.ledstrip.animationType, type); !result) + BobbyErrorHandler{}.errorOccured(std::move(result).error()); +} #endif diff --git a/main/configutils_bobby.h b/main/configutils_bobby.h index b145153..938db07 100644 --- a/main/configutils_bobby.h +++ b/main/configutils_bobby.h @@ -10,3 +10,4 @@ IMPLEMENT_NVS_GET_SET_ENUM(OtaAnimationModes) IMPLEMENT_NVS_GET_SET_ENUM(HandbremseMode) +IMPLEMENT_NVS_GET_SET_ENUM(LedstripAnimation) diff --git a/main/configwrapper_bobby.cpp b/main/configwrapper_bobby.cpp index 46bef2f..31289b6 100644 --- a/main/configwrapper_bobby.cpp +++ b/main/configwrapper_bobby.cpp @@ -6,3 +6,4 @@ INSTANTIATE_CONFIGWRAPPER_TEMPLATES(OtaAnimationModes) INSTANTIATE_CONFIGWRAPPER_TEMPLATES(HandbremseMode) +INSTANTIATE_CONFIGWRAPPER_TEMPLATES(LedstripAnimation) diff --git a/main/displays/menus/ledstripselectanimationmenu.cpp b/main/displays/menus/ledstripselectanimationmenu.cpp index 4444707..391a705 100644 --- a/main/displays/menus/ledstripselectanimationmenu.cpp +++ b/main/displays/menus/ledstripselectanimationmenu.cpp @@ -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: diff --git a/main/ledstrip.cpp b/main/ledstrip.cpp index 6e4b304..cd85b14 100644 --- a/main/ledstrip.cpp +++ b/main/ledstrip.cpp @@ -18,12 +18,10 @@ std::vector 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(&*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) diff --git a/main/ledstrip.h b/main/ledstrip.h index 6570f96..08f0483 100644 --- a/main/ledstrip.h +++ b/main/ledstrip.h @@ -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 leds; extern uint8_t gHue; extern uint16_t blinkAnimation; -extern LedstripAnimation animation_type; void showDefaultLedstrip(); void showAnimation(); diff --git a/main/ledstripdefines.h b/main/ledstripdefines.h index 2713e4b..8db9bdc 100644 --- a/main/ledstripdefines.h +++ b/main/ledstripdefines.h @@ -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 diff --git a/main/newsettings.h b/main/newsettings.h index cf70ea1..2d53889 100644 --- a/main/newsettings.h +++ b/main/newsettings.h @@ -236,7 +236,7 @@ public: ConfigWrapper smallOffset {4, DoReset, {}, "smallOffset" }; ConfigWrapper bigOffset {10, DoReset, {}, "bigOffset" }; ConfigWrapper enableBeepWhenBlink {true, DoReset, {}, "beepwhenblink" }; - ConfigWrapper animationType {1, DoReset, {}, "animationType" }; + ConfigWrapper animationType{LedstripAnimation::DefaultRainbow, DoReset, {}, "animationType" }; ConfigWrapper enableFullBlink {true, DoReset, {}, "fullblink" }; ConfigWrapper enableStVO {true, DoReset, {}, "ledstvo" }; ConfigWrapper stvoFrontOffset {0, DoReset, {}, "ledstvofoff" };