From 8646eb4ac14ae37f7f229b7654952b3a21e949fe Mon Sep 17 00:00:00 2001 From: Stephan <31169771+Blueforcer@users.noreply.github.com> Date: Tue, 28 Nov 2023 22:36:29 +0100 Subject: [PATCH] v0.91 - Allows to set a http callback for button presses via dev.json. - You can send a 8x8 jpg icon as base64 string. - Applies gamma correction to brightness control - IP adress was added to stats - Fixes a bug where duration wasnt reset after custom app deletion. closes #407 - Indicator fading and blinking options are now disabled after deactivation. closes #402 - Awtrix sends the stats only after the first full sensor reading to avoid zero numbers after boot. closes #391 - Uptime reading now handles the millis() overflow to calculate longer uptime than 49days - fixes some minor bugs --- docs/api.md | 2 +- docs/dev.md | 3 ++- src/Globals.cpp | 2 +- src/MQTTManager.cpp | 3 +-- src/PeripheryManager.cpp | 17 ++++++++++++++--- src/PeripheryManager.h | 2 +- 6 files changed, 20 insertions(+), 9 deletions(-) diff --git a/docs/api.md b/docs/api.md index e7b4f867..8e69cd5f 100644 --- a/docs/api.md +++ b/docs/api.md @@ -180,7 +180,7 @@ Below are the properties you can utilize in the JSON object. **All keys are opti | `fadeText` | Integer | Fades the text on and off in an given interval, not compatible with gradient or rainbow | N/A | X | X | | `background` | string or array of integers | Sets a background color. | N/A | X | X | | `rainbow` | boolean | Fades each letter in the text differently through the entire RGB spectrum. | false | X | X | -| `icon` | string | The icon ID or filename (without extension) to display on the app. | N/A | X | X | +| `icon` | string | The icon ID or filename (without extension) to display on the app. You can also send a **8x8 jpg** as Base64 String | N/A | X | X | | `pushIcon` | integer | 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 | X | X | | `repeat` | integer | Sets how many times the text should be scrolled through the matrix before the app ends. | -1 | X | X | | `duration` | integer | Sets how long the app or notification should be displayed. | 5 | X | X | diff --git a/docs/dev.md b/docs/dev.md index c0838195..3d853d63 100644 --- a/docs/dev.md +++ b/docs/dev.md @@ -30,4 +30,5 @@ The JSON object has the following properties: | `background_effect` | string | Sets an [effect](https://blueforcer.github.io/awtrix-light/#/effects) as global background layer | - | | `stats_interval` | integer | Sets the interval in milliseconds when awtrix should send its stats to HA and MQTT | 10000 | | `debug_mode` | boolean | Enables serial debug outputs. | false | -| `dfplayer` | boolean | Enables DFPLayer for Awtrix2_conversation builds. | false | \ No newline at end of file +| `dfplayer` | boolean | Enables DFPLayer for Awtrix2_conversation builds. | false | +| `button_callback` | string | http callback url for button presses. | - | \ No newline at end of file diff --git a/src/Globals.cpp b/src/Globals.cpp index c7cd70c1..b8910ab1 100644 --- a/src/Globals.cpp +++ b/src/Globals.cpp @@ -307,7 +307,7 @@ IPAddress gateway; IPAddress subnet; IPAddress primaryDNS; IPAddress secondaryDNS; -const char *VERSION = "0.90"; +const char *VERSION = "0.91"; String MQTT_HOST = ""; uint16_t MQTT_PORT = 1883; diff --git a/src/MQTTManager.cpp b/src/MQTTManager.cpp index db24106e..fa50fd1c 100644 --- a/src/MQTTManager.cpp +++ b/src/MQTTManager.cpp @@ -482,9 +482,8 @@ void MQTTManager_::sendStats() int freeHeapBytes = ESP.getFreeHeap(); itoa(freeHeapBytes, rambuffer, 10); ram->setValue(rambuffer); - long uptimeValue = PeripheryManager.readUptime(); char uptimeStr[25]; // Buffer for string representation - sprintf(uptimeStr, "%ld", uptimeValue); + sprintf(uptimeStr, "%ld", PeripheryManager.readUptime()); uptime->setValue(uptimeStr); transition->setState(AUTO_TRANSITION, false); ipAddr->setValue(ServerManager.myIP.toString().c_str()); diff --git a/src/PeripheryManager.cpp b/src/PeripheryManager.cpp index ed0bed6f..1828d6fe 100644 --- a/src/PeripheryManager.cpp +++ b/src/PeripheryManager.cpp @@ -506,14 +506,25 @@ void PeripheryManager_::tick() } } -long PeripheryManager_::readUptime() +unsigned long long PeripheryManager_::readUptime() { + static unsigned long lastTime = 0; + static unsigned long long totalElapsed = 0; + unsigned long currentTime = millis(); - unsigned long elapsedTime = currentTime - startTime; - long uptimeSeconds = elapsedTime / 1000; + if (currentTime < lastTime) { + // millis() overflow + totalElapsed += 4294967295UL - lastTime + currentTime + 1; + } else { + totalElapsed += currentTime - lastTime; + } + lastTime = currentTime; + + unsigned long long uptimeSeconds = totalElapsed / 1000; return uptimeSeconds; } + void PeripheryManager_::r2d2(const char *msg) { #ifdef ULANZI diff --git a/src/PeripheryManager.h b/src/PeripheryManager.h index ab700a04..4d261ff0 100644 --- a/src/PeripheryManager.h +++ b/src/PeripheryManager.h @@ -44,7 +44,7 @@ class PeripheryManager_ #ifndef ULANZI void setVolume(uint8_t); #endif - long readUptime(); + unsigned long long readUptime(); }; extern PeripheryManager_ &PeripheryManager;