Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions library/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion library/lcd/lcd_comm_rev_a.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down