Skip to content

Add LCD backlight timeout with shared LcdTaskBase base class for energy savings#1039

Draft
Copilot wants to merge 9 commits intomasterfrom
copilot/add-lcd-backlight-control
Draft

Add LCD backlight timeout with shared LcdTaskBase base class for energy savings#1039
Copilot wants to merge 9 commits intomasterfrom
copilot/add-lcd-backlight-control

Conversation

Copy link
Contributor

Copilot AI commented Feb 14, 2026

Implements configurable LCD backlight timeout for energy savings. Backlight turns off after inactivity, wakes on state changes, and remains on during error and charging conditions. The character LCD and TFT display implementations are properly subclassed via a common LcdTaskBase base class that contains all shared code.

Configuration

  • lcd_backlight_timeout (uint32_t, seconds) - 0 disables timeout (default for character LCD)
  • TFT boards default to TFT_BACKLIGHT_TIMEOUT_MS / 1000 (600 seconds) automatically
  • Added to standard config pipeline: app_config.h, app_config.cpp, emonesp.h

LcdTaskBase Base Class

Replaced the hacky preprocessor-based dual class definitions with proper C++ subclassing. LcdTaskBase (defined in lcd.h, implemented in lcd.cpp) contains all shared code:

  • Message class — inner class for queued display messages (previously duplicated)
  • Message queuedisplay() methods and displayNextMessage() with virtual onMessageDisplayed() hook
  • Backlight logic — state tracking, timeout management, wakeBacklight(), updateBacklight() with virtual backlightControl() for hardware-specific control
  • Common members_evse, _scheduler, _manual pointers

Subclasses

Character LCD LcdTask (in lcd.h/lcd.cpp, guarded by !ENABLE_SCREEN_LCD_TFT):

  • backlightControl() — sends RAPI $FB 0/$FB 1 commands
  • onMessageDisplayed() — calls showText(), sets display update flags
  • Full character LCD display logic (info lines, state display, etc.)

TFT LcdTask (in lcd_tft.h/lcd_tft.cpp, guarded by ENABLE_SCREEN_LCD_TFT):

  • backlightControl() — calls digitalWrite(LCD_BACKLIGHT_PIN, ...)
  • onMessageDisplayed() — wakes backlight, calls set_message_line()
  • TFT-specific display logic (ScreenManager, double buffering, etc.)

Behavior

  • Wakes on any EVSE state or vehicle connection change
  • Always stays on during error conditions (isError())
  • Always stays on during charging (isCharging())
  • Timeout uses signed comparison for millis() rollover protection
  • Caps timeout at ~49 days to prevent overflow

Refactoring

  • Removed duplicate backlight code from screen_manager.cpp (~60 lines)
  • ScreenManager::setWifiMode() now returns bool so LcdTask can trigger backlight wake
  • Eliminated duplicated Message class, display methods, and message queue code between lcd.cpp and lcd_tft.cpp
  • Net reduction of ~157 lines
Original prompt

This section details on the original issue you should resolve

<issue_title>LCD Energy Savings (backlight off)</issue_title>
<issue_description>Add basic energy savings.

Add ability to turn of LCD back light after x minutes of inactivity with the RAPI command $FB 0.

back light will turn back on automatically with any state change.</issue_description>

Comments on the Issue (you are @copilot in this section)

@jeremypoulter The dimming is for the LEDs, but we can however set the backlight off. The problem is more when to turn it back on, especially for units with no button.

That being said this is probably going to be the next issue to work on. </comment_new>
<comment_new>@jeremypoulter
I will take a look, but probably it would be better for the LCD backlight to be controlled by the WiFi firmware, that is where the majority of the logic is now. One thing to bear in mind is that the backlight should remain on in error conditions.

@jeremypoulter Definitely a lot of confusion between the LCD and LED, but not in this case ;-) (although the LED probably does need to do the same) the vast majority of the LCD control at this point comes from the WiFi module via RAPI commands and probably will move the LCD to be directly connected to the WiFi module at some point. It also is a lot harder to update the EVSE firmware we try not to implement new features on the EVSE board.

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits February 14, 2026 09:30
Co-authored-by: jeremypoulter <6116992+jeremypoulter@users.noreply.github.com>
Co-authored-by: jeremypoulter <6116992+jeremypoulter@users.noreply.github.com>
Co-authored-by: jeremypoulter <6116992+jeremypoulter@users.noreply.github.com>
Co-authored-by: jeremypoulter <6116992+jeremypoulter@users.noreply.github.com>
Copilot AI changed the title [WIP] Add ability to turn off LCD backlight after inactivity Add LCD backlight timeout for energy savings Feb 14, 2026
Copilot AI requested a review from jeremypoulter February 14, 2026 09:35
@github-actions
Copy link
Contributor

github-actions bot commented Feb 14, 2026

Test Results

58 tests  ±0   58 ✅ ±0   1s ⏱️ ±0s
 1 suites ±0    0 💤 ±0 
 1 files   ±0    0 ❌ ±0 

Results for commit 3e0a542. ± Comparison against base commit b931d6c.

♻️ This comment has been updated with latest results.

@jeremypoulter
Copy link
Collaborator

@copilot lets look at seeing if we can refactor lcd.cpp and lcd_tft.cpp to share the common code and merge the backlight code to ensure consistent behaviour

…TFT behaviour

Co-authored-by: jeremypoulter <6116992+jeremypoulter@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 25, 2026

@copilot lets look at seeing if we can refactor lcd.cpp and lcd_tft.cpp to share the common code and merge the backlight code to ensure consistent behaviour

Refactored in 648f8df. Created a shared LcdBacklight class (lcd_backlight.h/.cpp) that both display types now use:

  • Character LCD: initializes with RAPI $FB command callback
  • TFT LCD: initializes with digitalWrite(LCD_BACKLIGHT_PIN, ...) callback

The common logic (state change detection, error state handling, charging state handling, timeout with rollover protection) is now in one place. Removed ~60 lines of duplicate backlight code from screen_manager.cpp. Both paths now use the lcd_backlight_timeout config option — TFT boards default to TFT_BACKLIGHT_TIMEOUT_MS / 1000 automatically via emonesp.h.

Copilot AI changed the title Add LCD backlight timeout for energy savings Add LCD backlight timeout with shared LcdBacklight class for energy savings Feb 25, 2026
@jeremypoulter
Copy link
Collaborator

@copilot rather than create a new class specifically for the backlight functionality ir would probably be better to propperly subclass lcd.cpp/lcd_tft.cpp rather than the current hacky implementation as there is a lot of shared code between the two

Co-authored-by: jeremypoulter <6116992+jeremypoulter@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 25, 2026

@copilot rather than create a new class specifically for the backlight functionality ir would probably be better to propperly subclass lcd.cpp/lcd_tft.cpp rather than the current hacky...

Refactored in 3e0a542. Replaced the separate LcdBacklight class with a proper LcdTaskBase base class that both LCD implementations now inherit from:

  • LcdTaskBase (in lcd.h/lcd.cpp, always compiled) — contains Message class, message queue, display() methods, displayNextMessage(), backlight state management, _evse/_scheduler/_manual member pointers
  • Char LCD LcdTask (in lcd.h/lcd.cpp, guarded) — overrides backlightControl() for RAPI $FB commands, onMessageDisplayed() for text display
  • TFT LcdTask (in lcd_tft.h/lcd_tft.cpp, guarded) — overrides backlightControl() for GPIO, onMessageDisplayed() for TFT rendering

Deleted lcd_backlight.h/lcd_backlight.cpp. Net reduction of 157 lines by eliminating duplicated Message class, display methods, and message queue code.

Copilot AI changed the title Add LCD backlight timeout with shared LcdBacklight class for energy savings Add LCD backlight timeout with shared LcdTaskBase base class for energy savings Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LCD Energy Savings (backlight off)

2 participants