diff --git a/main/displays/menus/ledstripcolorsmenu.h b/main/displays/menus/ledstripcolorsmenu.h index 14b97cc..d6fd9b9 100644 --- a/main/displays/menus/ledstripcolorsmenu.h +++ b/main/displays/menus/ledstripcolorsmenu.h @@ -1,6 +1,8 @@ #pragma once #include +#include +#include // Local includes #include "menudisplay.h" @@ -12,6 +14,8 @@ #include "texts.h" #include "actions/dummyaction.h" #include "actions/switchscreenaction.h" +#include "actioninterface.h" +#include "globals.h" using namespace espgui; @@ -19,27 +23,158 @@ namespace { class LedstripMenu; } -namespace { +namespace { + +static uint8_t ledstrip_side; +static int8_t selected_color; +bool state_select_color{false}; +bool last_state = {false}; + +const std::array Colors = { + CRGB{0,0,0}, + CRGB{255,255,255}, + CRGB{255,0,0}, + CRGB{255,255,0}, + CRGB{0,255,0}, + CRGB{0,255,255}, + CRGB{0,0,255}, + CRGB{255,0,255} +}; + +const std::array tft_colors = { + TFT_BLACK, + TFT_WHITE, + TFT_RED, + TFT_YELLOW, + TFT_GREEN, + TFT_CYAN, + TFT_BLUE, + TFT_MAGENTA +}; + +class LedstripColorsMenuBackAction : ActionInterface +{ +public: + void triggered() { + if(!state_select_color) + { + switchScreen(); + } + else + { + state_select_color = false; + tft.fillRect(0, 228, tft.width(), ((tft.width() - 40) / 8) + 4, TFT_BLACK); + } + } +}; + class LedstripColorsMenu : public MenuDisplay, public StaticText, - public BackActionInterface> + public BackActionInterface { using Base = MenuDisplay; public: void redraw() override; - LedstripColorsMenu() - { - constructMenuItem, SwitchScreenAction, StaticMenuItemIcon<&espgui::icons::back>>>(); - } + void rotate(int offset) override; + void confirm() override; + uint8_t side_to_crgb_index(uint8_t side); + void drawColors(); + LedstripColorsMenu() {} }; +uint8_t LedstripColorsMenu::side_to_crgb_index(uint8_t side) +{ + return 0; +} + void LedstripColorsMenu::redraw() { Base::redraw(); tft.setSwapBytes(true); - tft.pushImage(70, 80, bobbyicons::bobbycar.WIDTH, bobbyicons::bobbycar.HEIGHT, bobbyicons::bobbycar.buffer); + tft.pushImage(70, 60, bobbyicons::bobbycar.WIDTH, bobbyicons::bobbycar.HEIGHT, bobbyicons::bobbycar.buffer); tft.setSwapBytes(false); + + auto y_pos = ((tft.width() - 40) / 8 + 4) + 240; + if (last_state != state_select_color) + { + tft.fillRect(0,y_pos - 1, tft.width(), 20, TFT_BLACK); + last_state = state_select_color; + } + + tft.setTextFont(2); + tft.setTextColor(TFT_WHITE); + if(state_select_color) + { + tft.drawString("Please select a color!", 50, y_pos); + } + else + { + tft.drawString("Please select a side!", 50, y_pos); + } +} + +void LedstripColorsMenu::rotate(int offset) +{ + if (offset < 0) + { + if (state_select_color) + { + selected_color++; + if (selected_color > 7) + { + selected_color = 0; + } + } + } else if (offset > 0) + { + if (state_select_color) + { + selected_color--; + if (selected_color < 0) + { + selected_color = 7; + } + } + } + + if (state_select_color) + { + this->drawColors(); + } + else + { + tft.fillRect(0, 228, tft.width(), ((tft.width() - 40) / 8) + 4, TFT_BLACK); + } +} + +void LedstripColorsMenu::confirm() +{ + if(!state_select_color) + { + state_select_color = true; + this->drawColors(); + } + else + { + ledstrip_custom_colors[side_to_crgb_index(ledstrip_side)] = Colors[selected_color]; + } +} + +void LedstripColorsMenu::drawColors() +{ + uint16_t width = (tft.width() - 40); + auto cube_width = width / 8; + + tft.fillRect(0, 228, tft.width(), cube_width + 4, TFT_BLACK); + tft.fillRect(21, 231, width - 1, cube_width - 1, TFT_WHITE); + + tft.fillRect(20 + (selected_color * cube_width - 1), 228, cube_width + 4, cube_width + 4, TFT_YELLOW); + for (int index = 0; index < 8; index++) + { + auto offset = index * (cube_width); + tft.fillRect(22 + offset, 232, cube_width - 4, cube_width - 4, tft_colors[index]); + } } } // Namespace diff --git a/main/globals.h b/main/globals.h index 5909e73..8aa2aa8 100644 --- a/main/globals.h +++ b/main/globals.h @@ -55,6 +55,8 @@ Settings settings; StringSettings stringSettings; SettingsPersister settingsPersister; +std::array ledstrip_custom_colors = {}; + class Controllers : public std::array { public: diff --git a/main/ledstripdefines.h b/main/ledstripdefines.h index 772848c..efbdde8 100644 --- a/main/ledstripdefines.h +++ b/main/ledstripdefines.h @@ -17,3 +17,4 @@ #define LEDSTRIP_ANIMATION_TYPE_DEFAULTRAINBOW 0 #define LEDSTRIP_ANIMATION_TYPE_BETTERRAINBOW 1 #define LEDSTRIP_ANIMATION_TYPE_SPEEDSYNCANIMATION 2 +#define LEDSTRIP_ANIMATION_TYPE_CUSTOMCOLOR 3 diff --git a/main/settings.h b/main/settings.h index c9f42c8..55f94a9 100644 --- a/main/settings.h +++ b/main/settings.h @@ -3,6 +3,7 @@ // system includes #include #include +#include // esp-idf includes #include