diff --git a/library/display.py b/library/display.py index dabbca52..e1484606 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,9 @@ 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))) + orientation = _get_theme_orientation() + 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 520b8364..7e96ec52 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 dad5251f..9c274658 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")