Skip to content
Open
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
10 changes: 6 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,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)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'Restoring display orientation' log is confusing when turn_on() is called at program startup, since it is not really restoring the setting but rather applying it for the first time.
I think it is not necessary to have a log here at all.
Same for the comment l. 142 that speaks of a specific case

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