feat: add turnOffScreen parameter for sunlight fading fix

Add optional turnOffScreen parameter to displayBuffer() and displayWindow()
to allow turning off the screen after refresh, mitigating sunlight fading issues.
This commit is contained in:
cottongin 2026-01-30 23:02:20 -05:00
parent dede09001c
commit be6ba1b62b
No known key found for this signature in database
GPG Key ID: 0ECC91FE4655C262
2 changed files with 7 additions and 7 deletions

View File

@ -42,9 +42,9 @@ class EInkDisplay {
void cleanupGrayscaleBuffers(const uint8_t* bwBuffer); void cleanupGrayscaleBuffers(const uint8_t* bwBuffer);
#endif #endif
void displayBuffer(RefreshMode mode = FAST_REFRESH); void displayBuffer(RefreshMode mode = FAST_REFRESH, bool turnOffScreen = false);
// EXPERIMENTAL: Windowed update - display only a rectangular region // EXPERIMENTAL: Windowed update - display only a rectangular region
void displayWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h); void displayWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h, bool turnOffScreen = false);
void displayGrayBuffer(bool turnOffScreen = false); void displayGrayBuffer(bool turnOffScreen = false);
void refreshDisplay(RefreshMode mode = FAST_REFRESH, bool turnOffScreen = false); void refreshDisplay(RefreshMode mode = FAST_REFRESH, bool turnOffScreen = false);

View File

@ -418,8 +418,8 @@ void EInkDisplay::cleanupGrayscaleBuffers(const uint8_t* bwBuffer) {
} }
#endif #endif
void EInkDisplay::displayBuffer(RefreshMode mode) { void EInkDisplay::displayBuffer(RefreshMode mode, const bool turnOffScreen) {
if (!isScreenOn) { if (!isScreenOn && !turnOffScreen) {
// Force half refresh if screen is off // Force half refresh if screen is off
mode = HALF_REFRESH; mode = HALF_REFRESH;
} }
@ -451,7 +451,7 @@ void EInkDisplay::displayBuffer(RefreshMode mode) {
#endif #endif
// Refresh the display // Refresh the display
refreshDisplay(mode); refreshDisplay(mode, turnOffScreen);
#ifdef EINK_DISPLAY_SINGLE_BUFFER_MODE #ifdef EINK_DISPLAY_SINGLE_BUFFER_MODE
// In single buffer mode always sync RED RAM after refresh to prepare for next fast refresh // In single buffer mode always sync RED RAM after refresh to prepare for next fast refresh
@ -464,7 +464,7 @@ void EInkDisplay::displayBuffer(RefreshMode mode) {
// EXPERIMENTAL: Windowed update support // EXPERIMENTAL: Windowed update support
// Displays only a rectangular region of the frame buffer, preserving the rest of the screen. // Displays only a rectangular region of the frame buffer, preserving the rest of the screen.
// Requirements: x and w must be byte-aligned (multiples of 8 pixels) // Requirements: x and w must be byte-aligned (multiples of 8 pixels)
void EInkDisplay::displayWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h) { void EInkDisplay::displayWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const bool turnOffScreen) {
Serial.printf("[%lu] Displaying window at (%d,%d) size (%dx%d)\n", millis(), x, y, w, h); Serial.printf("[%lu] Displaying window at (%d,%d) size (%dx%d)\n", millis(), x, y, w, h);
// Validate bounds // Validate bounds
@ -525,7 +525,7 @@ void EInkDisplay::displayWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
#endif #endif
// Perform fast refresh // Perform fast refresh
refreshDisplay(FAST_REFRESH); refreshDisplay(FAST_REFRESH, turnOffScreen);
#ifdef EINK_DISPLAY_SINGLE_BUFFER_MODE #ifdef EINK_DISPLAY_SINGLE_BUFFER_MODE
// Post-refresh: Sync RED RAM with current window (for next fast refresh) // Post-refresh: Sync RED RAM with current window (for next fast refresh)