From 19809add5feddce181a48c8546201fe82444d089 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChl?= <31169771+Blueforcer@users.noreply.github.com> Date: Tue, 16 May 2023 15:23:03 +0200 Subject: [PATCH] V0.63 - Adds third indicator (indeicator 2 is now in the middle) - Fixes a bug where the Eyes app wasnt reported --- docs/api.md | 3 +- src/Apps.h | 2 + src/Dictionary.cpp | 6 ++- src/Dictionary.h | 4 ++ src/DisplayManager.cpp | 86 ++++++++++++++++++++++++++++++----------- src/DisplayManager.h | 2 + src/Globals.cpp | 2 +- src/LookingEyes.h | 2 +- src/MQTTManager.cpp | 41 +++++++++++++++++++- src/MatrixDisplayUi.cpp | 63 ++++++++++++++++++++++-------- src/MatrixDisplayUi.h | 13 ++++++- 11 files changed, 178 insertions(+), 46 deletions(-) diff --git a/docs/api.md b/docs/api.md index 9eebd33d..be2dd1fe 100644 --- a/docs/api.md +++ b/docs/api.md @@ -45,12 +45,13 @@ or ## Colored indicators -A colored indicator is like a small notification sign wich will be shown on the upper right or lower right corner. +A colored indicator is like a small notification sign wich will be shown on the upper right (1), right side (2) and lower right corner (3). | Topic | URL | Payload/Body | HTTP method | | --- | --- | --- | --- | | `[PREFIX]/indicator1` | `http://[IP]/api/indicator1` | `{"color":[255,0,0]}` | POST | | `[PREFIX]/indicator2` | `http://[IP]/api/indicator2` | `{"color":[0,255,0]}` | POST | +| `[PREFIX]/indicator3` | `http://[IP]/api/indicator3` | `{"color":[0,255,0]}` | POST | Instead of a RGB array you can also sent HEX color strings like `{"color":"#32a852"}` Send the color black `{"color":[0,0,0]}` or `{"color":"0"}` or a empty payload/body to hide the indicators. diff --git a/src/Apps.h b/src/Apps.h index 961a9d13..80c13191 100644 --- a/src/Apps.h +++ b/src/Apps.h @@ -588,6 +588,8 @@ void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState static unsigned long lastTime = 0; void EyesApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame, GifPlayer *gifPlayer) { + + CURRENT_APP = "Eyes"; if (blinkCountdown < sizeof(blinkIndex) / sizeof(blinkIndex[0]) - 1) { matrix->drawRGBBitmap(6 + x, 0 + y, eye[blinkIndex[blinkCountdown]], 8, 8); diff --git a/src/Dictionary.cpp b/src/Dictionary.cpp index aaf726dc..ac823b1f 100644 --- a/src/Dictionary.cpp +++ b/src/Dictionary.cpp @@ -23,9 +23,13 @@ const char HAi1Icon[] PROGMEM = {"mdi:arrow-top-right-thick"}; const char HAi1Name[] PROGMEM = {"Indicator 1"}; const char HAi2ID[] PROGMEM = {"%s_ind2"}; -const char HAi2Icon[] PROGMEM = {"mdi:arrow-bottom-right-thick"}; +const char HAi2Icon[] PROGMEM = {"mdi:arrow-right-thick"}; const char HAi2Name[] PROGMEM = {"Indicator 2"}; +const char HAi3ID[] PROGMEM = {"%s_ind3"}; +const char HAi3Icon[] PROGMEM = {"mdi:arrow-bottom-right-thick"}; +const char HAi3Name[] PROGMEM = {"Indicator 3"}; + const char HAbriID[] PROGMEM = {"%s_bri"}; const char HAbriIcon[] PROGMEM = {"mdi:brightness-auto"}; const char HAbriName[] PROGMEM = {"Brightness mode"}; diff --git a/src/Dictionary.h b/src/Dictionary.h index 7d1fafe4..01c5ceff 100644 --- a/src/Dictionary.h +++ b/src/Dictionary.h @@ -26,6 +26,10 @@ extern const char HAi2ID[]; extern const char HAi2Icon[]; extern const char HAi2Name[]; +extern const char HAi3ID[]; +extern const char HAi3Icon[]; +extern const char HAi3Name[]; + extern const char HAbriID[]; extern const char HAbriIcon[]; extern const char HAbriName[]; diff --git a/src/DisplayManager.cpp b/src/DisplayManager.cpp index 04c4deb3..9f77a273 100644 --- a/src/DisplayManager.cpp +++ b/src/DisplayManager.cpp @@ -1432,6 +1432,7 @@ void DisplayManager_::setIndicator1State(bool state) ui->setIndicator1State(state); } + void DisplayManager_::setIndicator2Color(uint16_t color) { ui->setIndicator2Color(color); @@ -1442,20 +1443,37 @@ void DisplayManager_::setIndicator2State(bool state) ui->setIndicator2State(state); } +void DisplayManager_::setIndicator3Color(uint16_t color) +{ + ui->setIndicator3Color(color); +} + +void DisplayManager_::setIndicator3State(bool state) +{ + ui->setIndicator3State(state); +} + void DisplayManager_::indicatorParser(uint8_t indicator, const char *json) { if (strcmp(json, "") == 0) { - if (indicator == 1) + switch (indicator) { + case 1: ui->setIndicator1State(false); MQTTManager.setIndicatorState(1, ui->indicator1State, ui->indicator1Color); - } - else - { + break; + case 2: ui->setIndicator2State(false); MQTTManager.setIndicatorState(2, ui->indicator2State, ui->indicator2Color); + break; + case 3: + ui->setIndicator3State(false); + MQTTManager.setIndicatorState(3, ui->indicator3State, ui->indicator3Color); + break; + default: + break; } return; } @@ -1473,54 +1491,78 @@ void DisplayManager_::indicatorParser(uint8_t indicator, const char *json) if (col > 0) { - if (indicator == 1) + switch (indicator) { + case 1: ui->setIndicator1State(true); ui->setIndicator1Color(col); - } - else - { + break; + case 2: ui->setIndicator2State(true); ui->setIndicator2Color(col); + break; + case 3: + ui->setIndicator3State(true); + ui->setIndicator3Color(col); + break; + default: + break; } } else { - if (indicator == 1) + switch (indicator) { + case 1: ui->setIndicator1State(false); - } - else - { + break; + case 2: ui->setIndicator2State(false); + break; + case 3: + ui->setIndicator3State(false); + break; + default: + break; } } } if (doc.containsKey("blink")) { - if (indicator == 1) + switch (indicator) { + case 1: ui->setIndicator1Blink(doc["blink"].as()); - } - else - { + break; + case 2: ui->setIndicator2Blink(doc["blink"].as()); + break; + case 3: + ui->setIndicator3Blink(doc["blink"].as()); + break; + default: + break; } } else { - if (indicator == 1) + switch (indicator) { + case 1: ui->setIndicator1Blink(0); - } - else - { + break; + case 2: ui->setIndicator2Blink(0); + break; + case 3: + ui->setIndicator3Blink(0); + break; + default: + break; } } - MQTTManager.setIndicatorState(1, ui->indicator1State, ui->indicator1Color); - // MQTTManager.setIndicatorState(2, ui->indicator2State, ui->indicator2Color); + MQTTManager.setIndicatorState(indicator, ui->indicator1State, ui->indicator1Color); } void DisplayManager_::gammaCorrection() diff --git a/src/DisplayManager.h b/src/DisplayManager.h index 5624901a..f19d5425 100644 --- a/src/DisplayManager.h +++ b/src/DisplayManager.h @@ -74,6 +74,8 @@ class DisplayManager_ void setIndicator1State(bool state); void setIndicator2Color(uint16_t color); void setIndicator2State(bool state); + void setIndicator3Color(uint16_t color); + void setIndicator3State(bool state); void reorderApps(const String &jsonString); void gammaCorrection(); void indicatorParser(uint8_t indicator, const char *json); diff --git a/src/Globals.cpp b/src/Globals.cpp index fc3dbc86..d61976c4 100644 --- a/src/Globals.cpp +++ b/src/Globals.cpp @@ -216,7 +216,7 @@ IPAddress gateway; IPAddress subnet; IPAddress primaryDNS; IPAddress secondaryDNS; -const char *VERSION = "0.62"; +const char *VERSION = "0.63"; String MQTT_HOST = ""; uint16_t MQTT_PORT = 1883; diff --git a/src/LookingEyes.h b/src/LookingEyes.h index 6f4b43d6..62a90791 100644 --- a/src/LookingEyes.h +++ b/src/LookingEyes.h @@ -10,7 +10,7 @@ int newX = 9; int newY = 3; int dX = 6; int dY = 0; -int PET_MOOD = 2; +int PET_MOOD = 0; uint16_t eye[5][64] = { {0, 0, 65535, 65535, 65535, 65535, 0, 0, 0, 65535, 65535, 65535, 65535, 65535, 65535, 0, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 0, 65535, 65535, 65535, 65535, 65535, 65535, 0, 0, 0, 65535, 65535, 65535, 65535, 0, 0}, diff --git a/src/MQTTManager.cpp b/src/MQTTManager.cpp index acd4a4e9..5fa1d352 100644 --- a/src/MQTTManager.cpp +++ b/src/MQTTManager.cpp @@ -13,7 +13,7 @@ WiFiClient espClient; HADevice device; HAMqtt mqtt(espClient, device, 25); -HALight *Matrix, *Indikator1, *Indikator2 = nullptr; +HALight *Matrix, *Indikator1, *Indikator2, *Indikator3 = nullptr; HASelect *BriMode = nullptr; HAButton *dismiss, *nextApp, *prevApp, *doUpdate = nullptr; HASwitch *transition = nullptr; @@ -23,7 +23,7 @@ HASensor *battery = nullptr; HASensor *temperature, *humidity, *illuminance, *uptime, *strength, *version, *ram, *curApp = nullptr; HABinarySensor *btnleft, *btnmid, *btnright = nullptr; -char matID[40], ind1ID[40], ind2ID[40], briID[40], btnAID[40], btnBID[40], btnCID[40], appID[40], tempID[40], humID[40], luxID[40], verID[40], ramID[40], upID[40], sigID[40], btnLID[40], btnMID[40], btnRID[40], transID[40], doUpdateID[40], batID[40]; +char matID[40], ind1ID[40], ind2ID[40], ind3ID[40], briID[40], btnAID[40], btnBID[40], btnCID[40], appID[40], tempID[40], humID[40], luxID[40], verID[40], ramID[40], upID[40], sigID[40], btnLID[40], btnMID[40], btnRID[40], transID[40], doUpdateID[40], batID[40]; // The getter for the instantiated singleton instance MQTTManager_ &MQTTManager_::getInstance() @@ -97,6 +97,10 @@ void onRGBColorCommand(HALight::RGBColor color, HALight *sender) { DisplayManager.setIndicator2Color(((color.red & 0x1F) << 11) | ((color.green & 0x3F) << 5) | (color.blue & 0x1F)); } + else if (sender == Indikator3) + { + DisplayManager.setIndicator3Color(((color.red & 0x1F) << 11) | ((color.green & 0x3F) << 5) | (color.blue & 0x1F)); + } sender->setRGBColor(color); // report color back to the Home Assistant } @@ -109,11 +113,17 @@ void onStateCommand(bool state, HALight *sender) else if (sender == Indikator1) { DisplayManager.setIndicator1State(state); + Serial.println("I1"); } else if (sender == Indikator2) { DisplayManager.setIndicator2State(state); } + else if (sender == Indikator3) + { + Serial.println("I3"); + DisplayManager.setIndicator3State(state); + } sender->setState(state); } @@ -196,6 +206,7 @@ void onMqttMessage(const char *topic, const uint8_t *payload, uint16_t length) delete[] payloadCopy; return; } + if (strTopic.equals(MQTT_PREFIX + "/doupdate")) { if (UpdateManager.checkUpdate(true)) @@ -205,6 +216,7 @@ void onMqttMessage(const char *topic, const uint8_t *payload, uint16_t length) delete[] payloadCopy; return; } + if (strTopic.equals(MQTT_PREFIX + "/power")) { StaticJsonDocument<128> doc; @@ -222,24 +234,35 @@ void onMqttMessage(const char *topic, const uint8_t *payload, uint16_t length) 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; } + + if (strTopic.equals(MQTT_PREFIX + "/indicator3")) + { + DisplayManager.indicatorParser(3, payloadCopy); + delete[] payloadCopy; + return; + } + if (strTopic.equals(MQTT_PREFIX + "/moodlight")) { DisplayManager.moodlight(payloadCopy); delete[] payloadCopy; return; } + if (strTopic.equals(MQTT_PREFIX + "/reboot")) { DEBUG_PRINTLN("REBOOT COMMAND RECEIVED") @@ -248,12 +271,14 @@ void onMqttMessage(const char *topic, const uint8_t *payload, uint16_t length) delete[] payloadCopy; return; } + if (strTopic.equals(MQTT_PREFIX + "/sound")) { PeripheryManager.parseSound(payloadCopy); delete[] payloadCopy; return; } + if (strTopic.startsWith(MQTT_PREFIX + "/custom")) { String topic_str = topic; @@ -290,6 +315,7 @@ void onMqttConnected() "/power", "/indicator1", "/indicator2", + "/indicator3", "/timeformat", "/dateformat", "/reboot", @@ -378,6 +404,13 @@ void MQTTManager_::setup() Indikator2->onStateCommand(onStateCommand); Indikator2->onRGBColorCommand(onRGBColorCommand); + sprintf(ind3ID, HAi3ID, macStr); + Indikator3 = new HALight(ind3ID, HALight::RGBFeature); + Indikator3->setIcon(HAi3Icon); + Indikator3->setName(HAi3Name); + Indikator3->onStateCommand(onStateCommand); + Indikator3->onRGBColorCommand(onRGBColorCommand); + sprintf(briID, HAbriID, macStr); BriMode = new HASelect(briID); BriMode->setOptions(HAbriOptions); @@ -641,6 +674,10 @@ void MQTTManager_::setIndicatorState(uint8_t indicator, bool state, uint16_t col Indikator2->setRGBColor(c); Indikator2->setState(state); break; + case 3: + Indikator3->setRGBColor(c); + Indikator3->setState(state); + break; default: break; } diff --git a/src/MatrixDisplayUi.cpp b/src/MatrixDisplayUi.cpp index 24931578..a4d9eb45 100644 --- a/src/MatrixDisplayUi.cpp +++ b/src/MatrixDisplayUi.cpp @@ -236,35 +236,47 @@ void MatrixDisplayUi::tick() void MatrixDisplayUi::drawIndicators() { - if (indicator1State && !indicator1Blink) + + if (indicator1State && indicator1Blink && (millis() % (2 * indicator1Blink)) < indicator1Blink) { matrix->drawPixel(31, 0, indicator1Color); matrix->drawPixel(30, 0, indicator1Color); matrix->drawPixel(31, 1, indicator1Color); } - - if (indicator2State && !indicator2Blink) + + if (indicator2State && indicator2Blink && (millis() % (2 * indicator2Blink)) < indicator2Blink) { - matrix->drawPixel(31, 7, indicator2Color); - matrix->drawPixel(31, 6, indicator2Color); - matrix->drawPixel(30, 7, indicator2Color); + matrix->drawPixel(31, 3, indicator2Color); + matrix->drawPixel(31, 4, indicator2Color); } - if (indicator1State && indicator1Blink && (millis() % (2 * indicator1Blink)) < indicator1Blink) + if (indicator3State && indicator3Blink && (millis() % (2 * indicator3Blink)) < indicator3Blink) + { + matrix->drawPixel(31, 7, indicator3Color); + matrix->drawPixel(31, 6, indicator3Color); + matrix->drawPixel(30, 7, indicator3Color); + } + + if (indicator1State && !indicator1Blink) { matrix->drawPixel(31, 0, indicator1Color); matrix->drawPixel(30, 0, indicator1Color); matrix->drawPixel(31, 1, indicator1Color); } - if (indicator2State && indicator2Blink && (millis() % (2 * indicator2Blink)) < indicator2Blink) + if (indicator2State && !indicator2Blink) { - matrix->drawPixel(31, 7, indicator2Color); - matrix->drawPixel(31, 6, indicator2Color); - matrix->drawPixel(30, 7, indicator2Color); + matrix->drawPixel(31, 3, indicator2Color); + matrix->drawPixel(31, 4, indicator2Color); } -} + if (indicator3State && !indicator3Blink) + { + matrix->drawPixel(31, 7, indicator3Color); + matrix->drawPixel(31, 6, indicator3Color); + matrix->drawPixel(30, 7, indicator3Color); + } +} void MatrixDisplayUi::drawApp() { @@ -364,6 +376,13 @@ void MatrixDisplayUi::setIndicator1State(bool state) this->indicator1State = state; } +void MatrixDisplayUi::setIndicator1Blink(int blink) +{ + this->indicator1Blink = blink; +} + + + void MatrixDisplayUi::setIndicator2Color(uint16_t color) { this->indicator2Color = color; @@ -374,12 +393,24 @@ void MatrixDisplayUi::setIndicator2State(bool state) this->indicator2State = state; } -void MatrixDisplayUi::setIndicator1Blink(int blink) +void MatrixDisplayUi::setIndicator2Blink(int blink) { - this->indicator1Blink = blink; + this->indicator2Blink = blink; } -void MatrixDisplayUi::setIndicator2Blink(int blink) + + +void MatrixDisplayUi::setIndicator3Color(uint16_t color) { - this->indicator2Blink = blink; + this->indicator3Color = color; +} + +void MatrixDisplayUi::setIndicator3State(bool state) +{ + this->indicator3State = state; +} + +void MatrixDisplayUi::setIndicator3Blink(int blink) +{ + this->indicator3Blink = blink; } diff --git a/src/MatrixDisplayUi.h b/src/MatrixDisplayUi.h index c60db32c..a370cd2e 100644 --- a/src/MatrixDisplayUi.h +++ b/src/MatrixDisplayUi.h @@ -149,12 +149,16 @@ class MatrixDisplayUi void setIndicator1Color(uint16_t color); void setIndicator1State(bool state); + void setIndicator1Blink(int Blink); + void setIndicator2Color(uint16_t color); void setIndicator2State(bool state); - - void setIndicator1Blink(int Blink); void setIndicator2Blink(int Blink); + void setIndicator3Color(uint16_t color); + void setIndicator3State(bool state); + void setIndicator3Blink(int Blink); + void drawIndicators(); // Customize indicator position and style @@ -199,9 +203,14 @@ class MatrixDisplayUi uint16_t indicator1Color = 63488; uint16_t indicator2Color = 31; + uint16_t indicator3Color = 65504; + bool indicator1State = false; bool indicator2State = false; + bool indicator3State = false; + int indicator1Blink = 0; int indicator2Blink = 0; + int indicator3Blink = 0; }; #endif