Skip to content

Commit eda5d3c

Browse files
committed
Add reverse orientation support for rev.B/flagship HW
1 parent 8447bad commit eda5d3c

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

library/lcd_comm_rev_a.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,10 @@ def DisplayPILImage(
154154
assert image_height > 0, 'Image width must be > 0'
155155
assert image_width > 0, 'Image height must be > 0'
156156

157-
self.SendCommand(Command.DISPLAY_BITMAP, x, y, x + image_width - 1, y + image_height - 1)
157+
(x0, y0) = (x, y)
158+
(x1, y1) = (x + image_width - 1, y + image_height - 1)
159+
160+
self.SendCommand(Command.DISPLAY_BITMAP, x0, y0, x1, y1)
158161

159162
pix = image.load()
160163
line = bytes()

library/lcd_comm_rev_b.py

+28-14
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class Command(IntEnum):
1414
SET_BRIGHTNESS = 0xCE # Sets the screen brightness
1515

1616

17+
# In revision B, basic orientations (portrait / landscape) are managed by the display
18+
# The reverse orientations (reverse portrait / reverse landscape) are software-managed
1719
class OrientationValueRevB(IntEnum):
1820
ORIENTATION_PORTRAIT = 0x0
1921
ORIENTATION_LANDSCAPE = 0x1
@@ -27,17 +29,11 @@ class SubRevision(IntEnum):
2729
A12 = 0xA12 # HW revision "flagship" - brightness 0-255
2830

2931

30-
def get_rev_b_orientation(orientation: Orientation) -> OrientationValueRevB:
31-
if orientation == Orientation.PORTRAIT or orientation == Orientation.REVERSE_PORTRAIT:
32-
return OrientationValueRevB.ORIENTATION_PORTRAIT
33-
else:
34-
return OrientationValueRevB.ORIENTATION_LANDSCAPE
35-
36-
3732
class LcdCommRevB(LcdComm):
3833
def __init__(self):
3934
self.openSerial()
40-
self.sub_revision = SubRevision.A01 # Will be detected later by Hello
35+
self.sub_revision = SubRevision.A01 # Run a Hello command to detect correct sub-rev.
36+
self.is_reverse_orientation = False # Can be updated later by setOrientation()
4137

4238
def __del__(self):
4339
try:
@@ -176,7 +172,16 @@ def SetBackplateLedColor(self, led_color: tuple[int, int, int] = THEME_DATA['dis
176172
logger.info("Only HW revision 'flagship' supports backplate LED color setting")
177173

178174
def SetOrientation(self, orientation: Orientation = get_theme_orientation()):
179-
self.SendCommand(Command.SET_ORIENTATION, payload=[get_rev_b_orientation(orientation)])
175+
# In revision B, basic orientations (portrait / landscape) are managed by the display
176+
# The reverse orientations (reverse portrait / reverse landscape) are software-managed
177+
178+
self.is_reverse_orientation = (
179+
orientation == Orientation.REVERSE_PORTRAIT or orientation == Orientation.REVERSE_LANDSCAPE)
180+
181+
if orientation == Orientation.PORTRAIT or orientation == Orientation.REVERSE_PORTRAIT:
182+
self.SendCommand(Command.SET_ORIENTATION, payload=[OrientationValueRevB.ORIENTATION_PORTRAIT])
183+
else:
184+
self.SendCommand(Command.SET_ORIENTATION, payload=[OrientationValueRevB.ORIENTATION_LANDSCAPE])
180185

181186
def DisplayPILImage(
182187
self,
@@ -202,8 +207,12 @@ def DisplayPILImage(
202207
assert image_height > 0, 'Image width must be > 0'
203208
assert image_width > 0, 'Image height must be > 0'
204209

205-
(x0, y0) = (x, y)
206-
(x1, y1) = (x + image_width - 1, y + image_height - 1)
210+
if not self.is_reverse_orientation:
211+
(x0, y0) = (x, y)
212+
(x1, y1) = (x + image_width - 1, y + image_height - 1)
213+
else:
214+
(x0, y0) = (get_width() - x - image_width, get_height() - y - image_height)
215+
(x1, y1) = (get_width() - x - 1, get_height() - y - 1)
207216

208217
self.SendCommand(Command.DISPLAY_BITMAP,
209218
payload=[(x0 >> 8) & 255, x0 & 255,
@@ -217,9 +226,14 @@ def DisplayPILImage(
217226
with config.update_queue_mutex:
218227
for h in range(image_height):
219228
for w in range(image_width):
220-
R = pix[w, h][0] >> 3
221-
G = pix[w, h][1] >> 2
222-
B = pix[w, h][2] >> 3
229+
if not self.is_reverse_orientation:
230+
R = pix[w, h][0] >> 3
231+
G = pix[w, h][1] >> 2
232+
B = pix[w, h][2] >> 3
233+
else:
234+
R = pix[image_width - w - 1, image_height - h - 1][0] >> 3
235+
G = pix[image_width - w - 1, image_height - h - 1][1] >> 2
236+
B = pix[image_width - w - 1, image_height - h - 1][2] >> 3
223237

224238
# Revision A: 0bRRRRRGGGGGGBBBBB
225239
# fedcba9876543210

0 commit comments

Comments
 (0)