-
-
Notifications
You must be signed in to change notification settings - Fork 125
/
epd_helper.py
68 lines (60 loc) · 2.27 KB
/
epd_helper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# epd_helper.py
import importlib
import logging
logger = logging.getLogger(__name__)
class EPDHelper:
def __init__(self, epd_type):
self.epd_type = epd_type
self.epd = self._load_epd_module()
def _load_epd_module(self):
try:
epd_module_name = f'resources.waveshare_epd.{self.epd_type}'
epd_module = importlib.import_module(epd_module_name)
return epd_module.EPD()
except ImportError as e:
logger.error(f"EPD module {self.epd_type} not found: {e}")
raise
except Exception as e:
logger.error(f"Error loading EPD module {self.epd_type}: {e}")
raise
def init_full_update(self):
try:
if hasattr(self.epd, 'FULL_UPDATE'):
self.epd.init(self.epd.FULL_UPDATE)
elif hasattr(self.epd, 'lut_full_update'):
self.epd.init(self.epd.lut_full_update)
else:
self.epd.init()
logger.info("EPD full update initialization complete.")
except Exception as e:
logger.error(f"Error initializing EPD for full update: {e}")
raise
def init_partial_update(self):
try:
if hasattr(self.epd, 'PART_UPDATE'):
self.epd.init(self.epd.PART_UPDATE)
elif hasattr(self.epd, 'lut_partial_update'):
self.epd.init(self.epd.lut_partial_update)
else:
self.epd.init()
logger.info("EPD partial update initialization complete.")
except Exception as e:
logger.error(f"Error initializing EPD for partial update: {e}")
raise
def display_partial(self, image):
try:
if hasattr(self.epd, 'displayPartial'):
self.epd.displayPartial(self.epd.getbuffer(image))
else:
self.epd.display(self.epd.getbuffer(image))
logger.info("Partial display update complete.")
except Exception as e:
logger.error(f"Error during partial display update: {e}")
raise
def clear(self):
try:
self.epd.Clear()
logger.info("EPD cleared.")
except Exception as e:
logger.error(f"Error clearing EPD: {e}")
raise