add indicator lights
This commit is contained in:
@@ -223,7 +223,7 @@ void MatrixDisplayUi::tick()
|
||||
}
|
||||
|
||||
this->matrix->clear();
|
||||
|
||||
|
||||
if (this->AppCount > 0)
|
||||
this->drawApp();
|
||||
this->drawOverlays();
|
||||
@@ -311,16 +311,22 @@ uint8_t MatrixDisplayUi::getnextAppNumber()
|
||||
return (this->state.currentApp + this->AppCount + this->state.appTransitionDirection) % this->AppCount;
|
||||
}
|
||||
|
||||
void MatrixDisplayUi::setIndicator1(bool state, uint16_t color)
|
||||
void MatrixDisplayUi::setIndicator1Color(uint16_t color)
|
||||
{
|
||||
this->indicator1State = state;
|
||||
if (color > 0)
|
||||
this->indicator1Color = color;
|
||||
}
|
||||
|
||||
void MatrixDisplayUi::setIndicator2(bool state, uint16_t color)
|
||||
void MatrixDisplayUi::setIndicator1State(bool state)
|
||||
{
|
||||
this->indicator1State = state;
|
||||
}
|
||||
|
||||
void MatrixDisplayUi::setIndicator2Color(uint16_t color)
|
||||
{
|
||||
this->indicator2Color = color;
|
||||
}
|
||||
|
||||
void MatrixDisplayUi::setIndicator2State(bool state)
|
||||
{
|
||||
this->indicator2State = state;
|
||||
if (color > 0)
|
||||
this->indicator2Color = color;
|
||||
}
|
||||
@@ -153,8 +153,10 @@ public:
|
||||
*/
|
||||
void setTimePerTransition(uint16_t time);
|
||||
|
||||
void setIndicator1(bool state, uint16_t color);
|
||||
void setIndicator2(bool state, uint16_t color);
|
||||
void setIndicator1Color(uint16_t color);
|
||||
void setIndicator1State(bool state);
|
||||
void setIndicator2Color(uint16_t color);
|
||||
void setIndicator2State(bool state);
|
||||
|
||||
void drawIndicators();
|
||||
// Customize indicator position and style
|
||||
|
||||
@@ -56,7 +56,7 @@ void DisplayManager_::setBrightness(uint8_t bri)
|
||||
else
|
||||
{
|
||||
matrix->setBrightness(bri);
|
||||
//napplyGamma_video(&leds[256], 256, 2.2);
|
||||
// napplyGamma_video(&leds[256], 256, 2.2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -423,7 +423,7 @@ void DisplayManager_::generateNotification(const char *json)
|
||||
else
|
||||
{
|
||||
notify.barSize = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (doc.containsKey("color"))
|
||||
{
|
||||
@@ -475,7 +475,7 @@ void DisplayManager_::generateNotification(const char *json)
|
||||
}
|
||||
else
|
||||
{
|
||||
fs::File nullPointer;
|
||||
fs::File nullPointer;
|
||||
notify.icon = nullPointer;
|
||||
}
|
||||
}
|
||||
@@ -948,18 +948,20 @@ String DisplayManager_::getAppsAsJson()
|
||||
return json;
|
||||
}
|
||||
|
||||
|
||||
void DisplayManager_::onStateParse(const char *json)
|
||||
void DisplayManager_::powerStateParse(const char *json)
|
||||
{
|
||||
DynamicJsonDocument doc(512);
|
||||
DynamicJsonDocument doc(128);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error)
|
||||
return;
|
||||
bool state = doc["state"].as<bool>();
|
||||
onState(state);
|
||||
if (doc.containsKey("state"))
|
||||
{
|
||||
bool state = doc["state"].as<bool>();
|
||||
setPower(state);
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayManager_::onState(bool state)
|
||||
void DisplayManager_::setPower(bool state)
|
||||
{
|
||||
if (state)
|
||||
{
|
||||
@@ -974,13 +976,93 @@ void DisplayManager_::onState(bool state)
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayManager_::setIndicator1(bool state, uint16_t color)
|
||||
void DisplayManager_::setIndicator1Color(uint16_t color)
|
||||
{
|
||||
ui->setIndicator1(state, color);
|
||||
ui->setIndicator1Color(color);
|
||||
}
|
||||
|
||||
void DisplayManager_::setIndicator2(bool state, uint16_t color)
|
||||
void DisplayManager_::setIndicator1State(bool state)
|
||||
{
|
||||
ui->setIndicator2(state, color);
|
||||
ui->setIndicator1State(state);
|
||||
}
|
||||
|
||||
void DisplayManager_::setIndicator2Color(uint16_t color)
|
||||
{
|
||||
ui->setIndicator2Color(color);
|
||||
}
|
||||
|
||||
void DisplayManager_::setIndicator2State(bool state)
|
||||
{
|
||||
ui->setIndicator2State(state);
|
||||
}
|
||||
|
||||
void DisplayManager_::indicatorParser(uint8_t indicator, const char *json)
|
||||
{
|
||||
DynamicJsonDocument doc(128);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error)
|
||||
return;
|
||||
if (doc.containsKey("color"))
|
||||
{
|
||||
auto color = doc["color"];
|
||||
if (color.is<String>())
|
||||
{
|
||||
uint16_t col = hexToRgb565(color.as<String>());
|
||||
if (col > 0)
|
||||
{
|
||||
if (indicator == 1)
|
||||
{
|
||||
ui->setIndicator1State(true);
|
||||
ui->setIndicator1Color(col);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->setIndicator2State(true);
|
||||
ui->setIndicator2Color(col);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (indicator == 1)
|
||||
{
|
||||
ui->setIndicator1State(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->setIndicator2State(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (color.is<JsonArray>() && color.size() == 3)
|
||||
{
|
||||
uint8_t r = color[0];
|
||||
uint8_t g = color[1];
|
||||
uint8_t b = color[2];
|
||||
|
||||
if (r == 0 && g == 0 && b == 0)
|
||||
{
|
||||
if (indicator == 1)
|
||||
{
|
||||
ui->setIndicator1State(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->setIndicator2State(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (indicator == 1)
|
||||
{
|
||||
ui->setIndicator1State(true);
|
||||
ui->setIndicator1Color((r << 11) | (g << 5) | b);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->setIndicator2State(true);
|
||||
ui->setIndicator2Color((r << 11) | (g << 5) | b);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,6 @@ public:
|
||||
bool setAutoTransition(bool active);
|
||||
void switchToApp(const char *json);
|
||||
void setNewSettings(const char *json);
|
||||
void drawGIF(uint16_t x, uint16_t y, fs::File gifFile);
|
||||
void drawJPG(uint16_t x, uint16_t y, fs::File jpgFile);
|
||||
void drawProgressBar(int cur, int total);
|
||||
void drawMenuIndicator(int cur, int total, uint16_t color);
|
||||
@@ -66,13 +65,13 @@ public:
|
||||
void setAppTime(uint16_t duration);
|
||||
String getAppsAsJson();
|
||||
String getStat();
|
||||
|
||||
void onState(bool state);
|
||||
void onStateParse(const char *json);
|
||||
|
||||
void setIndicator1(bool state, uint16_t color);
|
||||
void setIndicator2(bool state, uint16_t color);
|
||||
|
||||
void setPower(bool state);
|
||||
void powerStateParse(const char *json);
|
||||
void setIndicator1Color(uint16_t color);
|
||||
void setIndicator1State(bool state);
|
||||
void setIndicator2Color(uint16_t color);
|
||||
void setIndicator2State(bool state);
|
||||
void indicatorParser(uint8_t indicator, const char *json);
|
||||
};
|
||||
|
||||
extern DisplayManager_ &DisplayManager;
|
||||
|
||||
@@ -109,11 +109,11 @@ void onRGBColorCommand(HALight::RGBColor color, HALight *sender)
|
||||
}
|
||||
else if (sender == Indikator1)
|
||||
{
|
||||
DisplayManager.setIndicator1(true, ((color.red & 0x1F) << 11) | ((color.green & 0x3F) << 5) | (color.blue & 0x1F));
|
||||
DisplayManager.setIndicator1Color(((color.red & 0x1F) << 11) | ((color.green & 0x3F) << 5) | (color.blue & 0x1F));
|
||||
}
|
||||
else if (sender == Indikator2)
|
||||
{
|
||||
DisplayManager.setIndicator2(true, ((color.red & 0x1F) << 11) | ((color.green & 0x3F) << 5) | (color.blue & 0x1F));
|
||||
DisplayManager.setIndicator2Color(((color.red & 0x1F) << 11) | ((color.green & 0x3F) << 5) | (color.blue & 0x1F));
|
||||
}
|
||||
sender->setRGBColor(color); // report color back to the Home Assistant
|
||||
}
|
||||
@@ -122,15 +122,15 @@ void onStateCommand(bool state, HALight *sender)
|
||||
{
|
||||
if (sender == Matrix)
|
||||
{
|
||||
DisplayManager.onState(state);
|
||||
DisplayManager.setPower(state);
|
||||
}
|
||||
else if (sender == Indikator1)
|
||||
{
|
||||
DisplayManager.setIndicator1(state, 0);
|
||||
DisplayManager.setIndicator1State(state);
|
||||
}
|
||||
else if (sender == Indikator2)
|
||||
{
|
||||
DisplayManager.setIndicator2(state, 0);
|
||||
DisplayManager.setIndicator2State(state);
|
||||
}
|
||||
sender->setState(state);
|
||||
}
|
||||
@@ -219,10 +219,21 @@ void onMqttMessage(const char *topic, const uint8_t *payload, uint16_t length)
|
||||
delete[] payloadCopy;
|
||||
return;
|
||||
}
|
||||
if (strTopic.equals(MQTT_PREFIX + "/onstate"))
|
||||
if (strTopic.equals(MQTT_PREFIX + "/power"))
|
||||
{
|
||||
DisplayManager.onStateParse(payloadCopy);
|
||||
Serial.println(payloadCopy);
|
||||
DisplayManager.powerStateParse(payloadCopy);
|
||||
delete[] payloadCopy;
|
||||
return;
|
||||
}
|
||||
if (strTopic.equals(MQTT_PREFIX + "/indicator1"))
|
||||
{
|
||||
DisplayManager.indicatorParser(1, payloadCopy);
|
||||
delete[] payloadCopy;
|
||||
return;
|
||||
}
|
||||
if (strTopic.equals(MQTT_PREFIX + "/indicator2"))
|
||||
{
|
||||
DisplayManager.indicatorParser(2, payloadCopy);
|
||||
delete[] payloadCopy;
|
||||
return;
|
||||
}
|
||||
@@ -257,7 +268,9 @@ void onMqttConnected()
|
||||
"/doupdate",
|
||||
"/nextapp",
|
||||
"/apps",
|
||||
"/onstate"};
|
||||
"/power",
|
||||
"/indicator1",
|
||||
"/indicator2"};
|
||||
for (const char *topic : topics)
|
||||
{
|
||||
String fullTopic = prefix + topic;
|
||||
|
||||
@@ -99,11 +99,15 @@ void ServerManager_::setup()
|
||||
{ DisplayManager.generateCustomPage(mws.webserver->arg("name"),mws.webserver->arg("plain").c_str()); mws.webserver->send(200,"OK"); });
|
||||
mws.addHandler("/api/stats", HTTP_GET, []()
|
||||
{ mws.webserver->sendContent(DisplayManager.getStat()); });
|
||||
mws.addHandler("/api/indicator1", HTTP_POST, []()
|
||||
{ DisplayManager.indicatorParser(1,mws.webserver->arg("plain").c_str()); mws.webserver->send(200,"OK"); });
|
||||
mws.addHandler("/api/indicator2", HTTP_POST, []()
|
||||
{ DisplayManager.indicatorParser(2,mws.webserver->arg("plain").c_str()); mws.webserver->send(200,"OK"); });
|
||||
mws.addHandler("/api/doupdate", HTTP_POST, []()
|
||||
{ if (UPDATE_AVAILABLE)
|
||||
UpdateManager.updateFirmware(); mws.webserver->send(200,"OK"); });
|
||||
mws.addHandler("/api/onstate", HTTP_POST, []()
|
||||
{ DisplayManager.onStateParse(mws.webserver->arg("plain").c_str()); mws.webserver->send(200,"OK"); });
|
||||
mws.addHandler("/api/power", HTTP_POST, []()
|
||||
{ DisplayManager.powerStateParse(mws.webserver->arg("plain").c_str()); mws.webserver->send(200,"OK"); });
|
||||
Serial.println("Webserver loaded");
|
||||
}
|
||||
mws.addHandler("/version", HTTP_GET, versionHandler);
|
||||
|
||||
Reference in New Issue
Block a user