Add LCD backlight timeout with shared LcdTaskBase base class for energy savings#1039
Add LCD backlight timeout with shared LcdTaskBase base class for energy savings#1039
Conversation
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 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>
Refactored in 648f8df. Created a shared
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 |
|
@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>
Refactored in 3e0a542. Replaced the separate
Deleted |
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
LcdTaskBasebase class that contains all shared code.Configuration
lcd_backlight_timeout(uint32_t, seconds) - 0 disables timeout (default for character LCD)TFT_BACKLIGHT_TIMEOUT_MS / 1000(600 seconds) automaticallyapp_config.h,app_config.cpp,emonesp.hLcdTaskBase Base Class
Replaced the hacky preprocessor-based dual class definitions with proper C++ subclassing.
LcdTaskBase(defined inlcd.h, implemented inlcd.cpp) contains all shared code:display()methods anddisplayNextMessage()with virtualonMessageDisplayed()hookwakeBacklight(),updateBacklight()with virtualbacklightControl()for hardware-specific control_evse,_scheduler,_manualpointersSubclasses
Character LCD
LcdTask(inlcd.h/lcd.cpp, guarded by!ENABLE_SCREEN_LCD_TFT):backlightControl()— sends RAPI$FB 0/$FB 1commandsonMessageDisplayed()— callsshowText(), sets display update flagsTFT
LcdTask(inlcd_tft.h/lcd_tft.cpp, guarded byENABLE_SCREEN_LCD_TFT):backlightControl()— callsdigitalWrite(LCD_BACKLIGHT_PIN, ...)onMessageDisplayed()— wakes backlight, callsset_message_line()Behavior
isError())isCharging())millis()rollover protectionRefactoring
screen_manager.cpp(~60 lines)ScreenManager::setWifiMode()now returnsboolsoLcdTaskcan trigger backlight wakeMessageclass, display methods, and message queue code between lcd.cpp and lcd_tft.cppOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.