adds new MQTT commands.
See
https://blueforcer.github.io/awtrix-light/#/mqtt
This commit is contained in:
Stephan Mühl
2023-03-23 17:13:52 +01:00
parent 04c9b5a85c
commit a3584ce059
10 changed files with 77 additions and 12 deletions

Binary file not shown.

View File

@@ -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,

View File

@@ -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.
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` |

View File

@@ -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();
}

View File

@@ -26,7 +26,7 @@ public:
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 @@ public:
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);
};

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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");
}

View File

@@ -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;

View File

@@ -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;
}