Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SSD1306] MQTT confirmations removal #1508

Merged
merged 1 commit into from
Mar 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 18 additions & 26 deletions main/ZdisplaySSD1306.ino
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,12 @@ void MQTTtoSSD1306(char* topicOri, JsonObject& SSD1306data) { // json object dec
Log.trace(F("MQTTtoSSD1306 json set" CR));
// properties
if (SSD1306data.containsKey("onstate")) {
if (displayState != SSD1306data["onstate"]) {
displayState = SSD1306data["onstate"].as<bool>();
if (!displayState) {
Oled.display->displayOff();
} else {
Oled.display->displayOn();
Oled.begin();
}
}
displayState = SSD1306data["onstate"].as<bool>();
Log.notice(F("Set display state: %T" CR), displayState);
success = true;
}
if (SSD1306data.containsKey("brightness")) {
displayBrightness = SSD1306data["brightness"].as<int>();
Oled.display->setBrightness(round(displayBrightness * 2.55));
Oled.begin();
Log.notice(F("Set brightness: %d" CR), displayBrightness);
success = true;
}
Expand Down Expand Up @@ -178,49 +167,38 @@ void MQTTtoSSD1306(char* topicOri, JsonObject& SSD1306data) { // json object dec
if (SSD1306data.containsKey("display-flip")) {
displayFlip = SSD1306data["display-flip"].as<bool>();
Log.notice(F("Set display-flip: %T" CR), displayFlip);
if (displayFlip) {
Oled.display->flipScreenVertically();
} else {
Oled.display->resetOrientation();
}
success = true;
}
// save, load, init, erase
if (SSD1306data.containsKey("save") && SSD1306data["save"]) {
success = SSD1306Config_save();
if (success) {
Log.notice(F("SSD1306 config saved" CR));
pub(subjectSSD1306toMQTT, "{\"Status\": \"SSD1306 configs saved\"}");
}
} else if (SSD1306data.containsKey("load") && SSD1306data["load"]) {
success = SSD1306Config_load();
if (success) {
Log.notice(F("SSD1306 config loaded" CR));
pub(subjectSSD1306toMQTT, "{\"Status\": \"SSD1306 configs loaded\"}");
Oled.begin();
}
} else if (SSD1306data.containsKey("init") && SSD1306data["init"]) {
SSD1306Config_init();
pub(subjectSSD1306toMQTT, "{\"Status\": \"SSD1306 configs initialised\"}");
Oled.begin();
success = true;
if (success) {
Log.notice(F("SSD1306 config initialised" CR));
}
} else if (SSD1306data.containsKey("erase") && SSD1306data["erase"]) {
// Erase config from NVS (non-volatile storage)
preferences.begin(Gateway_Short_Name, false);
success = preferences.remove("SSD1306Config");
preferences.end();
if (success) {
Log.notice(F("SSD1306 config erased" CR));
pub(subjectSSD1306toMQTT, "{\"Status\": \"SSD1306 configs erased\"}");
} else {
Log.notice(F("SSD1306 nothing to erase" CR));
pub(subjectSSD1306toMQTT, "{\"Status\": \"SSD1306 nothing to erase\"}");
}
}
if (success) {
stateSSD1306Display();
} else {
pub(subjectSSD1306toMQTT, "{\"Status\": \"Error\"}"); // Fail feedback
// pub(subjectSSD1306toMQTT, "{\"Status\": \"Error\"}"); // Fail feedback
Log.error(F("[ SSD1306 ] MQTTtoSSD1306 Fail json" CR), SSD1306data);
}
}
Expand Down Expand Up @@ -1029,6 +1007,20 @@ void stateSSD1306Display() {
DISPLAYdata["log-oled"] = (bool)logToOLEDDisplay;
DISPLAYdata["json-oled"] = (bool)jsonDisplay;
pub(subjectSSD1306toMQTT, DISPLAYdata);
// apply
Oled.display->setBrightness(round(displayBrightness * 2.55));

if (!displayState) {
Oled.display->displayOff();
} else {
Oled.display->displayOn();
}

if (displayFlip) {
Oled.display->flipScreenVertically();
} else {
Oled.display->resetOrientation();
}
}

#endif