From 258e212e07b2420edf7e2cc3126c002f83abad8c Mon Sep 17 00:00:00 2001 From: infinition <37984399+infinition@users.noreply.github.com> Date: Tue, 19 Nov 2024 23:42:20 +0100 Subject: [PATCH] Update epd2in13_V4.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_V4.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/resources/waveshare_epd/epd2in13_V4.py b/resources/waveshare_epd/epd2in13_V4.py index da328b1..f32906a 100644 --- a/resources/waveshare_epd/epd2in13_V4.py +++ b/resources/waveshare_epd/epd2in13_V4.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 @@ -138,11 +139,11 @@ class EPD: parameter: ''' def init(self): - 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.is_initialized = True self.ReadBusy() self.send_command(0x12) #SWRESET self.ReadBusy()