From c8ce3949b3368329c290ca1858e65dc3416fc591 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maik=20Allg=C3=B6wer?= Date: Sun, 1 Feb 2026 14:36:37 +0100 Subject: [PATCH] feat: Allow for sunlight fading fix (#15) See crosspoint-reader/crosspoint-reader#561 for details. This PR contains necessary changes to be able to implement a fix for the sunlight fading issue present on the XTEINK X4. Basically, I'm making sure for all necessary functions to have a parameter turnOffScreen and to pass it through to displayBuffer() . displayBuffer() then won't do a HALF_REFRESH if if turnOffScreen is true and also pass it down to refreshDisplay(). --- libs/display/EInkDisplay/include/EInkDisplay.h | 4 ++-- libs/display/EInkDisplay/src/EInkDisplay.cpp | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/libs/display/EInkDisplay/include/EInkDisplay.h b/libs/display/EInkDisplay/include/EInkDisplay.h index 10d832f..2a98dcd 100644 --- a/libs/display/EInkDisplay/include/EInkDisplay.h +++ b/libs/display/EInkDisplay/include/EInkDisplay.h @@ -42,9 +42,9 @@ class EInkDisplay { void cleanupGrayscaleBuffers(const uint8_t* bwBuffer); #endif - void displayBuffer(RefreshMode mode = FAST_REFRESH); + void displayBuffer(RefreshMode mode = FAST_REFRESH, bool turnOffScreen = false); // 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 refreshDisplay(RefreshMode mode = FAST_REFRESH, bool turnOffScreen = false); diff --git a/libs/display/EInkDisplay/src/EInkDisplay.cpp b/libs/display/EInkDisplay/src/EInkDisplay.cpp index 572e127..6eaf138 100644 --- a/libs/display/EInkDisplay/src/EInkDisplay.cpp +++ b/libs/display/EInkDisplay/src/EInkDisplay.cpp @@ -408,8 +408,9 @@ void EInkDisplay::cleanupGrayscaleBuffers(const uint8_t* bwBuffer) { } #endif -void EInkDisplay::displayBuffer(RefreshMode mode) { - if (!isScreenOn) { +void EInkDisplay::displayBuffer(RefreshMode mode, const bool turnOffScreen) { + if (!isScreenOn && !turnOffScreen) + { // Force half refresh if screen is off mode = HALF_REFRESH; } @@ -442,7 +443,7 @@ void EInkDisplay::displayBuffer(RefreshMode mode) { #endif // Refresh the display - refreshDisplay(mode); + refreshDisplay(mode, turnOffScreen); #ifdef EINK_DISPLAY_SINGLE_BUFFER_MODE // In single buffer mode always sync RED RAM after refresh to prepare for next fast refresh @@ -455,7 +456,7 @@ void EInkDisplay::displayBuffer(RefreshMode mode) { // EXPERIMENTAL: Windowed update support // 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) -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) { if (Serial) Serial.printf("[%lu] Displaying window at (%d,%d) size (%dx%d)\n", millis(), x, y, w, h); // Validate bounds @@ -517,7 +518,7 @@ void EInkDisplay::displayWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h) #endif // Perform fast refresh - refreshDisplay(FAST_REFRESH); + refreshDisplay(FAST_REFRESH, turnOffScreen); #ifdef EINK_DISPLAY_SINGLE_BUFFER_MODE // Post-refresh: Sync RED RAM with current window (for next fast refresh)