@@ -14,6 +14,8 @@ class Command(IntEnum):
14
14
SET_BRIGHTNESS = 0xCE # Sets the screen brightness
15
15
16
16
17
+ # In revision B, basic orientations (portrait / landscape) are managed by the display
18
+ # The reverse orientations (reverse portrait / reverse landscape) are software-managed
17
19
class OrientationValueRevB (IntEnum ):
18
20
ORIENTATION_PORTRAIT = 0x0
19
21
ORIENTATION_LANDSCAPE = 0x1
@@ -27,17 +29,11 @@ class SubRevision(IntEnum):
27
29
A12 = 0xA12 # HW revision "flagship" - brightness 0-255
28
30
29
31
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
-
37
32
class LcdCommRevB (LcdComm ):
38
33
def __init__ (self ):
39
34
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()
41
37
42
38
def __del__ (self ):
43
39
try :
@@ -176,7 +172,16 @@ def SetBackplateLedColor(self, led_color: tuple[int, int, int] = THEME_DATA['dis
176
172
logger .info ("Only HW revision 'flagship' supports backplate LED color setting" )
177
173
178
174
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 ])
180
185
181
186
def DisplayPILImage (
182
187
self ,
@@ -202,8 +207,12 @@ def DisplayPILImage(
202
207
assert image_height > 0 , 'Image width must be > 0'
203
208
assert image_width > 0 , 'Image height must be > 0'
204
209
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 )
207
216
208
217
self .SendCommand (Command .DISPLAY_BITMAP ,
209
218
payload = [(x0 >> 8 ) & 255 , x0 & 255 ,
@@ -217,9 +226,14 @@ def DisplayPILImage(
217
226
with config .update_queue_mutex :
218
227
for h in range (image_height ):
219
228
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
223
237
224
238
# Revision A: 0bRRRRRGGGGGGBBBBB
225
239
# fedcba9876543210
0 commit comments