@@ -125,7 +125,8 @@ class SubRevision(Enum):
125
125
UNKNOWN = ""
126
126
REV_2INCH = "chs_21inch"
127
127
REV_5INCH = "chs_5inch"
128
- REV_8INCH = "chs_88inch"
128
+ REV_8INCH_V88 = "chs_88inch.dev1_rom1.88"
129
+ REV_8INCH_V90 = "chs_88inch.dev1_rom1.90"
129
130
130
131
def __init__ (self , command ):
131
132
self .command = command
@@ -216,33 +217,24 @@ def _hello(self):
216
217
self .serial_flush_input ()
217
218
logger .debug ("HW sub-revision returned: %s" % '' .join (filter (lambda x : x in set (string .printable ), response )))
218
219
219
- # Note: sub-revisions returned by display are not reliable e.g. 2.1" displays return "chs_5inch"
220
- # if response.startswith(SubRevision.REV_5INCH.value):
221
- # self.sub_revision = SubRevision.REV_5INCH
222
- # self.display_width = 480
223
- # self.display_height = 800
224
- # elif response.startswith(SubRevision.REV_2INCH.value):
225
- # self.sub_revision = SubRevision.REV_2INCH
226
- # self.display_width = 480
227
- # self.display_height = 480
228
- # elif response.startswith(SubRevision.REV_8INCH.value):
229
- # self.sub_revision = SubRevision.REV_8INCH
230
- # self.display_width = 480
231
- # self.display_height = 1920
232
- # else:
233
- # logger.warning("Display returned unknown sub-revision on Hello answer (%s)" % str(response))
234
- # logger.debug("HW sub-revision detected: %s" % (str(self.sub_revision)))
235
-
236
- # Relay on width/height for sub-revision detection
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
237
222
if self .display_width == 480 and self .display_height == 480 :
238
223
self .sub_revision = SubRevision .REV_2INCH
239
224
elif self .display_width == 480 and self .display_height == 800 :
240
225
self .sub_revision = SubRevision .REV_5INCH
241
226
elif self .display_width == 480 and self .display_height == 1920 :
242
- self .sub_revision = SubRevision .REV_8INCH
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 ))
243
233
else :
244
234
logger .error (f"Unsupported resolution { self .display_width } x{ self .display_height } for revision C" )
245
235
236
+ logger .debug ("HW sub-revision detected: %s" % (str (self .sub_revision )))
237
+
246
238
def InitializeComm (self ):
247
239
self ._hello ()
248
240
@@ -293,12 +285,12 @@ def SetOrientation(self, orientation: Orientation = Orientation.PORTRAIT):
293
285
self .orientation = orientation
294
286
# logger.info(f"Call SetOrientation to: {self.orientation.name}")
295
287
296
- if self .orientation == Orientation .REVERSE_LANDSCAPE or self .orientation == Orientation .REVERSE_PORTRAIT :
297
- b = Command .STARTMODE_DEFAULT .value + Padding .NULL .value + Command .FLIP_180 .value + SleepInterval .OFF .value
298
- self ._send_command (Command .OPTIONS , payload = b )
299
- else :
300
- b = Command .STARTMODE_DEFAULT .value + Padding .NULL .value + Command .NO_FLIP .value + SleepInterval .OFF .value
301
- self ._send_command (Command .OPTIONS , payload = b )
288
+ # if self.orientation == Orientation.REVERSE_LANDSCAPE or self.orientation == Orientation.REVERSE_PORTRAIT:
289
+ # b = Command.STARTMODE_DEFAULT.value + Padding.NULL.value + Command.FLIP_180.value + SleepInterval.OFF.value
290
+ # self._send_command(Command.OPTIONS, payload=b)
291
+ # else:
292
+ b = Command .STARTMODE_DEFAULT .value + Padding .NULL .value + Command .NO_FLIP .value + SleepInterval .OFF .value
293
+ self ._send_command (Command .OPTIONS , payload = b )
302
294
303
295
def DisplayPILImage (
304
296
self ,
@@ -336,11 +328,12 @@ def DisplayPILImage(
336
328
display_bmp_cmd = Command .DISPLAY_BITMAP_5INCH
337
329
elif self .sub_revision == SubRevision .REV_2INCH :
338
330
display_bmp_cmd = Command .DISPLAY_BITMAP_2INCH
339
- elif self .sub_revision == SubRevision .REV_8INCH :
331
+ elif self .sub_revision == SubRevision .REV_8INCH_V88 or self . sub_revision == SubRevision . REV_8INCH_V90 :
340
332
display_bmp_cmd = Command .DISPLAY_BITMAP_8INCH
341
333
342
334
self ._send_command (display_bmp_cmd ,
343
- payload = bytearray (int (self .display_width * self .display_width / 64 ).to_bytes (2 , "big" )))
335
+ payload = bytearray (
336
+ int (self .display_width * self .display_width / 64 ).to_bytes (2 , "big" )))
344
337
self ._send_command (Command .SEND_PAYLOAD ,
345
338
payload = bytearray (self ._generate_full_image (image )),
346
339
readsize = 1024 )
@@ -354,7 +347,7 @@ def DisplayPILImage(
354
347
Count .Start += 1
355
348
356
349
def _generate_full_image (self , image : Image .Image ) -> bytes :
357
- if self .sub_revision == SubRevision .REV_8INCH :
350
+ if self .sub_revision == SubRevision .REV_8INCH_V88 or self . sub_revision == SubRevision . REV_8INCH_V90 :
358
351
if self .orientation == Orientation .LANDSCAPE :
359
352
image = image .rotate (270 , expand = True )
360
353
elif self .orientation == Orientation .REVERSE_LANDSCAPE :
@@ -379,7 +372,7 @@ def _generate_update_image(
379
372
self , image : Image .Image , x : int , y : int , count : int , cmd : Optional [Command ] = None
380
373
) -> Tuple [bytearray , bytearray ]:
381
374
x0 , y0 = x , y
382
- if self .sub_revision == SubRevision .REV_8INCH :
375
+ if self .sub_revision == SubRevision .REV_8INCH_V88 or self . sub_revision == SubRevision . REV_8INCH_V90 :
383
376
if self .orientation == Orientation .LANDSCAPE :
384
377
image = image .rotate (270 , expand = True )
385
378
y0 = self .get_height () - y - image .width
@@ -409,9 +402,19 @@ def _generate_update_image(
409
402
y0 = x
410
403
411
404
img_raw_data = bytearray ()
412
- bgr_data = image_to_BGR (image )
413
- for h , line in enumerate (chunked (bgr_data , image .width * 3 )):
414
- if self .sub_revision == SubRevision .REV_8INCH :
405
+
406
+ # Some screens require BGR for update image, some require BGRA
407
+ if self .sub_revision == SubRevision .REV_8INCH_V90 :
408
+ # BGRA mode
409
+ img_data = image_to_BGRA (image )
410
+ pixel_size = 4
411
+ else :
412
+ # BGR mode
413
+ img_data = image_to_BGR (image )
414
+ pixel_size = 3
415
+
416
+ 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 :
415
418
img_raw_data += int (((x0 + h ) * self .display_width ) + y0 ).to_bytes (3 , "big" )
416
419
else :
417
420
img_raw_data += int (((x0 + h ) * self .display_height ) + y0 ).to_bytes (3 , "big" )
0 commit comments