Color now changeable for 8 sides (#104)
This commit is contained in:
@ -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<Bobbycar_Side>(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<Bobbycar_Side>(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<Bobbycar_Side>(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
|
||||
|
@ -1,4 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <FastLED.h>
|
||||
|
||||
// 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<LedstripMenu>
|
||||
>;
|
||||
|
||||
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<TEXT_LEDSTRIP>,
|
||||
@ -117,6 +132,7 @@ public:
|
||||
|
||||
if (!simplified) { constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_LEDSTRIP_STVO>, ToggleBoolAction, CheckboxIcon, EnableLedstripStVOAccessor>>(); }
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_STVO_ENABLEFRONTLIGHT>, ToggleBoolAction, CheckboxIcon, EnableLedstripStVOFrontlight>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_LEDSTRIP_ALLCUSTOMOFF>, AllCustomLedsOffAction>>();
|
||||
if (!simplified) { constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_STVO_FRONTOFFSET, LedsStVOFrontOffsetAccessor>, SwitchScreenAction<StVOOffsetChangeScreen>>>(); }
|
||||
if (!simplified) { constructMenuItem<makeComponent<MenuItem, TextWithValueHelper<TEXT_STVO_FRONTLENGTH, LedsStVOFrontLengthAccessor>, SwitchScreenAction<StVOLengthChangeScreen>>>(); }
|
||||
|
||||
|
@ -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<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_DEFAULTRAINBOW>, LedStripSetAnimationAction<LEDSTRIP_ANIMATION_TYPE_DEFAULTRAINBOW>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_BETTERRAINBOW>, LedStripSetAnimationAction<LEDSTRIP_ANIMATION_TYPE_BETTERRAINBOW>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_SPEEDSYNCANIMATION>, LedStripSetAnimationAction<LEDSTRIP_ANIMATION_TYPE_SPEEDSYNCANIMATION>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_ANIMATION_CUSTOMCOLOR>, LedStripSetAnimationAction<LEDSTRIP_ANIMATION_TYPE_CUSTOMCOLOR>>>();
|
||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<LedstripMenu>, StaticMenuItemIcon<&espgui::icons::back>>>();
|
||||
}
|
||||
};
|
||||
|
@ -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<CRGB> 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
|
||||
|
@ -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";
|
||||
|
Reference in New Issue
Block a user