From 7c8e416d667a98cafb65afe1106917d26bad1133 Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Fri, 1 Oct 2021 14:33:28 +0200 Subject: [PATCH 1/2] Added beep-blink, 6Wire and more --- main/accessors/settingsaccessors.h | 1 + main/actions/ledstripblinkactions.h | 20 +++++++++-- main/displays/menus/ledstripmenu.h | 2 ++ main/dpad6wire.h | 1 - main/ledstrip.h | 54 ++++++++++++++++++++--------- main/ledstripdefines.h | 9 +++-- main/presets.h | 5 +-- main/settings.h | 2 ++ main/texts.h | 1 + 9 files changed, 72 insertions(+), 23 deletions(-) diff --git a/main/accessors/settingsaccessors.h b/main/accessors/settingsaccessors.h index a81e7fa..3e640c0 100644 --- a/main/accessors/settingsaccessors.h +++ b/main/accessors/settingsaccessors.h @@ -159,6 +159,7 @@ struct SmallOffsetAccessor : public RefAccessorSaveSettings { int16_t & struct BigOffsetAccessor : public RefAccessorSaveSettings { int16_t &getRef() const override { return settings.ledstrip.bigOffset; } }; struct DeziampereAccessor : public RefAccessorSaveSettings { int16_t &getRef() const override { return settings.ledstrip.deziampere; } }; struct EnableBeepWhenBlinkAccessor : public RefAccessorSaveSettings { bool &getRef() const override { return settings.ledstrip.enableBeepWhenBlink; } }; +struct EnableFullBlinkAccessor : public RefAccessorSaveSettings { bool &getRef() const override { return settings.ledstrip.enableFullBlink; } }; #endif struct LockscreenAllowPresetSwitchAccessor : public RefAccessorSaveSettings { bool &getRef() const override { return settings.lockscreen.allowPresetSwitch; } }; diff --git a/main/actions/ledstripblinkactions.h b/main/actions/ledstripblinkactions.h index a7db559..06c5f8d 100644 --- a/main/actions/ledstripblinkactions.h +++ b/main/actions/ledstripblinkactions.h @@ -18,13 +18,29 @@ public: class LedstripAnimationBlinkLeftAction : public virtual ActionInterface { public: - void triggered() override { blinkAnimation = LEDSTRIP_OVERWRITE_BLINKLEFT; } +#ifndef LEDSTRIP_WRONG_DIRECTION + void triggered() override { + blinkAnimation = LEDSTRIP_OVERWRITE_BLINKLEFT; + } +#else + void triggered() override { + blinkAnimation = LEDSTRIP_OVERWRITE_BLINKRIGHT; + } +#endif }; class LedstripAnimationBlinkRightAction : public virtual ActionInterface { public: - void triggered() override { blinkAnimation = LEDSTRIP_OVERWRITE_BLINKRIGHT; } +#ifndef LEDSTRIP_WRONG_DIRECTION + void triggered() override { + blinkAnimation = LEDSTRIP_OVERWRITE_BLINKRIGHT; + } +#else + void triggered() override { + blinkAnimation = LEDSTRIP_OVERWRITE_BLINKLEFT; + } +#endif }; class LedstripAnimationBlinkBothAction : public virtual ActionInterface diff --git a/main/displays/menus/ledstripmenu.h b/main/displays/menus/ledstripmenu.h index 63dfb72..a635a8f 100644 --- a/main/displays/menus/ledstripmenu.h +++ b/main/displays/menus/ledstripmenu.h @@ -78,6 +78,8 @@ public: { constructMenuItem, ToggleBoolAction, CheckboxIcon, EnableLedAnimationAccessor>>(); constructMenuItem, ToggleBoolAction, CheckboxIcon, EnableBrakeLightsAccessor>>(); + constructMenuItem, ToggleBoolAction, CheckboxIcon, EnableBeepWhenBlinkAccessor>>(); + constructMenuItem, ToggleBoolAction, CheckboxIcon, EnableFullBlinkAccessor>>(); constructMenuItem, SwitchScreenAction>>(); constructMenuItem, SwitchScreenAction>>(); constructMenuItem, SwitchScreenAction>>(); diff --git a/main/dpad6wire.h b/main/dpad6wire.h index b9b86f7..8eb1eef 100644 --- a/main/dpad6wire.h +++ b/main/dpad6wire.h @@ -1,5 +1,4 @@ #pragma once -#define FEATURE_DPAD_6WIRESW // system includes #include diff --git a/main/ledstrip.h b/main/ledstrip.h index a3ec98a..4ed7647 100644 --- a/main/ledstrip.h +++ b/main/ledstrip.h @@ -1,4 +1,5 @@ #pragma once +#define FEATURE_LEDSTRIP #ifdef FEATURE_LEDSTRIP // 3rdparty lib includes #include @@ -32,37 +33,43 @@ void initLedStrip() void updateLedStrip() { EVERY_N_MILLISECONDS( 20 ) { gHue++; } + static bool have_disabled_beeper = false; 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}); - if (espchrono::millis_clock::now().time_since_epoch() % 750ms < 375ms) { if (settings.ledstrip.enableBeepWhenBlink) { - for (Controller &controller : controllers) - controller.command.buzzer.freq = 3; + for (Controller &controller : controllers) + controller.command.buzzer.freq = 3; } 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_OVERWRITE_BLINKRIGHT) + if (blinkAnimation != LEDSTRIP_OVERWRITE_BLINKRIGHT && !settings.ledstrip.enableFullBlink) + { std::fill(center - settings.ledstrip.bigOffset, center - settings.ledstrip.smallOffset, color); - if (blinkAnimation != LEDSTRIP_OVERWRITE_BLINKLEFT) + } + else if(blinkAnimation != LEDSTRIP_OVERWRITE_BLINKRIGHT && settings.ledstrip.enableFullBlink) + { + std::fill(std::begin(leds), center, color); + } + if (blinkAnimation != LEDSTRIP_OVERWRITE_BLINKLEFT && !settings.ledstrip.enableFullBlink) + { std::fill(center + settings.ledstrip.smallOffset, center + settings.ledstrip.bigOffset, color); -#else - if (blinkAnimation != LEDSTRIP_OVERWRITE_BLINKLEFT) - std::fill(center - settings.ledstrip.bigOffset, center - settings.ledstrip.smallOffset, color); - if (blinkAnimation != LEDSTRIP_OVERWRITE_BLINKRIGHT) - std::fill(center + settings.ledstrip.smallOffset, center + settings.ledstrip.bigOffset, color); -#endif + } + else if(blinkAnimation != LEDSTRIP_OVERWRITE_BLINKLEFT && settings.ledstrip.enableFullBlink) + { + std::fill(center, std::end(leds), color); + } + } else { if (settings.ledstrip.enableBeepWhenBlink) { - for (Controller &controller : controllers) - controller.command.buzzer.freq = 0; + for (Controller &controller : controllers) + controller.command.buzzer.freq = 0; } } } @@ -86,8 +93,15 @@ void updateLedStrip() const auto center = (std::begin(leds) + (leds.size() / 2) + settings.ledstrip.centerOffset); std::fill(std::begin(leds), std::end(leds), CRGB{0, 0, 0}); - std::fill(center - settings.ledstrip.bigOffset, center - settings.ledstrip.smallOffset, color); - std::fill(center + settings.ledstrip.smallOffset, center + settings.ledstrip.bigOffset, color); + if (settings.ledstrip.enableFullBlink) + { + std::fill(std::begin(leds), std::end(leds), color); + } + else + { + std::fill(center - settings.ledstrip.bigOffset, center - settings.ledstrip.smallOffset, color); + std::fill(center + settings.ledstrip.smallOffset, center + settings.ledstrip.bigOffset, color); + } } else { @@ -100,6 +114,14 @@ void updateLedStrip() } } + if (have_disabled_beeper == false && !(cpputils::is_in(blinkAnimation, LEDSTRIP_OVERWRITE_BLINKLEFT, LEDSTRIP_OVERWRITE_BLINKRIGHT, LEDSTRIP_OVERWRITE_BLINKBOTH))) + { + for (Controller &controller : controllers) + controller.command.buzzer.freq = 0; + have_disabled_beeper = true; + } + else if (cpputils::is_in(blinkAnimation, LEDSTRIP_OVERWRITE_BLINKLEFT, LEDSTRIP_OVERWRITE_BLINKRIGHT, LEDSTRIP_OVERWRITE_BLINKBOTH)) have_disabled_beeper = false; + FastLED.setMaxPowerInVoltsAndMilliamps(5,settings.ledstrip.deziampere * 100); FastLED.show(); } diff --git a/main/ledstripdefines.h b/main/ledstripdefines.h index f292349..772848c 100644 --- a/main/ledstripdefines.h +++ b/main/ledstripdefines.h @@ -4,9 +4,14 @@ */ #define LEDSTRIP_OVERWRITE_NONE 0 -#define LEDSTRIP_OVERWRITE_BLINKLEFT 1 +#ifndef LEDSTRIP_WRONG_DIRECTION +#define LEDSTRIP_OVERWRITE_BLINKLEFT 1 #define LEDSTRIP_OVERWRITE_BLINKRIGHT 2 -#define LEDSTRIP_OVERWRITE_BLINKBOTH 3 +#else +#define LEDSTRIP_OVERWRITE_BLINKLEFT 2 +#define LEDSTRIP_OVERWRITE_BLINKRIGHT 1 +#endif +#define LEDSTRIP_OVERWRITE_BLINKBOTH 3 #define LEDSTRIP_ANIMATION_TYPE_DEFAULTRAINBOW 0 diff --git a/main/presets.h b/main/presets.h index 23c19b3..fe0640f 100644 --- a/main/presets.h +++ b/main/presets.h @@ -234,10 +234,11 @@ constexpr Settings::Ledstrip defaultLedstrip { .deziampere = 30, .enableBeepWhenBlink = false, #ifdef LEDSTRIP_ANIMATION_DEFAULT - .animationType = LEDSTRIP_ANIMATION_DEFAULT + .animationType = LEDSTRIP_ANIMATION_DEFAULT, #else - .animationType = LEDSTRIP_ANIMATION_TYPE_DEFAULTRAINBOW + .animationType = LEDSTRIP_ANIMATION_TYPE_DEFAULTRAINBOW, #endif + .enableFullBlink = false }; #endif diff --git a/main/settings.h b/main/settings.h index 287f236..8092b81 100644 --- a/main/settings.h +++ b/main/settings.h @@ -163,6 +163,7 @@ struct Settings int16_t deziampere; bool enableBeepWhenBlink; int16_t animationType; + bool enableFullBlink; } ledstrip; #endif @@ -264,6 +265,7 @@ void Settings::executeForEveryCommonSetting(T &&callable) callable("deziampere", ledstrip.deziampere); callable("beeppwhenblink", ledstrip.enableBeepWhenBlink); // callable("animationType", ledstrip.animationType); + callable("fullblink", ledstrip.enableFullBlink); #endif callable("lockAlwPresetSw", lockscreen.allowPresetSwitch); diff --git a/main/texts.h b/main/texts.h index 49cc0a0..10f6cbc 100644 --- a/main/texts.h +++ b/main/texts.h @@ -250,6 +250,7 @@ constexpr char TEXT_SMALLOFFSET[] = "Small Offset"; constexpr char TEXT_BIGOFFSET[] = "Big Offset"; constexpr char TEXT_LEDSTRIP_MILLIAMP[] = "Ledstrip 0.1A"; constexpr char TEXT_BLINKBEEP[] = "Blink Beep"; +constexpr char TEXT_FULLBLINK[] = "Full blink"; //constexpr char TEXT_BACK[] = "Back"; //LedstripSelectAnimationMenu From fbb2ba1905ad6a444809195b77d3fda1da5cac2c Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Fri, 1 Oct 2021 15:58:59 +0200 Subject: [PATCH 2/2] Should fix bug that beeper won't turn off if turning the feature off in ledstrip menu --- main/ledstrip.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main/ledstrip.h b/main/ledstrip.h index 4ed7647..6f47a74 100644 --- a/main/ledstrip.h +++ b/main/ledstrip.h @@ -114,13 +114,13 @@ void updateLedStrip() } } - if (have_disabled_beeper == false && !(cpputils::is_in(blinkAnimation, LEDSTRIP_OVERWRITE_BLINKLEFT, LEDSTRIP_OVERWRITE_BLINKRIGHT, LEDSTRIP_OVERWRITE_BLINKBOTH))) + if (have_disabled_beeper == false && (!(cpputils::is_in(blinkAnimation, LEDSTRIP_OVERWRITE_BLINKLEFT, LEDSTRIP_OVERWRITE_BLINKRIGHT, LEDSTRIP_OVERWRITE_BLINKBOTH)) || !settings.ledstrip.enableBeepWhenBlink)) { for (Controller &controller : controllers) controller.command.buzzer.freq = 0; have_disabled_beeper = true; } - else if (cpputils::is_in(blinkAnimation, LEDSTRIP_OVERWRITE_BLINKLEFT, LEDSTRIP_OVERWRITE_BLINKRIGHT, LEDSTRIP_OVERWRITE_BLINKBOTH)) have_disabled_beeper = false; + else if ((cpputils::is_in(blinkAnimation, LEDSTRIP_OVERWRITE_BLINKLEFT, LEDSTRIP_OVERWRITE_BLINKRIGHT, LEDSTRIP_OVERWRITE_BLINKBOTH)) && settings.ledstrip.enableBeepWhenBlink) have_disabled_beeper = false; FastLED.setMaxPowerInVoltsAndMilliamps(5,settings.ledstrip.deziampere * 100); FastLED.show();