Skip to content

Commit 55c5006

Browse files
committed
Refactor supported device detection (#71)
1 parent 3faf7a2 commit 55c5006

File tree

1 file changed

+22
-41
lines changed

1 file changed

+22
-41
lines changed

epdlib/Screen.py

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def _load_hd(self, epd, timeout=20):
440440
clear_args: [arg1: val, arg2: val],
441441
constants: None
442442
'''
443-
443+
444444
from IT8951.display import AutoEPDDisplay
445445
from IT8951 import constants as constants_HD
446446

@@ -467,7 +467,8 @@ def _load_hd(self, epd, timeout=20):
467467
'screen_type': screen_type,
468468
'constants': constants_HD}
469469

470-
def _load_non_hd(self, epd):
470+
@staticmethod
471+
def _load_non_hd(epd):
471472
'''configure non IT8951 SPI epd
472473
473474
For a complete list see the list_compatible_modules() functon
@@ -494,7 +495,7 @@ def _load_non_hd(self, epd):
494495
non_hd = []
495496
for i in pkgutil.iter_modules(waveshare_epd.__path__):
496497
non_hd.append(i.name)
497-
498+
498499
if epd in non_hd:
499500
try:
500501
myepd = import_module(f'waveshare_epd.{epd}')
@@ -514,7 +515,7 @@ def _load_non_hd(self, epd):
514515
raise ScreenError(f'{epd} has an unsupported `EPD.Clear()` function and is not usable with this module ')
515516

516517
color_default = clear_sig.parameters.get('color', False)
517-
518+
518519
# it appears that not all of the older waveshare epd screens have
519520
# a default `color` parameter. For those use constants.CLEAR_COLOR (0xFF)
520521
if color_default:
@@ -665,7 +666,7 @@ def _full_writeEPD_hd(self, image):
665666
def _full_writeEPD_non_hd(self, image):
666667
'''wipe screen and write an image'''
667668
if self.screen_type == ScreenType.FOUR_GRAYS:
668-
image_buffer = self.epd.getbuffer_4Gray(Screen.image_to_4_grays(image))
669+
image_buffer = self.epd.getbuffer_4Gray(self.image_to_4_grays(image))
669670
else:
670671
image_buffer = self.epd.getbuffer(image)
671672

@@ -814,46 +815,26 @@ def list_compatible_modules(print_modules=True, reasons=False):
814815
continue
815816

816817
try:
817-
myepd = import_module(f'waveshare_epd.{i.name}')
818+
myepd = Screen._load_non_hd(i.name)
818819

819-
except ModuleNotFoundError:
820-
reason.append(f'ModuleNotFound: {i.name}')
820+
except ScreenError as e:
821+
reason.append(f'ScreenError: {e}')
821822
myepd = None
822823
except Exception as e:
823824
reason.append(f'General Exception: {e}')
824825
myepd = None
825-
826-
try:
827-
if vars(myepd.EPD()).get('GREEN', False):
828-
mode = '"RGB" 7 Color'
829-
else:
830-
mode = '"1" 1 bit'
831-
except AttributeError as e:
832-
mode = 'Unsupported'
833-
834-
835-
try:
836-
clear_args_spec = inspect.getfullargspec(myepd.EPD.Clear)
837-
clear_args = clear_args_spec.args
838-
if len(clear_args) > 2:
839-
supported = False
840-
reason.append('Non-standard, unsupported `EPD.Clear()` function')
841-
mode = 'Unsupported'
842-
except AttributeError:
843-
supported = False
844-
mode = 'Unsupported'
845-
reason.append('AttributeError: module does not support `EPD.Clear()`')
846-
847-
try:
848-
display_args_spec = inspect.getfullargspec(myepd.EPD.display)
849-
display_args = display_args_spec.args
850-
except AttributeError:
826+
827+
if myepd == None:
851828
supported = False
852-
reason.append('AttributeError: module does not support standard `EPD.display()`')
853829
mode = 'Unsupported'
830+
elif myepd["screen_type"] == ScreenType.SEVEN_COLORS:
831+
mode = '"RGB" Color'
832+
elif myepd["screen_type"] == ScreenType.FOUR_GRAYS:
833+
mode = '"L" 2 bit grayscale'
834+
else:
835+
mode = '"1" 1 bit b/w'
854836

855-
856-
panels.append({'name': i.name,
837+
panels.append({'name': i.name,
857838
'clear_args': clear_args,
858839
'display_args': display_args,
859840
'supported': supported,
@@ -864,13 +845,13 @@ def list_compatible_modules(print_modules=True, reasons=False):
864845
'display_args': {},
865846
'supported': True,
866847
'reason': [],
867-
'mode': '"L" 8 bit'})
848+
'mode': '"L" 8 bit grayscale'})
868849

869850
if print_modules:
870-
print(f'|Screen |Supported |Mode |')
871-
print( '|:-----------------|:--------------|:-------------|')
851+
print(f'|Screen |Supported |Mode |')
852+
print( '|:-------------------|:---------|:-------------------|')
872853
for idx, i in enumerate(panels):
873-
print(f"|{idx:02d}. {i['name']:<14s}|{i['supported']!s: <15}|{i['mode']:<14s}|")
854+
print(f"|{idx:02d}. {i['name']:<16s}|{i['supported']!s: <10}|{i['mode']:<20s}|")
874855
if reasons:
875856
if not i['supported']:
876857
print(f' Issues:')

0 commit comments

Comments
 (0)