MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / EPDHelper

Class EPDHelper

epd_helper.py:27–157  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25 "max7219_8panel",
26]
27
28class EPDHelper:
29 def __init__(self, epd_type):
30 self.epd_type = epd_type
31 self.epd = self._load_epd_module()
32
33 def _load_epd_module(self):
34 try:
35 epd_module_name = f'resources.waveshare_epd.{self.epd_type}'
36 epd_module = importlib.import_module(epd_module_name)
37 return epd_module.EPD()
38 except ImportError as e:
39 logger.error(f"EPD module {self.epd_type} not found: {e}")
40 raise
41 except Exception as e:
42 logger.error(f"Error loading EPD module {self.epd_type}: {e}")
43 raise
44
45 def init_full_update(self):
46 try:
47 if hasattr(self.epd, 'FULL_UPDATE'):
48 self.epd.init(self.epd.FULL_UPDATE)
49 elif hasattr(self.epd, 'lut_full_update'):
50 self.epd.init(self.epd.lut_full_update)
51 else:
52 self.epd.init()
53 logger.info("EPD full update initialization complete.")
54 except Exception as e:
55 logger.error(f"Error initializing EPD for full update: {e}")
56 raise
57
58 def init_partial_update(self):
59 try:
60 if hasattr(self.epd, 'PART_UPDATE'):
61 self.epd.init(self.epd.PART_UPDATE)
62 elif hasattr(self.epd, 'lut_partial_update'):
63 self.epd.init(self.epd.lut_partial_update)
64 else:
65 self.epd.init()
66 logger.info("EPD partial update initialization complete.")
67 except Exception as e:
68 logger.error(f"Error initializing EPD for partial update: {e}")
69 raise
70
71 def display_partial(self, image):
72 try:
73 imw, imh = image.size
74 epd_w, epd_h = self.epd.width, self.epd.height
75
76 # Ensure image matches EPD dimensions before sending to driver
77 # Allow swapped dimensions (90°/270° rotation) — getbuffer handles both orientations
78 if (imw != epd_w or imh != epd_h) and (imw != epd_h or imh != epd_w):
79 logger.warning(f"Image size {imw}x{imh} != EPD size {epd_w}x{epd_h}, resizing")
80 image = image.resize((epd_w, epd_h))
81
82 buf = self.epd.getbuffer(image)
83
84 if hasattr(self.epd, 'displayPartial'):

Callers 3

wipe_displayFunction · 0.90
auto_detectMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected