From ddf0d271371319d398c2f5442e1d70feb470612b Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Tue, 7 Dec 2021 02:53:43 +0100 Subject: [PATCH] Refactored Ledstrip (Fixed types and removed Macros) --- main/actions/ledstripanimationactions.h | 2 +- main/ledstrip.cpp | 12 ++++++------ main/ledstrip.h | 4 ++-- main/ledstripdefines.h | 12 +++++++----- main/presets.h | 2 +- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/main/actions/ledstripanimationactions.h b/main/actions/ledstripanimationactions.h index ed08b8f..d79671e 100644 --- a/main/actions/ledstripanimationactions.h +++ b/main/actions/ledstripanimationactions.h @@ -10,7 +10,7 @@ using namespace espgui; namespace { #ifdef FEATURE_LEDSTRIP -template +template class LedStripSetAnimationAction : public virtual ActionInterface { public: diff --git a/main/ledstrip.cpp b/main/ledstrip.cpp index 625d866..b35229a 100644 --- a/main/ledstrip.cpp +++ b/main/ledstrip.cpp @@ -16,8 +16,8 @@ using namespace std::chrono_literals; std::vector leds; uint8_t gHue = 0; -int16_t blinkAnimation = LEDSTRIP_OVERWRITE_NONE; -int16_t animation_type = LEDSTRIP_ANIMATION_TYPE_DEFAULTRAINBOW; +uint16_t blinkAnimation = LEDSTRIP_OVERWRITE_NONE; +uint16_t animation_type = LedstripAnimation::DefaultRainbow; void initLedStrip() @@ -215,10 +215,10 @@ void showAnimation() { if (settings.ledstrip.enableLedAnimation && !simplified && !(asyncOtaTaskStarted && settings.ledstrip.otaMode != OtaAnimationModes::None)) { - 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 if (animation_type == LEDSTRIP_ANIMATION_TYPE_CUSTOMCOLOR) showCustomColor(); + 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(); } else if (asyncOtaTaskStarted && settings.ledstrip.otaMode != OtaAnimationModes::None) diff --git a/main/ledstrip.h b/main/ledstrip.h index 5c79fd4..e8edea8 100644 --- a/main/ledstrip.h +++ b/main/ledstrip.h @@ -29,8 +29,8 @@ enum OtaAnimationModes extern std::vector leds; extern uint8_t gHue; -extern int16_t blinkAnimation; -extern int16_t animation_type; +extern uint16_t blinkAnimation; +extern uint16_t animation_type; void showDefaultLedstrip(); void showAnimation(); diff --git a/main/ledstripdefines.h b/main/ledstripdefines.h index 283f1e3..5582ca9 100644 --- a/main/ledstripdefines.h +++ b/main/ledstripdefines.h @@ -1,4 +1,5 @@ #pragma once +#include /* * This file contains a few defines, so you don't have to remember which ledstrip animation is which number */ @@ -13,11 +14,12 @@ #endif #define LEDSTRIP_OVERWRITE_BLINKBOTH 3 - -#define LEDSTRIP_ANIMATION_TYPE_DEFAULTRAINBOW 0 -#define LEDSTRIP_ANIMATION_TYPE_BETTERRAINBOW 1 -#define LEDSTRIP_ANIMATION_TYPE_SPEEDSYNCANIMATION 2 -#define LEDSTRIP_ANIMATION_TYPE_CUSTOMCOLOR 3 +enum LedstripAnimation : uint16_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/presets.h b/main/presets.h index 578bc5f..c99feab 100644 --- a/main/presets.h +++ b/main/presets.h @@ -256,7 +256,7 @@ constexpr Settings::Ledstrip defaultLedstrip { #ifdef LEDSTRIP_ANIMATION_DEFAULT .animationType = LEDSTRIP_ANIMATION_DEFAULT, #else - .animationType = LEDSTRIP_ANIMATION_TYPE_DEFAULTRAINBOW, + .animationType = LedstripAnimation::DefaultRainbow, #endif .enableFullBlink = false, .enableStVO = false,