Skip to content
Open
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
27 changes: 24 additions & 3 deletions src/display/waveshare_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ def initialize_display(self):

try:
# Dynamically load module
epd_module = importlib.import_module(module_name)
self.epd_display = epd_module.EPD()
self.epd_module = importlib.import_module(module_name)
self.epd_display = self.epd_module.EPD()
# Workaround for init functions with inconsistent casing
self.epd_display_init = getattr(self.epd_display, "Init", getattr(self.epd_display, "init", None))

Comment thread
motschel123 marked this conversation as resolved.
Expand All @@ -98,6 +98,27 @@ def initialize_display(self):
"resolution",
resolution,
write=True)

def reinitialize_display(self):

"""
Re-initializes the Waveshare display device.

Waveshare EPDs may require re-initialization after entering sleep mode. This is
achieved by calling the EPD() constructor and init method again.

Not doing this results in "OSError: [Errno 9] Bad file descriptor" because the
SPI file descriptor is closed by waveshare's epdconfig sleep() command.
"""

self.epd_display = self.epd_module.EPD()
# Workaround for init functions with inconsistent casing
self.epd_display_init = getattr(self.epd_display, "Init", getattr(self.epd_display, "init", None))

if not callable(self.epd_display_init):
raise AttributeError("No Init/init method found")

self.epd_display_init()


def display_image(self, image, image_settings=[]):
Expand All @@ -121,7 +142,7 @@ def display_image(self, image, image_settings=[]):
raise ValueError(f"No image provided.")

# Assume device was in sleep mode.
self.epd_display_init()
self.reinitialize_display()

# Clear residual pixels before updating the image.
self.epd_display.Clear()
Expand Down