From 46684adebd70acc7c612078f0030629ec1043bfb Mon Sep 17 00:00:00 2001 From: infinition <37984399+infinition@users.noreply.github.com> Date: Tue, 19 Nov 2024 23:44:44 +0100 Subject: [PATCH] Update epd2in13.py New flag & if condition to track if the display has been initialized & avoid repeated initialization and accumulation of File descriptors & system crash. --- resources/waveshare_epd/epd2in13.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/resources/waveshare_epd/epd2in13.py b/resources/waveshare_epd/epd2in13.py index 611e9d7..e8fa364 100644 --- a/resources/waveshare_epd/epd2in13.py +++ b/resources/waveshare_epd/epd2in13.py @@ -9,6 +9,7 @@ logger = logging.getLogger(__name__) class EPD: def __init__(self): + self.is_initialized = False # New flag to track if the display has been initialized #INFINITION self.reset_pin = epdconfig.RST_PIN self.dc_pin = epdconfig.DC_PIN self.busy_pin = epdconfig.BUSY_PIN @@ -66,10 +67,10 @@ class EPD: logger.debug("e-Paper busy release") def init(self, lut): - if (epdconfig.module_init() != 0): - return -1 - # EPD hardware init start - self.reset() + if not self.is_initialized: # Avoid repeated initialization and accumulation of File descriptors #INFINITION + if epdconfig.module_init() != 0: + return -1 + self.reset() self.send_command(0x01) # DRIVER_OUTPUT_CONTROL self.send_data((EPD_HEIGHT - 1) & 0xFF) self.send_data(((EPD_HEIGHT - 1) >> 8) & 0xFF)