mirror of
https://github.com/Lemonochrme/clover.git
synced 2025-06-08 16:50:50 +02:00
HotFix LedComponent: Inverted Green and Blue channels. Added LedNumber Enumeration. setColor() now calls this enum.
This commit is contained in:
parent
8b610a9dcc
commit
0972097733
5 changed files with 21 additions and 18 deletions
|
@ -23,24 +23,20 @@ void LedComponent::setup()
|
||||||
_led = new ChainableLED(_pinClock, _pin, _ledNumber);
|
_led = new ChainableLED(_pinClock, _pin, _ledNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LedComponent::setColor(uint8_t led_number, Color color)
|
void LedComponent::setColor(LedNumber led_number, Color color)
|
||||||
{
|
{
|
||||||
if (led_number >= _ledNumber)
|
_led->setColorRGB(static_cast<byte>(led_number), color.red, color.green, color.blue);
|
||||||
return;
|
|
||||||
_led->setColorRGB(led_number, color.red, color.green, color.blue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LedComponent::setColor(uint8_t led_number, Color color, uint16_t fading_time)
|
void LedComponent::setColor(LedNumber led_number, Color color, uint16_t fading_time)
|
||||||
{
|
{
|
||||||
if (led_number >= _ledNumber)
|
|
||||||
return;
|
|
||||||
const auto redFade = color.red / (static_cast<float>(fading_time));
|
const auto redFade = color.red / (static_cast<float>(fading_time));
|
||||||
const auto greenFade = color.green / (static_cast<float>(fading_time));
|
const auto greenFade = color.green / (static_cast<float>(fading_time));
|
||||||
const auto blueFade = color.blue / (static_cast<float>(fading_time));
|
const auto blueFade = color.blue / (static_cast<float>(fading_time));
|
||||||
|
|
||||||
for (uint16_t time(0); time < fading_time; time++)
|
for (uint16_t time(0); time < fading_time; time++)
|
||||||
{
|
{
|
||||||
_led->setColorRGB(led_number, static_cast<byte>(redFade * time), static_cast<byte>(greenFade * time), static_cast<byte>(blueFade * time));
|
_led->setColorRGB(static_cast<byte>(led_number), static_cast<byte>(redFade * time), static_cast<byte>(greenFade * time), static_cast<byte>(blueFade * time));
|
||||||
delay(1);
|
delay(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,8 +6,8 @@
|
||||||
struct Color
|
struct Color
|
||||||
{
|
{
|
||||||
byte red;
|
byte red;
|
||||||
byte blue;
|
|
||||||
byte green;
|
byte green;
|
||||||
|
byte blue;
|
||||||
|
|
||||||
Color operator-(byte value);
|
Color operator-(byte value);
|
||||||
};
|
};
|
||||||
|
@ -17,16 +17,23 @@ namespace LedColors
|
||||||
constexpr Color LED_OFF = {0,0,0};
|
constexpr Color LED_OFF = {0,0,0};
|
||||||
constexpr Color WIFI_ON = {0x18,0x28,0x36};
|
constexpr Color WIFI_ON = {0x18,0x28,0x36};
|
||||||
constexpr Color NO_WIFI = {0x64,0x04,0x0B};
|
constexpr Color NO_WIFI = {0x64,0x04,0x0B};
|
||||||
|
constexpr Color TOO_DRY = {0xB3,0x58,0x1B};
|
||||||
|
constexpr Color TOO_WET = {0x1B,0x09,0x3F};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum class LedNumber {
|
||||||
|
LED_HARDWARE = 0,
|
||||||
|
LED_PLANT = 1
|
||||||
|
};
|
||||||
|
|
||||||
class LedComponent
|
class LedComponent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LedComponent(byte pin, byte pin_clock, uint8_t led_number);
|
LedComponent(byte pin, byte pin_clock, uint8_t led_number);
|
||||||
~LedComponent();
|
~LedComponent();
|
||||||
void setup();
|
void setup();
|
||||||
void setColor(uint8_t led_number, Color color);
|
void setColor(LedNumber led_number, Color color);
|
||||||
void setColor(uint8_t led_number, Color color, uint16_t fading_time);
|
void setColor(LedNumber led_number, Color color, uint16_t fading_time);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
byte _pin;
|
byte _pin;
|
||||||
|
|
|
@ -13,8 +13,8 @@ void MainComponent::setup()
|
||||||
_led.setup();
|
_led.setup();
|
||||||
_dht.setup();
|
_dht.setup();
|
||||||
// Lights are off when powered
|
// Lights are off when powered
|
||||||
_led.setColor(0,{0,0,0});
|
_led.setColor(LedNumber::LED_HARDWARE,{0,0,0});
|
||||||
_led.setColor(1,{0,0,0});
|
_led.setColor(LedNumber::LED_PLANT,{0,0,0});
|
||||||
}
|
}
|
||||||
|
|
||||||
Component& MainComponent::getHumidity() { return _humidity; }
|
Component& MainComponent::getHumidity() { return _humidity; }
|
||||||
|
|
|
@ -131,7 +131,7 @@ void Screen::boot()
|
||||||
|
|
||||||
// Shutting down led when finished booting
|
// Shutting down led when finished booting
|
||||||
if(_bootFrame == MAX_BOOT_FRAMES)
|
if(_bootFrame == MAX_BOOT_FRAMES)
|
||||||
MainComponent::GetInstance().getLed().setColor(0,LedColors::LED_OFF);
|
MainComponent::GetInstance().getLed().setColor(LedNumber::LED_HARDWARE,LedColors::LED_OFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen::loop(const float plantHumidity, const float airTemperature, const float airHumidity)
|
void Screen::loop(const float plantHumidity, const float airTemperature, const float airHumidity)
|
||||||
|
|
|
@ -5,9 +5,9 @@
|
||||||
|
|
||||||
inline void led_blink(LedComponent& led)
|
inline void led_blink(LedComponent& led)
|
||||||
{
|
{
|
||||||
led.setColor(0,LedColors::WIFI_ON);
|
led.setColor(LedNumber::LED_HARDWARE,LedColors::WIFI_ON);
|
||||||
delay(50);
|
delay(50);
|
||||||
led.setColor(0,LedColors::LED_OFF);
|
led.setColor(LedNumber::LED_HARDWARE,LedColors::LED_OFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerHandler::ServerHandler() : server(80), display_time(0), _connected(false)
|
ServerHandler::ServerHandler() : server(80), display_time(0), _connected(false)
|
||||||
|
@ -40,13 +40,13 @@ void ServerHandler::setup(const char *ssid, const char *password)
|
||||||
{
|
{
|
||||||
_connected = true;
|
_connected = true;
|
||||||
auto color = LedColors::WIFI_ON;
|
auto color = LedColors::WIFI_ON;
|
||||||
led.setColor(0,color-15,200);
|
led.setColor(LedNumber::LED_HARDWARE,color-15,200);
|
||||||
server.begin();
|
server.begin();
|
||||||
server.on("/", [this]()
|
server.on("/", [this]()
|
||||||
{ this->handleRoot(); }); // fonction lamda pour gérer les requettes get
|
{ this->handleRoot(); }); // fonction lamda pour gérer les requettes get
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
led.setColor(0,LedColors::NO_WIFI,200);
|
led.setColor(LedNumber::LED_HARDWARE,LedColors::NO_WIFI,200);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue