1- #if defined(ENABLE_DEBUG) && !defined(ENABLE_DEBUG_LCD )
1+ #if defined(ENABLE_DEBUG) && !defined(ENABLE_DEBUG_SCREEN_MANAGER )
22#undef ENABLE_DEBUG
33#endif
44
@@ -64,6 +64,8 @@ void ScreenManager::setScreen(ScreenType screen)
6464
6565unsigned long ScreenManager::update ()
6666{
67+ unsigned long nextUpdate = 1000 ; // Default to 1 second
68+
6769 // Handle special case: automatic transition from boot to charge screen
6870 if (_current_screen == SCREEN_BOOT) {
6971 BootScreen* bootScreen = static_cast <BootScreen*>(_screens[SCREEN_BOOT]);
@@ -74,7 +76,7 @@ unsigned long ScreenManager::update()
7476
7577 // Update the current screen
7678 if (_screens[_current_screen]) {
77- return _screens[_current_screen]->update ();
79+ nextUpdate = _screens[_current_screen]->update ();
7880 }
7981
8082#ifdef TFT_BACKLIGHT_TIMEOUT_MS
@@ -83,15 +85,14 @@ unsigned long ScreenManager::update()
8385
8486 if (_previous_evse_state != evse_state || _previous_vehicle_state != vehicle_state) {
8587 wakeBacklight ();
86- _previous_vehicle_state = vehicle_state;
88+ _previous_vehicle_state = vehicle_state;
8789 _previous_evse_state = evse_state;
8890 } else {
8991 updateBacklight ();
9092 }
9193#endif // TFT_BACKLIGHT_TIMEOUT_MS
9294
93-
94- return 1000 ; // Default update interval if no screen is active
95+ return nextUpdate;
9596}
9697
9798void ScreenManager::handleEvent (uint8_t event)
@@ -117,19 +118,26 @@ void ScreenManager::setWifiMode(bool client, bool connected)
117118
118119// Add backlight management implementations
119120#ifdef TFT_BACKLIGHT_TIMEOUT_MS
120- void ScreenManager::wakeBacklight () {
121+ void ScreenManager::wakeBacklight ()
122+ {
123+ DBUGLN (" 🔦 Waking backlight" );
121124 digitalWrite (LCD_BACKLIGHT_PIN, HIGH);
122- _last_backlight_wakeup = millis ();
125+ _backlight_timeout = millis () + TFT_BACKLIGHT_TIMEOUT_MS ;
123126}
124127
125- void ScreenManager::timeoutBacklight () {
126- if (millis () - _last_backlight_wakeup >= TFT_BACKLIGHT_TIMEOUT_MS) {
128+ void ScreenManager::timeoutBacklight ()
129+ {
130+ if (millis () >= _backlight_timeout)
131+ {
132+ DBUGLN (" Timing out backlight" );
127133 digitalWrite (LCD_BACKLIGHT_PIN, LOW);
128134 }
129135}
130136
131137void ScreenManager::updateBacklight ()
132138{
139+ DBUGF (" Backlight timeout in %lu ms" , _backlight_timeout - millis ());
140+
133141 bool timeout = true ;
134142 if (_evse.isVehicleConnected ()) {
135143 switch (_evse.getEvseState ()) {
@@ -165,6 +173,7 @@ void ScreenManager::updateBacklight()
165173 break ;
166174 }
167175 }
176+ DBUGVAR (timeout);
168177 if (timeout) {
169178 timeoutBacklight ();
170179 }
0 commit comments