From 73c18fbb9e4b44c9acd9f85ec4a11ea38e1ca458 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChl?= <31169771+Blueforcer@users.noreply.github.com> Date: Mon, 10 Apr 2023 14:59:48 +0200 Subject: [PATCH] indicator blink --- docs/api.md | 17 +++++++++------- lib/MatrixUI/MatrixDisplayUi.cpp | 33 ++++++++++++++++++++++++++++---- lib/MatrixUI/MatrixDisplayUi.h | 5 +++++ src/DisplayManager.cpp | 23 ++++++++++++++++++++++ 4 files changed, 67 insertions(+), 11 deletions(-) diff --git a/docs/api.md b/docs/api.md index e197916..9b27a52 100644 --- a/docs/api.md +++ b/docs/api.md @@ -26,14 +26,17 @@ A colored indicator is like a small notification sign wich will be shown on the | `[PREFIX]/indicator1` | `http://[IP]/api/indicator1` | `{"color":[255,0,0]}` | POST | | `[PREFIX]/indicator2` | `http://[IP]/api/indicator2` | `{"color":[0,255,0]}` | POST | -Instead of a RGB array you can also sent HEX color strings like `{"color":"#32a852"}` - +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"}` to hide the indicators. +Optionally you can make the indicator blinking by adding the key `"blink":true/false`. + ## Custom Apps and Notifications With AWTRIX Light, you can create custom apps or notifications to display your own text and icons. -With MQTT simply send a JSON object to the topic `[PREFIX]/custom/[page]` where [page] is a the name of your page (without spaces). -With the [HTTP API](api?id=add-custom-app) you have to set the appname in the request header (`name = Appname`) - +With MQTT simply send a JSON object to the topic `[PREFIX]/custom/[app]` where [app] is a the name of your app (without spaces). +With the HTTP API you have to set the appname in the request header (`name = [appname]`) +You can also send a one-time notification with the same JSON format. Simply send your JSON object to `[PREFIX]/notify` or `http://[IP]/api/notify`. + | Topic | URL | Payload/Body | Query parameters | HTTP method | | --- | --- | --- | --- | --- | | `[PREFIX]/custom/[appname]` |`http://[IP]/api/custom` | JSON | name = [appname] | POST | @@ -56,14 +59,14 @@ The JSON object has the following properties: | `sound` | string | The filename of your RTTTL ringtone file (without extension). | | | `pushIcon` | number | 0 = Icon doesn't move. 1 = Icon moves with text and will not appear again. 2 = Icon moves with text but appears again when the text starts to scroll again. | 0 | | `bar` | array of integers | draws a bargraph. Without icon maximum 16 values, with icon 11 values | | -| `textCase` | integer | Changes the Uppercase setting. 0=global setting, 1=forces uppercase; 2=shows what is sent. | 0 | +| `textCase` | integer | Changes the Uppercase setting. 0=global setting, 1=forces uppercase; 2=shows as it sent. | 0 | All keys are optional, so you can send just the properties you want to use. To update a custom page, simply send a modified JSON object to the same topic. The display will be updated immediately. -You can also send a one-time notification with the same JSON format. Simply send your JSON object to "awtrixlight/notify". + ### Example diff --git a/lib/MatrixUI/MatrixDisplayUi.cpp b/lib/MatrixUI/MatrixDisplayUi.cpp index 4d63c48..f5f6db4 100644 --- a/lib/MatrixUI/MatrixDisplayUi.cpp +++ b/lib/MatrixUI/MatrixDisplayUi.cpp @@ -230,15 +230,30 @@ void MatrixDisplayUi::tick() this->drawIndicators(); this->matrix->show(); } + void MatrixDisplayUi::drawIndicators() { - if (indicator1State) + if (indicator1State && !indicator1Blink) { matrix->drawPixel(31, 0, indicator1Color); matrix->drawPixel(30, 0, indicator1Color); matrix->drawPixel(31, 1, indicator1Color); } - if (indicator2State) + if (indicator2State && !indicator2Blink) + { + matrix->drawPixel(31, 7, indicator2Color); + matrix->drawPixel(31, 6, indicator2Color); + matrix->drawPixel(30, 7, indicator2Color); + } + + if (indicator1State && indicator1Blink && (millis() % 1000) < 500) + { + matrix->drawPixel(31, 0, indicator1Color); + matrix->drawPixel(30, 0, indicator1Color); + matrix->drawPixel(31, 1, indicator1Color); + } + + if (indicator2State && indicator2Blink && (millis() % 1000) < 500) { matrix->drawPixel(31, 7, indicator2Color); matrix->drawPixel(31, 6, indicator2Color); @@ -313,7 +328,7 @@ uint8_t MatrixDisplayUi::getnextAppNumber() void MatrixDisplayUi::setIndicator1Color(uint16_t color) { - this->indicator1Color = color; + this->indicator1Color = color; } void MatrixDisplayUi::setIndicator1State(bool state) @@ -323,10 +338,20 @@ void MatrixDisplayUi::setIndicator1State(bool state) void MatrixDisplayUi::setIndicator2Color(uint16_t color) { - this->indicator2Color = color; + this->indicator2Color = color; } void MatrixDisplayUi::setIndicator2State(bool state) { this->indicator2State = state; +} + +void MatrixDisplayUi::setIndicator1Blink(bool blink) +{ + this->indicator1Blink = blink; +} + +void MatrixDisplayUi::setIndicator2Blink(bool blink) +{ + this->indicator2Blink = blink; } \ No newline at end of file diff --git a/lib/MatrixUI/MatrixDisplayUi.h b/lib/MatrixUI/MatrixDisplayUi.h index 1919ca4..76c6d95 100644 --- a/lib/MatrixUI/MatrixDisplayUi.h +++ b/lib/MatrixUI/MatrixDisplayUi.h @@ -106,6 +106,8 @@ private: bool indicator1State = false; bool indicator2State = false; + bool indicator1Blink = false; + bool indicator2Blink = false; uint8_t getnextAppNumber(); void drawApp(); @@ -158,6 +160,9 @@ public: void setIndicator2Color(uint16_t color); void setIndicator2State(bool state); + void setIndicator1Blink(bool Blink); + void setIndicator2Blink(bool Blink); + void drawIndicators(); // Customize indicator position and style diff --git a/src/DisplayManager.cpp b/src/DisplayManager.cpp index ad375e8..96685bf 100644 --- a/src/DisplayManager.cpp +++ b/src/DisplayManager.cpp @@ -1065,4 +1065,27 @@ void DisplayManager_::indicatorParser(uint8_t indicator, const char *json) } } } + + if (doc.containsKey("blink")) + { + if (indicator == 1) + { + ui->setIndicator1Blink(doc["blink"].as()); + } + else + { + ui->setIndicator2Blink(doc["blink"].as()); + } + } + else + { + if (indicator == 1) + { + ui->setIndicator1Blink(false); + } + else + { + ui->setIndicator2Blink(false); + } + } } \ No newline at end of file