Skip to content

Commit

Permalink
add option to mirror display
Browse files Browse the repository at this point in the history
  • Loading branch information
GregDMeyer committed May 2, 2022
1 parent 04eee06 commit 2a81167
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
26 changes: 17 additions & 9 deletions IT8951/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class AutoDisplay:
rotation---they will be swapped automatically if rotate is set to CW or CCW
'''

def __init__(self, width, height, rotate=None, track_gray=False):
self._set_rotate(rotate)
def __init__(self, width, height, rotate=None, mirror=False, track_gray=False):
self._set_rotate(rotate, mirror)

self.display_dims = (width, height)
if rotate in ('CW', 'CCW'):
Expand Down Expand Up @@ -61,14 +61,22 @@ def _get_frame_buf(self):

return self.frame_buf.transpose(self._rotate_method)

def _set_rotate(self, rotate):
def _set_rotate(self, rotate, mirror):

methods = {
None : None,
'CW' : Image.ROTATE_270,
'CCW' : Image.ROTATE_90,
'flip' : Image.ROTATE_180,
}
if not mirror:
methods = {
None : None,
'CW' : Image.Transpose.ROTATE_270,
'CCW' : Image.Transpose.ROTATE_90,
'flip' : Image.Transpose.ROTATE_180,
}
else:
methods = {
None : Image.Transpose.FLIP_LEFT_RIGHT,
'CW' : Image.Transpose.TRANSPOSE,
'CCW' : Image.Transpose.TRANSVERSE,
'flip' : Image.Transpose.FLIP_TOP_BOTTOM,
}

if rotate not in methods:
raise ValueError("invalid value for 'rotate'---options are None, 'CW', 'CCW', and 'flip'")
Expand Down
6 changes: 4 additions & 2 deletions test/integration/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def parse_args():
'physical device)')
p.add_argument('-r', '--rotate', default=None, choices=['CW', 'CCW', 'flip'],
help='run the tests with the display rotated by the specified value')
p.add_argument('-m', '--mirror', action='store_true',
help='Mirror the display (use this if text appears backwards)')
return p.parse_args()

def main():
Expand All @@ -29,15 +31,15 @@ def main():
# value means faster display refreshes. the documentation for the IT8951 device
# says the max is 24 MHz (24000000), but my device seems to still work as high as
# 80 MHz (80000000)
display = AutoEPDDisplay(vcom=-2.06, rotate=args.rotate, spi_hz=24000000)
display = AutoEPDDisplay(vcom=-2.15, rotate=args.rotate, mirror=args.mirror, spi_hz=24000000)

print('VCOM set to', display.epd.get_vcom())

tests += [print_system_info]

else:
from IT8951.display import VirtualEPDDisplay
display = VirtualEPDDisplay(dims=(800, 600), rotate=args.rotate)
display = VirtualEPDDisplay(dims=(800, 600), rotate=args.rotate, mirror=args.mirror)

tests += [
clear_display,
Expand Down

0 comments on commit 2a81167

Please sign in to comment.