Update epd2in13_V2.py

New flag & if condition to track if the display has been initialized &
avoid repeated initialization and accumulation of File descriptors  & system crash.
This commit is contained in:
infinition
2024-11-19 23:44:00 +01:00
committed by GitHub
parent 7daf7e8632
commit d0b9b737f9

View File

@@ -9,6 +9,7 @@ logger = logging.getLogger(__name__)
class EPD: class EPD:
def __init__(self): 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.reset_pin = epdconfig.RST_PIN
self.dc_pin = epdconfig.DC_PIN self.dc_pin = epdconfig.DC_PIN
self.busy_pin = epdconfig.BUSY_PIN self.busy_pin = epdconfig.BUSY_PIN
@@ -99,10 +100,12 @@ class EPD:
self.ReadBusy() self.ReadBusy()
def init(self, update): def init(self, update):
if (epdconfig.module_init() != 0): if not self.is_initialized: # Avoid repeated initialization and accumulation of File descriptors #INFINITION
if epdconfig.module_init() != 0:
return -1 return -1
# EPD hardware init start
self.reset() self.reset()
self.is_initialized = True
if(update == self.FULL_UPDATE): if(update == self.FULL_UPDATE):
self.ReadBusy() self.ReadBusy()
self.send_command(0x12) # soft reset self.send_command(0x12) # soft reset