From 5c3ad4f89165964049c543de0377cca44380d681 Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Fri, 22 Oct 2021 16:39:14 +0200 Subject: [PATCH] Color now changeable for 8 sides (#104) --- main/displays/menus/ledstripcolorsmenu.h | 97 +++++++++++++++++-- main/displays/menus/ledstripmenu.h | 16 +++ .../menus/ledstripselectanimationmenu.h | 3 + main/ledstrip.h | 48 +++++++++ main/texts.h | 2 + 5 files changed, 157 insertions(+), 9 deletions(-) diff --git a/main/displays/menus/ledstripcolorsmenu.h b/main/displays/menus/ledstripcolorsmenu.h index d6fd9b9..7960503 100644 --- a/main/displays/menus/ledstripcolorsmenu.h +++ b/main/displays/menus/ledstripcolorsmenu.h @@ -16,6 +16,7 @@ #include "actions/switchscreenaction.h" #include "actioninterface.h" #include "globals.h" +#include "esp_log.h" using namespace espgui; @@ -25,7 +26,7 @@ namespace { namespace { -static uint8_t ledstrip_side; +static int8_t selected_side = 7; static int8_t selected_color; bool state_select_color{false}; bool last_state = {false}; @@ -78,16 +79,14 @@ public: void redraw() override; void rotate(int offset) override; void confirm() override; - uint8_t side_to_crgb_index(uint8_t side); void drawColors(); + void drawSide(Bobbycar_Side side, unsigned int color); + void clearSides(); LedstripColorsMenu() {} +private: + bool already_drew_circle{false}; }; -uint8_t LedstripColorsMenu::side_to_crgb_index(uint8_t side) -{ - return 0; -} - void LedstripColorsMenu::redraw() { Base::redraw(); @@ -112,6 +111,11 @@ void LedstripColorsMenu::redraw() { tft.drawString("Please select a side!", 50, y_pos); } + if(!already_drew_circle) + { + this->drawSide(static_cast(selected_side), TFT_GOLD); + already_drew_circle = true; + } } void LedstripColorsMenu::rotate(int offset) @@ -126,7 +130,16 @@ void LedstripColorsMenu::rotate(int offset) selected_color = 0; } } - } else if (offset > 0) + else + { + selected_side++; + if (selected_side > 7) + { + selected_side = 0; + } + } + } + else if (offset > 0) { if (state_select_color) { @@ -136,6 +149,14 @@ void LedstripColorsMenu::rotate(int offset) selected_color = 7; } } + else + { + selected_side--; + if (selected_side < 0) + { + selected_side = 7; + } + } } if (state_select_color) @@ -145,6 +166,8 @@ void LedstripColorsMenu::rotate(int offset) else { tft.fillRect(0, 228, tft.width(), ((tft.width() - 40) / 8) + 4, TFT_BLACK); + this->clearSides(); + this->drawSide(static_cast(selected_side), TFT_GOLD); } } @@ -157,7 +180,12 @@ void LedstripColorsMenu::confirm() } else { - ledstrip_custom_colors[side_to_crgb_index(ledstrip_side)] = Colors[selected_color]; + ledstrip_custom_colors[selected_side] = Colors[selected_color]; + // Uncomment to close select color menu on color select + /* + state_select_color = false; + tft.fillRect(0, 228, tft.width(), ((tft.width() - 40) / 8) + 4, TFT_BLACK); + */ } } @@ -177,4 +205,55 @@ void LedstripColorsMenu::drawColors() } } +void LedstripColorsMenu::clearSides() +{ + for(int index = 0; index < 8; index++) + { + this->drawSide(static_cast(index), TFT_BLACK); + } +} + +void LedstripColorsMenu::drawSide(Bobbycar_Side side, unsigned int color) +{ + const auto middle = tft.width() / 2; + const auto width = bobbyicons::bobbycar.WIDTH; + const auto height = bobbyicons::bobbycar.HEIGHT; + const auto left = middle - (width / 2); + const auto right = middle + (width / 2); + const auto above = 50; + const auto bellow = above + 10 + bobbyicons::bobbycar.HEIGHT; + + switch (side) { + case Bobbycar_Side::FRONT: + tft.fillRect(left, above, width, 5, color); + break; + case Bobbycar_Side::FRONT_LEFT: + tft.fillRect(left - 10, above + 10, 5, height / 2, color); + tft.fillRect(left, above, width / 2, 5, color); + break; + case Bobbycar_Side::LEFT: + tft.fillRect(left - 10, above + 10, 5, height, color); + break; + case Bobbycar_Side::BACK_LEFT: + tft.fillRect(left - 10, above + 10 + (height / 2), 5, height / 2, color); + tft.fillRect(left, bellow + 5, width / 2, 5, color); + break; + case Bobbycar_Side::BACK: + tft.fillRect(left, bellow + 5, width, 5, color); + break; + case Bobbycar_Side::BACK_RIGHT: + tft.fillRect(right + 5, above + 10 + (height / 2), 5, height / 2, color); + tft.fillRect(middle, bellow + 5, width / 2, 5, color); + break; + case Bobbycar_Side::RIGHT: + tft.fillRect(right + 5, above + 10, 5, height, color); + break; + case Bobbycar_Side::FRONT_RIGHT: + tft.fillRect(right + 5, above + 10, 5, height / 2, color); + tft.fillRect(middle, above, width / 2, 5, color); + break; + } + // tft.fillCircle(tft.width() / 2, 140, 100, TFT_BLACK); +} + } // Namespace diff --git a/main/displays/menus/ledstripmenu.h b/main/displays/menus/ledstripmenu.h index cee6264..e447d73 100644 --- a/main/displays/menus/ledstripmenu.h +++ b/main/displays/menus/ledstripmenu.h @@ -1,4 +1,7 @@ #pragma once + +#include + // local includes #include "menudisplay.h" #include "menuitem.h" @@ -15,6 +18,7 @@ #include "ledstrip.h" #endif #include "changevaluedisplay.h" +#include "actioninterface.h" // forward declares namespace { @@ -101,6 +105,17 @@ using ledstripBrightnessChangeScreen = makeComponent< SwitchScreenAction >; +class AllCustomLedsOffAction : public virtual ActionInterface +{ +public: + void triggered() { + for(int index = 0; index < 8; index++) + { + ledstrip_custom_colors[index] = CRGB{0,0,0}; + } + } +}; + class LedstripMenu : public MenuDisplay, public StaticText, @@ -117,6 +132,7 @@ public: if (!simplified) { constructMenuItem, ToggleBoolAction, CheckboxIcon, EnableLedstripStVOAccessor>>(); } constructMenuItem, ToggleBoolAction, CheckboxIcon, EnableLedstripStVOFrontlight>>(); + constructMenuItem, AllCustomLedsOffAction>>(); if (!simplified) { constructMenuItem, SwitchScreenAction>>(); } if (!simplified) { constructMenuItem, SwitchScreenAction>>(); } diff --git a/main/displays/menus/ledstripselectanimationmenu.h b/main/displays/menus/ledstripselectanimationmenu.h index 783f972..df731a7 100644 --- a/main/displays/menus/ledstripselectanimationmenu.h +++ b/main/displays/menus/ledstripselectanimationmenu.h @@ -22,6 +22,8 @@ class currentSelectedAnimationText : public virtual TextInterface { public: std: return TEXT_ANIMATION_BETTERRAINBOW; case LEDSTRIP_ANIMATION_TYPE_SPEEDSYNCANIMATION: return TEXT_ANIMATION_SPEEDSYNCANIMATION; + case LEDSTRIP_ANIMATION_TYPE_CUSTOMCOLOR: + return TEXT_ANIMATION_CUSTOMCOLOR; default: return "Animation Unkown"; } @@ -48,6 +50,7 @@ namespace { constructMenuItem, LedStripSetAnimationAction>>(); constructMenuItem, LedStripSetAnimationAction>>(); constructMenuItem, LedStripSetAnimationAction>>(); + constructMenuItem, LedStripSetAnimationAction>>(); constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); } }; diff --git a/main/ledstrip.h b/main/ledstrip.h index 1b4fc44..205c257 100644 --- a/main/ledstrip.h +++ b/main/ledstrip.h @@ -10,6 +10,18 @@ #include "ledstripdefines.h" namespace { + +enum Bobbycar_Side { + FRONT_RIGHT, + RIGHT, + BACK_RIGHT, + BACK, + BACK_LEFT, + LEFT, + FRONT_LEFT, + FRONT +}; + std::vector leds; uint8_t gHue = 0; @@ -20,6 +32,7 @@ void showDefaultLedstrip(); void showAnimation(); void showBetterRainbow(); void showSpeedSyncAnimation(); +void showCustomColor(); void initLedStrip() { @@ -154,6 +167,7 @@ void showAnimation() { 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(); else showDefaultLedstrip(); } else @@ -221,5 +235,39 @@ void showDefaultLedstrip() dothue += 32; } } + +void showCustomColor() +{ + const auto eighth_length = leds.size() / 8; + const auto center = (std::begin(leds) + (leds.size() / 2) + settings.ledstrip.centerOffset); + + std::fill(std::begin(leds), std::end(leds), ledstrip_custom_colors[int(Bobbycar_Side::FRONT)]); // Front + std::fill(center - (eighth_length / 2), center + (eighth_length / 2), ledstrip_custom_colors[int(Bobbycar_Side::BACK)]); // Back + +#ifdef LEDSTRIP_WRONG_DIRECTION + std::fill(center + (eighth_length / 2), center + (eighth_length / 2) + eighth_length, ledstrip_custom_colors[int(Bobbycar_Side::BACK_LEFT)]); // Back Left + std::fill(center - (eighth_length / 2) - eighth_length, center - (eighth_length / 2), ledstrip_custom_colors[int(Bobbycar_Side::BACK_RIGHT)]); // Back Right +#else + std::fill(center + (eighth_length / 2), center + (eighth_length / 2) + eighth_length, ledstrip_custom_colors[int(Bobbycar_Side::BACK_RIGHT)]); // Back Right + std::fill(center - (eighth_length / 2) - eighth_length, center - (eighth_length / 2), ledstrip_custom_colors[int(Bobbycar_Side::BACK_LEFT)]); // Back Left +#endif + +#ifdef LEDSTRIP_WRONG_DIRECTION + std::fill(center + (eighth_length / 2) + eighth_length, center + (eighth_length / 2) + eighth_length + eighth_length, ledstrip_custom_colors[int(Bobbycar_Side::LEFT)]); // Left + std::fill(center - (eighth_length / 2) - eighth_length - eighth_length, center - (eighth_length / 2) - eighth_length, ledstrip_custom_colors[int(Bobbycar_Side::RIGHT)]); // Right +#else + std::fill(center + (eighth_length / 2) + eighth_length, center + (eighth_length / 2) + eighth_length + eighth_length, ledstrip_custom_colors[int(Bobbycar_Side::RIGHT)]); // Right + std::fill(center - (eighth_length / 2) - eighth_length - eighth_length, center - (eighth_length / 2) - eighth_length, ledstrip_custom_colors[int(Bobbycar_Side::LEFT)]); // Left +#endif + +#ifdef LEDSTRIP_WRONG_DIRECTION + std::fill(center + (eighth_length / 2) + eighth_length + eighth_length, center + (eighth_length / 2) + eighth_length + eighth_length + eighth_length, ledstrip_custom_colors[int(Bobbycar_Side::FRONT_LEFT)]); // Front Left + std::fill(center - (eighth_length / 2) - eighth_length - eighth_length - eighth_length, center - (eighth_length / 2) - eighth_length - eighth_length, ledstrip_custom_colors[int(Bobbycar_Side::FRONT_RIGHT)]); // Front Right +#else + std::fill(center + (eighth_length / 2) + eighth_length + eighth_length, center + (eighth_length / 2) + eighth_length + eighth_length + eighth_length, ledstrip_custom_colors[int(Bobbycar_Side::FRONT_RIGHT)]); // Front Right + std::fill(center - (eighth_length / 2) - eighth_length - eighth_length - eighth_length, center - (eighth_length / 2) - eighth_length - eighth_length, ledstrip_custom_colors[int(Bobbycar_Side::FRONT_LEFT)]); // Front Left +#endif + +} } // namespace #endif diff --git a/main/texts.h b/main/texts.h index cd267d0..fd7d226 100644 --- a/main/texts.h +++ b/main/texts.h @@ -289,6 +289,7 @@ constexpr char TEXT_STVO_FRONTLENGTH[] = "StVO Front Length"; constexpr char TEXT_STVO_ENABLEFRONTLIGHT[] = "StVO Front Enable"; constexpr char TEXT_ANIMATION_MULTIPLIER[] = "Animation Multiplier"; constexpr char TEXT_LEDSTRIP_BRIGHTNESS[] = "Ledstrip Brightness"; +constexpr char TEXT_LEDSTRIP_ALLCUSTOMOFF[] = "All custom off"; //constexpr char TEXT_BACK[] = "Back"; //LedstripSelectAnimationMenu @@ -296,6 +297,7 @@ constexpr char TEXT_SELECTANIMATION[] = "Select Animation"; constexpr char TEXT_ANIMATION_DEFAULTRAINBOW[] = "Default Rainbow"; constexpr char TEXT_ANIMATION_BETTERRAINBOW[] = "Better Rainbow"; constexpr char TEXT_ANIMATION_SPEEDSYNCANIMATION[] = "Speed Sync"; +constexpr char TEXT_ANIMATION_CUSTOMCOLOR[] = "Custom Color"; //LedstripSelectBlinkMenu constexpr char TEXT_ANIMATION_BLINKNONE[] = "Blink Off";