Feature: Turn off Display before reboot

Thanks for the idea to @StefanOberhumer
This prevents always on Display if the device profile does not contain Display pins anymore after the reboot
This commit is contained in:
Thomas Basler 2023-08-25 16:57:24 +02:00
parent c91bd42a77
commit 701c490654
3 changed files with 20 additions and 2 deletions

View File

@ -19,6 +19,7 @@ public:
void init(DisplayType_t type, uint8_t data, uint8_t clk, uint8_t cs, uint8_t reset);
void loop();
void setContrast(uint8_t contrast);
void setStatus(bool turnOn);
void setOrientation(uint8_t rotation = DISPLAY_ROTATION);
void setLanguage(uint8_t language);
void setStartupDisplay();
@ -33,6 +34,8 @@ private:
U8G2* _display;
bool _displayTurnedOn;
DisplayType_t _display_type = DisplayType_t::None;
uint8_t _display_language = DISPLAY_LANGUAGE;
uint8_t _mExtra;

View File

@ -47,6 +47,7 @@ void DisplayGraphicClass::init(DisplayType_t type, uint8_t data, uint8_t clk, ui
_display = constructor(reset, clk, data, cs);
_display->begin();
setContrast(DISPLAY_CONTRAST);
setStatus(true);
}
}
@ -139,10 +140,11 @@ void DisplayGraphicClass::loop()
if ((millis() - _lastDisplayUpdate) > _period) {
_display->clearBuffer();
bool displayPowerSave = false;
//=====> Actual Production ==========
if (Datastore.getIsAtLeastOneReachable()) {
_display->setPowerSave(false);
displayPowerSave = false;
if (Datastore.getTotalAcPowerEnabled() > 999) {
snprintf(_fmtText, sizeof(_fmtText), i18n_current_power_kw[_display_language], (Datastore.getTotalAcPowerEnabled() / 1000));
} else {
@ -158,7 +160,7 @@ void DisplayGraphicClass::loop()
printText(i18n_offline[_display_language], 0);
// check if it's time to enter power saving mode
if (millis() - _previousMillis >= (_interval * 2)) {
_display->setPowerSave(enablePowerSafe);
displayPowerSave = enablePowerSafe;
}
}
//<=======================
@ -184,6 +186,12 @@ void DisplayGraphicClass::loop()
_mExtra++;
_lastDisplayUpdate = millis();
if (!_displayTurnedOn) {
displayPowerSave = true;
}
_display->setPowerSave(displayPowerSave);
}
}
@ -195,4 +203,9 @@ void DisplayGraphicClass::setContrast(uint8_t contrast)
_display->setContrast(contrast * 2.55f);
}
void DisplayGraphicClass::setStatus(bool turnOn)
{
_displayTurnedOn = turnOn;
}
DisplayGraphicClass Display;

View File

@ -3,6 +3,7 @@
* Copyright (C) 2022 - 2023 Thomas Basler and others
*/
#include "Utils.h"
#include "Display_Graphic.h"
#include "Led_Single.h"
#include <Esp.h>
@ -58,6 +59,7 @@ int Utils::getTimezoneOffset()
void Utils::restartDtu()
{
LedSingle.turnAllOff();
Display.setStatus(false);
yield();
delay(1000);
yield();