Skip to content

Commit 3728437

Browse files
Merge branch 'master' into max_hardware_current_set
2 parents 3e63771 + 06da17f commit 3728437

File tree

8 files changed

+30
-34
lines changed

8 files changed

+30
-34
lines changed

platformio.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ debug_flags =
7070
#-D ENABLE_DEBUG_CETRIFICATES
7171
#-D ENABLE_DEBUG_WEB_CETRIFICATES
7272
#-D ENABLE_DEBUG_MONGOOSE_MQTT_CLIENT
73+
#-D ENABLE_DEBUG_SCREEN_MANAGER
74+
#-D ENABLE_DEBUG_SCREEN_RENDERER
75+
#-D ENABLE_DEBUG_SCREEN_CHARGE
76+
#-D ENABLE_DEBUG_SCREEN_BOOT
7377
src_build_flags =
7478
# -D ARDUINOJSON_USE_LONG_LONG
7579
# -D ENABLE_ASYNC_WIFI_SCAN

src/lcd_tft.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,20 +166,16 @@ unsigned long LcdTask::loop(MicroTasks::WakeReason reason)
166166
DBUGF("Back buffer %p", _back_buffer_pixels);
167167
#endif
168168

169+
// Create the screen manager with pointers to display and data sources
170+
_screenManager = new ScreenManager(_screen, evse, scheduler, manual);
171+
169172
pinMode(LCD_BACKLIGHT_PIN, OUTPUT);
170173
#ifdef TFT_BACKLIGHT_TIMEOUT_MS
171-
if(_screenManager) {
172-
_screenManager->wakeBacklight();
173-
} else {
174-
digitalWrite(LCD_BACKLIGHT_PIN, HIGH);
175-
}
174+
_screenManager->wakeBacklight();
176175
#else
177176
digitalWrite(LCD_BACKLIGHT_PIN, HIGH);
178177
#endif //TFT_BACKLIGHT_TIMEOUT_MS
179178
_initialise = false;
180-
181-
// Create the screen manager with pointers to display and data sources
182-
_screenManager = new ScreenManager(_screen, evse, scheduler, manual);
183179
}
184180

185181
// If we have messages to display, do it

src/lcd_tft.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,9 @@ class LcdTask : public MicroTasks::Task
8888
// Screen management
8989
ScreenManager* _screenManager = nullptr;
9090

91-
#ifdef TFT_BACKLIGHT_TIMEOUT_MS
92-
long _last_backlight_wakeup = 0;
93-
bool _previous_vehicle_state;
94-
#endif //TFT_BACKLIGHT_TIMEOUT_MS
95-
9691
void display(Message *msg, uint32_t flags);
9792
unsigned long displayNextMessage();
9893

99-
#ifdef TFT_BACKLIGHT_TIMEOUT_MS
100-
void timeoutBacklight();
101-
#endif //TFT_BACKLIGHT_TIMEOUT_MS
102-
10394
protected:
10495
void setup();
10596
unsigned long loop(MicroTasks::WakeReason reason);
@@ -115,10 +106,6 @@ class LcdTask : public MicroTasks::Task
115106
void display(const char *msg, int x, int y, int time, uint32_t flags);
116107
void setWifiMode(bool client, bool connected);
117108

118-
#ifdef TFT_BACKLIGHT_TIMEOUT_MS
119-
void wakeBacklight();
120-
#endif //TFT_BACKLIGHT_TIMEOUT_MS
121-
122109
void fill_screen(uint16_t color) {
123110
_screen.fillScreen(color);
124111
}

src/screens/screen_boot.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if defined(ENABLE_DEBUG) && !defined(ENABLE_DEBUG_LCD)
1+
#if defined(ENABLE_DEBUG) && !defined(ENABLE_DEBUG_SCREEN_BOOT)
22
#undef ENABLE_DEBUG
33
#endif
44

src/screens/screen_charge.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if defined(ENABLE_DEBUG) && !defined(ENABLE_DEBUG_LCD)
1+
#if defined(ENABLE_DEBUG) && !defined(ENABLE_DEBUG_SCREEN_CHARGE)
22
#undef ENABLE_DEBUG
33
#endif
44

src/screens/screen_manager.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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

6565
unsigned 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

9798
void 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

131137
void 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
}

src/screens/screen_manager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class ScreenManager {
4848
ScreenBase* _screens[SCREEN_COUNT];
4949

5050
#ifdef TFT_BACKLIGHT_TIMEOUT_MS
51-
unsigned long _last_backlight_wakeup = 0;
51+
unsigned long _backlight_timeout = 0;
5252
bool _previous_vehicle_state = false;
5353
uint8_t _previous_evse_state = 0;
5454
#endif //TFT_BACKLIGHT_TIMEOUT_MS

src/screens/screen_renderer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if defined(ENABLE_DEBUG) && !defined(ENABLE_DEBUG_LCD)
1+
#if defined(ENABLE_DEBUG) && !defined(ENABLE_DEBUG_SCREEN_RENDERER)
22
#undef ENABLE_DEBUG
33
#endif
44

0 commit comments

Comments
 (0)