From 6b6536c1f074ce5dd4805c998f3ea754d18d1830 Mon Sep 17 00:00:00 2001 From: MrSoichi <21004580+MrSoichi@users.noreply.github.com> Date: Wed, 26 Aug 2026 19:40:17 +0600 Subject: [PATCH 1/2] Restore display orientation after Windows resume --- library/display.py | 10 ++++++---- library/lcd/lcd_comm_rev_a.py | 4 +++- main.py | 7 +++++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/library/display.py b/library/display.py index dabbca52c..9a7352af0 100644 --- a/library/display.py +++ b/library/display.py @@ -126,12 +126,9 @@ def initialize_display(self): # Send initialization commands self.lcd.InitializeComm() - # Turn on display, set brightness and LEDs for supported HW + # Turn on display, set brightness, LEDs and orientation for supported HW self.turn_on() - # Set orientation - self.lcd.SetOrientation(_get_theme_orientation()) - def turn_on(self): # Turn screen on in case it was turned off previously self.lcd.ScreenOn() @@ -142,6 +139,11 @@ def turn_on(self): # Set backplate RGB LED color (for supported HW only) self.lcd.SetBackplateLedColor(config.THEME_DATA['display'].get("DISPLAY_RGB_LED", (255, 255, 255))) + # The LCD controller may lose its configured orientation during sleep/hibernate. + orientation = _get_theme_orientation() + logger.info("Restoring display orientation: %s" % orientation.name) + self.lcd.SetOrientation(orientation) + def turn_off(self): # Turn screen off self.lcd.ScreenOff() diff --git a/library/lcd/lcd_comm_rev_a.py b/library/lcd/lcd_comm_rev_a.py index 520b83641..7e96ec52a 100644 --- a/library/lcd/lcd_comm_rev_a.py +++ b/library/lcd/lcd_comm_rev_a.py @@ -173,7 +173,9 @@ def SetOrientation(self, orientation: Orientation = Orientation.PORTRAIT): byteBuffer[8] = (width & 255) byteBuffer[9] = (height >> 8) byteBuffer[10] = (height & 255) - self.serial_write(bytes(byteBuffer)) + # Serialize orientation with the other display commands. A direct write can race + # the queue worker when Windows resumes and scheduled sensor redraws start again. + self.SendLine(bytes(byteBuffer)) def DisplayPILImage( self, diff --git a/main.py b/main.py index dad5251f6..9c2746586 100755 --- a/main.py +++ b/main.py @@ -161,10 +161,17 @@ def on_win32_wm_event(hWnd, msg, wParam, lParam): display.turn_off() elif wParam == win32con.PBT_APMRESUMEAUTOMATIC: logger.info("Computer is resuming from sleep, display will turn on") + # Windows may resume the process before the USB/serial endpoint is fully + # ready. Also allow queued pre-suspend writes to finish before restoring + # display state and redrawing the theme. + logger.info("Waiting 1.0s for USB display to settle after resume") + time.sleep(1.0) + wait_for_empty_queue(2) display.turn_on() # Some models have troubles displaying back the previous bitmap after being turned off/on display.display_static_images() display.display_static_text() + logger.info("Resume redraw queued") else: # For any other events, the program will stop logger.info("Program will now exit") From d2a880539a675ebd20e772ff4dab7ace4e5a5708 Mon Sep 17 00:00:00 2001 From: MrSoichi <21004580+MrSoichi@users.noreply.github.com> Date: Fri, 28 Aug 2026 23:57:11 +0600 Subject: [PATCH 2/2] Remove resume-specific orientation log --- library/display.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/library/display.py b/library/display.py index 9a7352af0..e14846063 100644 --- a/library/display.py +++ b/library/display.py @@ -139,9 +139,7 @@ def turn_on(self): # Set backplate RGB LED color (for supported HW only) self.lcd.SetBackplateLedColor(config.THEME_DATA['display'].get("DISPLAY_RGB_LED", (255, 255, 255))) - # The LCD controller may lose its configured orientation during sleep/hibernate. orientation = _get_theme_orientation() - logger.info("Restoring display orientation: %s" % orientation.name) self.lcd.SetOrientation(orientation) def turn_off(self):