diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index cf41118..cdbff58 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -13,6 +13,7 @@ set(headers actions/bmsturnonchargeaction.h actions/bmsturnondischargeaction.h actions/erasenvsaction.h + actions/ledstripanimationactions.h actions/loadsettingsaction.h actions/modesettingsaction.h actions/multiaction.h @@ -55,6 +56,7 @@ set(headers displays/menus/invertmenu.h displays/menus/larsmmodesettingsmenu.h displays/menus/ledstripmenu.h + displays/menus/ledstripselectanimationmenu.h displays/menus/modessettingsmenu.h displays/menus/mosfetsmenu.h displays/menus/motorstatedebugmenu.h @@ -111,6 +113,7 @@ set(headers icons/update.h icons/wifi.h ledstrip.h + ledstripdefines.h modes/defaultmode.h modes/gametrakmode.h modes/ignoreinputmode.h diff --git a/main/actions/ledstripanimationactions.h b/main/actions/ledstripanimationactions.h new file mode 100644 index 0000000..3f7b4e6 --- /dev/null +++ b/main/actions/ledstripanimationactions.h @@ -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 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; } +}; +} diff --git a/main/displays/menus/ledstripmenu.h b/main/displays/menus/ledstripmenu.h index b56fb9a..9ac55eb 100644 --- a/main/displays/menus/ledstripmenu.h +++ b/main/displays/menus/ledstripmenu.h @@ -5,6 +5,7 @@ #include "menuitem.h" #include "actions/toggleboolaction.h" #include "actions/switchscreenaction.h" +#include "ledstripselectanimationmenu.h" #include "texts.h" #include "icons/back.h" #include "checkboxicon.h" @@ -25,6 +26,7 @@ using namespace espgui; namespace { #ifdef FEATURE_LEDSTRIP class LedstripMenu; +class LedstripSelectAnimationMenu; struct BlinkAnimationAccessor : public RefAccessor { int16_t &getRef() const override { return blinkAnimation; } }; @@ -78,7 +80,8 @@ public: { constructMenuItem, ToggleBoolAction, CheckboxIcon, EnableLedAnimationAccessor>>(); constructMenuItem, ToggleBoolAction, CheckboxIcon, EnableBrakeLightsAccessor>>(); - constructMenuItem, SwitchScreenAction>>(); + constructMenuItem, SwitchScreenAction>>(); +// constructMenuItem, SwitchScreenAction>>(); constructMenuItem, SwitchScreenAction>>(); constructMenuItem, SwitchScreenAction>>(); constructMenuItem, SwitchScreenAction>>(); diff --git a/main/displays/menus/ledstripselectanimationmenu.h b/main/displays/menus/ledstripselectanimationmenu.h new file mode 100644 index 0000000..1548ed0 --- /dev/null +++ b/main/displays/menus/ledstripselectanimationmenu.h @@ -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/ledstripanimationactions.h" +#include "actions/switchscreenaction.h" + +using namespace espgui; + +namespace { + class LedstripMenu; +} + +namespace { + class LedstripSelectAnimationMenu : + public MenuDisplay, + public StaticText, + public BackActionInterface> + { + public: + LedstripSelectAnimationMenu() + { + constructMenuItem, LedstripAnimationDefaultRainbowAction>>(); + constructMenuItem, LedstripAnimationBlinkLeftAction>>(); + constructMenuItem, LedstripAnimationBlinkRightAction>>(); + constructMenuItem, LedstripAnimationBlinkBothAction>>(); + constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); + } + }; +} // Namespace diff --git a/main/ledstrip.h b/main/ledstrip.h index 4951ce0..29d6278 100644 --- a/main/ledstrip.h +++ b/main/ledstrip.h @@ -8,12 +8,13 @@ #include "globals.h" #include "cpputils.h" #include "espchrono.h" +#include "ledstripdefines.h" namespace { std::vector leds; uint8_t gHue = 0; -int16_t blinkAnimation = 0; +int16_t blinkAnimation = LEDSTRIP_ANIMATION_DEFAULT; void showDefaultLedstrip(); @@ -28,7 +29,7 @@ void updateLedStrip() { EVERY_N_MILLISECONDS( 20 ) { gHue++; } - if (cpputils::is_in(blinkAnimation, 1, 2, 3)) + if (cpputils::is_in(blinkAnimation, LEDSTRIP_ANIMATION_BLINKLEFT, LEDSTRIP_ANIMATION_BLINKRIGHT, LEDSTRIP_ANIMATION_BLINKBOTH)) { std::fill(std::begin(leds), std::end(leds), CRGB{0, 0, 0}); @@ -37,9 +38,9 @@ void updateLedStrip() auto color = CRGB{255, 255, 0}; const auto center = (std::begin(leds) + (leds.size() / 2) + settings.ledstrip.centerOffset); - if (blinkAnimation != 2) + if (blinkAnimation != LEDSTRIP_ANIMATION_BLINKLEFT) std::fill(center - settings.ledstrip.bigOffset, center - settings.ledstrip.smallOffset, color); - if (blinkAnimation != 1) + if (blinkAnimation != LEDSTRIP_ANIMATION_BLINKRIGHT) std::fill(center + settings.ledstrip.smallOffset, center + settings.ledstrip.bigOffset, color); } } diff --git a/main/ledstripdefines.h b/main/ledstripdefines.h new file mode 100644 index 0000000..88be16e --- /dev/null +++ b/main/ledstripdefines.h @@ -0,0 +1,10 @@ +#pragma once +/* + * 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_DEFAULT LEDSTRIP_ANIMATION_DEFAULTRAINBOW diff --git a/main/texts.h b/main/texts.h index 262c8df..c459f20 100644 --- a/main/texts.h +++ b/main/texts.h @@ -249,6 +249,13 @@ constexpr char TEXT_SMALLOFFSET[] = "Small Offset"; constexpr char TEXT_BIGOFFSET[] = "Big Offset"; //constexpr char TEXT_BACK[] = "Back"; +//LedstripSelectAnimationMenu +constexpr char TEXT_SELECTANIMATION[] = "Select Animation"; +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"; + //LockscreenSettingsMenu constexpr char TEXT_LOCKSCREENSETTINGS[] = "Lockscreen Settings"; constexpr char TEXT_ALLOWPRESETSWITCH[] = "Allow preset switch";