@@ -92,17 +92,11 @@ class Command(Enum):
92
92
NO_FLIP = bytearray ((0x00 ,))
93
93
SEND_PAYLOAD = bytearray ((0xFF ,))
94
94
95
- def __init__ (self , command ):
96
- self .command = command
97
-
98
95
99
96
class Padding (Enum ):
100
97
NULL = bytearray ([0x00 ])
101
98
START_DISPLAY_BITMAP = bytearray ([0x2c ])
102
99
103
- def __init__ (self , command ):
104
- self .command = command
105
-
106
100
107
101
class SleepInterval (Enum ):
108
102
OFF = bytearray ((0x00 ,))
@@ -117,19 +111,12 @@ class SleepInterval(Enum):
117
111
NINE = bytearray ((0x09 ,))
118
112
TEN = bytearray ((0x0a ,))
119
113
120
- def __init__ (self , command ):
121
- self .command = command
122
-
123
114
124
115
class SubRevision (Enum ):
125
116
UNKNOWN = ""
126
117
REV_2INCH = "chs_21inch"
127
118
REV_5INCH = "chs_5inch"
128
- REV_8INCH_V88 = "chs_88inch.dev1_rom1.88"
129
- REV_8INCH_V90 = "chs_88inch.dev1_rom1.90"
130
-
131
- def __init__ (self , command ):
132
- self .command = command
119
+ REV_8INCH = "chs_88inch"
133
120
134
121
135
122
# This class is for Turing Smart Screen 2.1" / 5" / 8" screens
@@ -213,27 +200,32 @@ def _hello(self):
213
200
# This command reads LCD answer on serial link, so it bypasses the queue
214
201
self .sub_revision = SubRevision .UNKNOWN
215
202
self ._send_command (Command .HELLO , bypass_queue = True )
216
- response = str (self .serial_read (23 ).decode (errors = "ignore" ))
203
+ response = '' . join ( filter ( lambda x : x in set ( string . printable ), str (self .serial_read (23 ).decode (errors = "ignore" )) ))
217
204
self .serial_flush_input ()
218
- logger .debug ("HW sub-revision returned: %s" % '' . join ( filter ( lambda x : x in set ( string . printable ), response )) )
205
+ logger .debug ("Display ID returned: %s" % response )
219
206
220
- # Note: sub-revisions returned by display are not reliable for some models e.g. 2.1" displays return "chs_5inch"
221
- # Relay mainly on width/height for sub-revision detection, except for 8.8" where ROM version matters
207
+ # Note: ID returned by display are not reliable for some models e.g. 2.1" displays return "chs_5inch"
208
+ # Rely on width/height for sub-revision detection
222
209
if self .display_width == 480 and self .display_height == 480 :
223
210
self .sub_revision = SubRevision .REV_2INCH
224
211
elif self .display_width == 480 and self .display_height == 800 :
225
212
self .sub_revision = SubRevision .REV_5INCH
226
213
elif self .display_width == 480 and self .display_height == 1920 :
227
- if response .startswith (SubRevision .REV_8INCH_V88 .value ):
228
- self .sub_revision = SubRevision .REV_8INCH_V88
229
- elif response .startswith (SubRevision .REV_8INCH_V90 .value ):
230
- self .sub_revision = SubRevision .REV_8INCH_V90
231
- else :
232
- logger .warning ("Display returned unknown sub-revision on Hello answer (%s)" % str (response ))
214
+ self .sub_revision = SubRevision .REV_8INCH
233
215
else :
234
216
logger .error (f"Unsupported resolution { self .display_width } x{ self .display_height } for revision C" )
235
217
236
- logger .debug ("HW sub-revision detected: %s" % (str (self .sub_revision )))
218
+ # Detect ROM version
219
+ try :
220
+ self .rom_version = int (response .split ("." )[2 ])
221
+ if self .rom_version < 80 or self .rom_version > 100 :
222
+ logger .warning ("ROM version %d may be invalid, use default ROM version 87" % self .rom_version )
223
+ self .rom_version = 87
224
+ except :
225
+ logger .warning ("Display returned invalid or unsupported ID on Hello answer, use default ROM version 87" )
226
+ self .rom_version = 87
227
+
228
+ logger .debug ("HW sub-revision detected: %s, ROM version: %d" % ((str (self .sub_revision )), self .rom_version ))
237
229
238
230
def InitializeComm (self ):
239
231
self ._hello ()
@@ -328,7 +320,7 @@ def DisplayPILImage(
328
320
display_bmp_cmd = Command .DISPLAY_BITMAP_5INCH
329
321
elif self .sub_revision == SubRevision .REV_2INCH :
330
322
display_bmp_cmd = Command .DISPLAY_BITMAP_2INCH
331
- elif self .sub_revision == SubRevision .REV_8INCH_V88 or self . sub_revision == SubRevision . REV_8INCH_V90 :
323
+ elif self .sub_revision == SubRevision .REV_8INCH :
332
324
display_bmp_cmd = Command .DISPLAY_BITMAP_8INCH
333
325
334
326
self ._send_command (display_bmp_cmd ,
@@ -347,7 +339,8 @@ def DisplayPILImage(
347
339
Count .Start += 1
348
340
349
341
def _generate_full_image (self , image : Image .Image ) -> bytes :
350
- if self .sub_revision == SubRevision .REV_8INCH_V88 or self .sub_revision == SubRevision .REV_8INCH_V90 :
342
+ if self .sub_revision == SubRevision .REV_8INCH :
343
+ # Switch landscape/portrait mode for 8"
351
344
if self .orientation == Orientation .LANDSCAPE :
352
345
image = image .rotate (270 , expand = True )
353
346
elif self .orientation == Orientation .REVERSE_LANDSCAPE :
@@ -372,7 +365,8 @@ def _generate_update_image(
372
365
self , image : Image .Image , x : int , y : int , count : int , cmd : Optional [Command ] = None
373
366
) -> Tuple [bytearray , bytearray ]:
374
367
x0 , y0 = x , y
375
- if self .sub_revision == SubRevision .REV_8INCH_V88 or self .sub_revision == SubRevision .REV_8INCH_V90 :
368
+ if self .sub_revision == SubRevision .REV_8INCH :
369
+ # Switch landscape/portrait mode for 8"
376
370
if self .orientation == Orientation .LANDSCAPE :
377
371
image = image .rotate (270 , expand = True )
378
372
y0 = self .get_height () - y - image .width
@@ -404,7 +398,7 @@ def _generate_update_image(
404
398
img_raw_data = bytearray ()
405
399
406
400
# Some screens require BGR for update image, some require BGRA
407
- if self .sub_revision == SubRevision . REV_8INCH_V90 :
401
+ if self .rom_version > 88 :
408
402
# BGRA mode
409
403
img_data = image_to_BGRA (image )
410
404
pixel_size = 4
@@ -414,7 +408,8 @@ def _generate_update_image(
414
408
pixel_size = 3
415
409
416
410
for h , line in enumerate (chunked (img_data , image .width * pixel_size )):
417
- if self .sub_revision == SubRevision .REV_8INCH_V88 or self .sub_revision == SubRevision .REV_8INCH_V90 :
411
+ if self .sub_revision == SubRevision .REV_8INCH :
412
+ # Switch landscape/portrait mode for 8"
418
413
img_raw_data += int (((x0 + h ) * self .display_width ) + y0 ).to_bytes (3 , "big" )
419
414
else :
420
415
img_raw_data += int (((x0 + h ) * self .display_height ) + y0 ).to_bytes (3 , "big" )
0 commit comments