indicator blink

This commit is contained in:
Stephan Mühl
2023-04-10 14:59:48 +02:00
parent 1447547e42
commit 73c18fbb9e
4 changed files with 67 additions and 11 deletions

View File

@@ -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]/indicator1` | `http://[IP]/api/indicator1` | `{"color":[255,0,0]}` | POST |
| `[PREFIX]/indicator2` | `http://[IP]/api/indicator2` | `{"color":[0,255,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 ## Custom Apps and Notifications
With AWTRIX Light, you can create custom apps or notifications to display your own text and icons. 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 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](api?id=add-custom-app) you have to set the appname in the request header (`name = Appname`) 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 | | Topic | URL | Payload/Body | Query parameters | HTTP method |
| --- | --- | --- | --- | --- | | --- | --- | --- | --- | --- |
| `[PREFIX]/custom/[appname]` |`http://[IP]/api/custom` | JSON | name = [appname] | POST | | `[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). | | | `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 | | `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 | | | `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. 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. 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 ### Example

View File

@@ -230,15 +230,30 @@ void MatrixDisplayUi::tick()
this->drawIndicators(); this->drawIndicators();
this->matrix->show(); this->matrix->show();
} }
void MatrixDisplayUi::drawIndicators() void MatrixDisplayUi::drawIndicators()
{ {
if (indicator1State) if (indicator1State && !indicator1Blink)
{ {
matrix->drawPixel(31, 0, indicator1Color); matrix->drawPixel(31, 0, indicator1Color);
matrix->drawPixel(30, 0, indicator1Color); matrix->drawPixel(30, 0, indicator1Color);
matrix->drawPixel(31, 1, 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, 7, indicator2Color);
matrix->drawPixel(31, 6, indicator2Color); matrix->drawPixel(31, 6, indicator2Color);
@@ -313,7 +328,7 @@ uint8_t MatrixDisplayUi::getnextAppNumber()
void MatrixDisplayUi::setIndicator1Color(uint16_t color) void MatrixDisplayUi::setIndicator1Color(uint16_t color)
{ {
this->indicator1Color = color; this->indicator1Color = color;
} }
void MatrixDisplayUi::setIndicator1State(bool state) void MatrixDisplayUi::setIndicator1State(bool state)
@@ -323,10 +338,20 @@ void MatrixDisplayUi::setIndicator1State(bool state)
void MatrixDisplayUi::setIndicator2Color(uint16_t color) void MatrixDisplayUi::setIndicator2Color(uint16_t color)
{ {
this->indicator2Color = color; this->indicator2Color = color;
} }
void MatrixDisplayUi::setIndicator2State(bool state) void MatrixDisplayUi::setIndicator2State(bool state)
{ {
this->indicator2State = state; this->indicator2State = state;
}
void MatrixDisplayUi::setIndicator1Blink(bool blink)
{
this->indicator1Blink = blink;
}
void MatrixDisplayUi::setIndicator2Blink(bool blink)
{
this->indicator2Blink = blink;
} }

View File

@@ -106,6 +106,8 @@ private:
bool indicator1State = false; bool indicator1State = false;
bool indicator2State = false; bool indicator2State = false;
bool indicator1Blink = false;
bool indicator2Blink = false;
uint8_t getnextAppNumber(); uint8_t getnextAppNumber();
void drawApp(); void drawApp();
@@ -158,6 +160,9 @@ public:
void setIndicator2Color(uint16_t color); void setIndicator2Color(uint16_t color);
void setIndicator2State(bool state); void setIndicator2State(bool state);
void setIndicator1Blink(bool Blink);
void setIndicator2Blink(bool Blink);
void drawIndicators(); void drawIndicators();
// Customize indicator position and style // Customize indicator position and style

View File

@@ -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<bool>());
}
else
{
ui->setIndicator2Blink(doc["blink"].as<bool>());
}
}
else
{
if (indicator == 1)
{
ui->setIndicator1Blink(false);
}
else
{
ui->setIndicator2Blink(false);
}
}
} }