V0.36
adds new MQTT commands. See https://blueforcer.github.io/awtrix-light/#/mqtt
This commit is contained in:
@@ -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();
|
||||
}
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user