diff --git a/docs/flasher/firmware/firmware.bin b/docs/flasher/firmware/firmware.bin index c466ca1a..788d40cb 100644 Binary files a/docs/flasher/firmware/firmware.bin and b/docs/flasher/firmware/firmware.bin differ diff --git a/docs/flasher/firmware/manifest.json b/docs/flasher/firmware/manifest.json index a917cd0e..a63ca1e4 100644 --- a/docs/flasher/firmware/manifest.json +++ b/docs/flasher/firmware/manifest.json @@ -1,6 +1,6 @@ { "name": "AWTRIX Light", - "version": "0.35", + "version": "0.36", "home_assistant_domain": "AwtrixLight", "funding_url": "https://blueforcer.de", "new_install_prompt_erase": true, diff --git a/docs/mqtt.md b/docs/mqtt.md index 7fa48f72..61cb1653 100644 --- a/docs/mqtt.md +++ b/docs/mqtt.md @@ -1,9 +1,14 @@ # MQTT Commands -### Switch to app -**Topic** +### Switch apps +##### Topic +`[PREFIX]/nextapp` +`[PREFIX]/previousapp` + +### Switch to specific app +##### Topic `[PREFIX]/switch` -**Payload** +##### Payload `{"name":"time"}` Build-in app names are @@ -15,4 +20,19 @@ Build-in app names are For custompages you need to call the name you set in the topic: If `[PREFIX]/custom/test` is your topic, -then `test` is the name. \ No newline at end of file +then `test` is the name. + +## Change Settings +##### Topic +`[PREFIX]/settings` + +##### JSON Properties +| Key | Type | Description | Value Range | +| ----------- | ------- | --------------------------------------------------------------------------- | ------------------------------------------ | +| `apptime` | number | Determines the duration an app is displayed in milliseconds. | Any positive integer value. Default 7000 | +| `transition`| number | The time the transition to the next app takes in milliseconds. | Any positive integer value. Default 500 | +| `textcolor` | string | A color in hexadecimal format. | Any valid 6-digit hexadecimal color value, e.g. "#FF0000" for red | +| `fps` | number | Determines the frame rate at which the matrix is updated. | Any positive integer value. Default 23 | +| `brightness`| number | Determines the brightness of the matrix. | An integer between 0 and 255 | +| `autobrightness`| boolean | Determines if automatic brightness control is active. | `true` or `false` | +| `autotransition`| boolean | Determines if automatic switching to the next app is active. | `true` or `false` | diff --git a/src/DisplayManager.cpp b/src/DisplayManager.cpp index c45eb28c..8a24da58 100644 --- a/src/DisplayManager.cpp +++ b/src/DisplayManager.cpp @@ -92,11 +92,14 @@ void DisplayManager_::drawJPG(uint16_t x, uint16_t y, fs::File jpgFile) TJpgDec.drawFsJpg(x, y, jpgFile); } -void DisplayManager_::setSettings() +void DisplayManager_::applyAllSettings() { ui.setTargetFPS(MATRIX_FPS); ui.setTimePerApp(TIME_PER_APP); ui.setTimePerTransition(TIME_PER_TRANSITION); + setBrightness(BRIGHTNESS); + setTextColor(TEXTCOLOR_565); + setAutoTransition(AUTO_TRANSITION); } void DisplayManager_::resetTextColor() @@ -492,4 +495,21 @@ void DisplayManager_::switchToApp(String Payload) int index = findAppIndexByName(name); if (index > -1) ui.transitionToApp(index); +} + +void DisplayManager_::setNewSettings(String Payload) +{ + DynamicJsonDocument doc(512); + DeserializationError error = deserializeJson(doc, Payload); + if (error) + return; + TIME_PER_APP = doc.containsKey("apptime") ? doc["apptime"] : TIME_PER_APP; + TIME_PER_TRANSITION = doc.containsKey("transition") ? doc["transition"] : TIME_PER_TRANSITION; + TEXTCOLOR_565 = doc.containsKey("textcolor") ? hexToRgb565(doc["textcolor"]) : TEXTCOLOR_565; + MATRIX_FPS = doc.containsKey("fps") ? doc["fps"] : MATRIX_FPS; + BRIGHTNESS = doc.containsKey("brightness") ? doc["brightness"] : BRIGHTNESS; + AUTO_BRIGHTNESS = doc.containsKey("autobrightness") ? doc["autobrightness"] : AUTO_BRIGHTNESS; + AUTO_TRANSITION = doc.containsKey("autotransition") ? doc["autotransition"] : AUTO_TRANSITION; + applyAllSettings(); + saveSettings(); } \ No newline at end of file diff --git a/src/DisplayManager.h b/src/DisplayManager.h index 979ccbc3..e0a587b1 100644 --- a/src/DisplayManager.h +++ b/src/DisplayManager.h @@ -26,7 +26,7 @@ class DisplayManager_ static DisplayManager_ &getInstance(); void setup(); void tick(); - void setSettings(); + void applyAllSettings(); void rightButton(); void dismissNotify(); void HSVtext(int16_t, int16_t, const char *, bool); @@ -48,6 +48,7 @@ class DisplayManager_ void printText(int16_t x, int16_t y, const char *text, bool centered, bool ignoreUppercase); bool setAutoTransition(bool active); void switchToApp(String Payload); + void setNewSettings(String Payload); void drawGIF(uint16_t x, uint16_t y, fs::File gifFile); void drawJPG(uint16_t x, uint16_t y, fs::File jpgFile); }; diff --git a/src/Functions.h b/src/Functions.h index 35e4c2c8..ca194ddb 100644 --- a/src/Functions.h +++ b/src/Functions.h @@ -24,6 +24,9 @@ uint16_t hexToRgb565(String hexValue) uint8_t r = strtol(hexValue.substring(0, 2).c_str(), NULL, 16); uint8_t g = strtol(hexValue.substring(2, 4).c_str(), NULL, 16); uint8_t b = strtol(hexValue.substring(4, 6).c_str(), NULL, 16); + if ((errno == ERANGE) || (r > 255) || (g > 255) || (b > 255)) { + return 0xFFFF; + } uint16_t color = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3); return color; } diff --git a/src/Globals.cpp b/src/Globals.cpp index fa6687f5..a4614d0a 100644 --- a/src/Globals.cpp +++ b/src/Globals.cpp @@ -34,7 +34,7 @@ IPAddress gateway; IPAddress subnet; IPAddress primaryDNS; IPAddress secondaryDNS; -const char *VERSION = "0.35"; +const char *VERSION = "0.36"; String MQTT_HOST = ""; uint16_t MQTT_PORT = 1883; String MQTT_USER; diff --git a/src/MQTTManager.cpp b/src/MQTTManager.cpp index b355bd2e..937f4b52 100644 --- a/src/MQTTManager.cpp +++ b/src/MQTTManager.cpp @@ -132,12 +132,30 @@ void onMqttMessage(const char *topic, const uint8_t *payload, uint16_t length) return; } - if (strTopic == MQTT_PREFIX + "/switch") + if (strTopic == MQTT_PREFIX + "/switch") { DisplayManager.switchToApp(strPayload); return; } + if (strTopic == MQTT_PREFIX + "/settings") + { + DisplayManager.setNewSettings(strPayload); + return; + } + + if (strTopic == MQTT_PREFIX + "/nextapp") + { + DisplayManager.nextApp(); + return; + } + + if (strTopic == MQTT_PREFIX + "/previousapp") + { + DisplayManager.previousApp(); + return; + } + else if (strTopic.startsWith(MQTT_PREFIX + "/custom")) { String topic_str = topic; @@ -161,6 +179,9 @@ void onMqttConnected() mqtt.subscribe((prefix + String("/timer")).c_str()); mqtt.subscribe((prefix + String("/custom/#")).c_str()); mqtt.subscribe((prefix + String("/switch")).c_str()); + mqtt.subscribe((prefix + String("/settings")).c_str()); + mqtt.subscribe((prefix + String("/previousapp")).c_str()); + mqtt.subscribe((prefix + String("/nextapp")).c_str()); Serial.println("MQTT Connected"); } diff --git a/src/MenuManager.cpp b/src/MenuManager.cpp index caf36fe9..80bef25e 100644 --- a/src/MenuManager.cpp +++ b/src/MenuManager.cpp @@ -289,12 +289,12 @@ void MenuManager_::selectButtonLong() } else if (currentState == TspeedMenu) { - DisplayManager.setSettings(); + DisplayManager.applyAllSettings(); saveSettings(); } else if (currentState == AppTimeMenu) { - DisplayManager.setSettings(); + DisplayManager.applyAllSettings(); saveSettings(); } currentState = MainMenu; diff --git a/src/ServerManager.cpp b/src/ServerManager.cpp index 427737d0..df0daf1c 100644 --- a/src/ServerManager.cpp +++ b/src/ServerManager.cpp @@ -206,7 +206,7 @@ void ServerManager_::loadSettings() SHOW_HUM = doc["Show humidity"]; SHOW_BATTERY = doc["Show battery"]; file.close(); - DisplayManager.setSettings(); + DisplayManager.applyAllSettings(); Serial.println(F("Configuration loaded")); return; }