@@ -125,7 +125,8 @@ class SubRevision(Enum):
125125 UNKNOWN = ""
126126 REV_2INCH = "chs_21inch"
127127 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"
129130
130131 def __init__ (self , command ):
131132 self .command = command
@@ -216,33 +217,24 @@ def _hello(self):
216217 self .serial_flush_input ()
217218 logger .debug ("HW sub-revision returned: %s" % '' .join (filter (lambda x : x in set (string .printable ), response )))
218219
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
237222 if self .display_width == 480 and self .display_height == 480 :
238223 self .sub_revision = SubRevision .REV_2INCH
239224 elif self .display_width == 480 and self .display_height == 800 :
240225 self .sub_revision = SubRevision .REV_5INCH
241226 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 ))
243233 else :
244234 logger .error (f"Unsupported resolution { self .display_width } x{ self .display_height } for revision C" )
245235
236+ logger .debug ("HW sub-revision detected: %s" % (str (self .sub_revision )))
237+
246238 def InitializeComm (self ):
247239 self ._hello ()
248240
@@ -293,12 +285,12 @@ def SetOrientation(self, orientation: Orientation = Orientation.PORTRAIT):
293285 self .orientation = orientation
294286 # logger.info(f"Call SetOrientation to: {self.orientation.name}")
295287
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 )
302294
303295 def DisplayPILImage (
304296 self ,
@@ -336,11 +328,12 @@ def DisplayPILImage(
336328 display_bmp_cmd = Command .DISPLAY_BITMAP_5INCH
337329 elif self .sub_revision == SubRevision .REV_2INCH :
338330 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 :
340332 display_bmp_cmd = Command .DISPLAY_BITMAP_8INCH
341333
342334 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" )))
344337 self ._send_command (Command .SEND_PAYLOAD ,
345338 payload = bytearray (self ._generate_full_image (image )),
346339 readsize = 1024 )
@@ -354,7 +347,7 @@ def DisplayPILImage(
354347 Count .Start += 1
355348
356349 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 :
358351 if self .orientation == Orientation .LANDSCAPE :
359352 image = image .rotate (270 , expand = True )
360353 elif self .orientation == Orientation .REVERSE_LANDSCAPE :
@@ -379,7 +372,7 @@ def _generate_update_image(
379372 self , image : Image .Image , x : int , y : int , count : int , cmd : Optional [Command ] = None
380373 ) -> Tuple [bytearray , bytearray ]:
381374 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 :
383376 if self .orientation == Orientation .LANDSCAPE :
384377 image = image .rotate (270 , expand = True )
385378 y0 = self .get_height () - y - image .width
@@ -409,9 +402,19 @@ def _generate_update_image(
409402 y0 = x
410403
411404 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 :
415418 img_raw_data += int (((x0 + h ) * self .display_width ) + y0 ).to_bytes (3 , "big" )
416419 else :
417420 img_raw_data += int (((x0 + h ) * self .display_height ) + y0 ).to_bytes (3 , "big" )
0 commit comments