mirror of
https://github.com/infinition/Bjorn.git
synced 2025-12-07 21:24:59 +00:00
Update epd2in13_V3.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:
@@ -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
|
||||||
@@ -200,33 +201,41 @@ class EPD:
|
|||||||
parameter:
|
parameter:
|
||||||
'''
|
'''
|
||||||
def init(self, update=None):
|
def init(self, update=None):
|
||||||
|
# Prevent reinitialization if already initialized #INFINITION
|
||||||
|
if self.is_initialized:
|
||||||
|
logger.debug("EPD is already initialized. Skipping redundant init.")
|
||||||
|
return 0
|
||||||
|
|
||||||
if update is None:
|
if update is None:
|
||||||
update = self.FULL_UPDATE
|
update = self.FULL_UPDATE
|
||||||
|
|
||||||
|
# Initialize the module
|
||||||
if epdconfig.module_init() != 0:
|
if epdconfig.module_init() != 0:
|
||||||
|
logger.error("Failed to initialize module")
|
||||||
return -1
|
return -1
|
||||||
# EPD hardware init start
|
|
||||||
|
# EPD hardware initialization start
|
||||||
self.reset()
|
self.reset()
|
||||||
|
|
||||||
self.ReadBusy()
|
self.ReadBusy()
|
||||||
self.send_command(0x12) #SWRESET
|
self.send_command(0x12) # SWRESET
|
||||||
self.ReadBusy()
|
self.ReadBusy()
|
||||||
|
|
||||||
self.send_command(0x01) #Driver output control
|
self.send_command(0x01) # Driver output control
|
||||||
self.send_data(0xf9)
|
self.send_data(0xf9)
|
||||||
self.send_data(0x00)
|
self.send_data(0x00)
|
||||||
self.send_data(0x00)
|
self.send_data(0x00)
|
||||||
|
|
||||||
self.send_command(0x11) #data entry mode
|
self.send_command(0x11) # Data entry mode
|
||||||
self.send_data(0x03)
|
self.send_data(0x03)
|
||||||
|
|
||||||
self.SetWindow(0, 0, self.width-1, self.height-1)
|
self.SetWindow(0, 0, self.width - 1, self.height - 1)
|
||||||
self.SetCursor(0, 0)
|
self.SetCursor(0, 0)
|
||||||
|
|
||||||
self.send_command(0x3c)
|
self.send_command(0x3c)
|
||||||
self.send_data(0x05)
|
self.send_data(0x05)
|
||||||
|
|
||||||
self.send_command(0x21) # Display update control
|
self.send_command(0x21) # Display update control
|
||||||
self.send_data(0x00)
|
self.send_data(0x00)
|
||||||
self.send_data(0x80)
|
self.send_data(0x80)
|
||||||
|
|
||||||
@@ -236,6 +245,10 @@ class EPD:
|
|||||||
self.ReadBusy()
|
self.ReadBusy()
|
||||||
|
|
||||||
self.SetLut(self.lut_full_update)
|
self.SetLut(self.lut_full_update)
|
||||||
|
|
||||||
|
# Mark the EPD as initialized #INFINITION
|
||||||
|
self.is_initialized = True
|
||||||
|
logger.info("EPD initialized successfully")
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|||||||
Reference in New Issue
Block a user