@@ -211,7 +211,7 @@ def _hello(self):
211211 # This command reads LCD answer on serial link, so it bypasses the queue
212212 self .sub_revision = SubRevision .UNKNOWN
213213 self ._send_command (Command .HELLO , bypass_queue = True )
214- response = str (self .serial_read (23 ).decode ())
214+ response = str (self .serial_read (23 ).decode (errors = "ignore" ))
215215 self .serial_flush_input ()
216216 logger .debug ("HW sub-revision returned: %s" % '' .join (filter (lambda x : x in set (string .printable ), response )))
217217
@@ -292,12 +292,12 @@ def SetOrientation(self, orientation: Orientation = Orientation.PORTRAIT):
292292 self .orientation = orientation
293293 # logger.info(f"Call SetOrientation to: {self.orientation.name}")
294294
295- if self .orientation == Orientation .REVERSE_LANDSCAPE or self .orientation == Orientation .REVERSE_PORTRAIT :
296- b = Command .STARTMODE_DEFAULT .value + Padding .NULL .value + Command .FLIP_180 .value + SleepInterval .OFF .value
297- self ._send_command (Command .OPTIONS , payload = b )
298- else :
299- b = Command .STARTMODE_DEFAULT .value + Padding .NULL .value + Command .NO_FLIP .value + SleepInterval .OFF .value
300- self ._send_command (Command .OPTIONS , payload = b )
295+ # if self.orientation == Orientation.REVERSE_LANDSCAPE or self.orientation == Orientation.REVERSE_PORTRAIT:
296+ # b = Command.STARTMODE_DEFAULT.value + Padding.NULL.value + Command.FLIP_180.value + SleepInterval.OFF.value
297+ # self._send_command(Command.OPTIONS, payload=b)
298+ # else:
299+ # b = Command.STARTMODE_DEFAULT.value + Padding.NULL.value + Command.NO_FLIP.value + SleepInterval.OFF.value
300+ # self._send_command(Command.OPTIONS, payload=b)
301301
302302 def DisplayPILImage (
303303 self ,
@@ -353,12 +353,22 @@ def DisplayPILImage(
353353 Count .Start += 1
354354
355355 def _generate_full_image (self , image : Image .Image ) -> bytes :
356- if self .orientation == Orientation .PORTRAIT :
357- image = image .rotate (90 , expand = True )
358- elif self .orientation == Orientation .REVERSE_PORTRAIT :
359- image = image .rotate (270 , expand = True )
360- elif self .orientation == Orientation .REVERSE_LANDSCAPE :
361- image = image .rotate (180 )
356+ if self .sub_revision == SubRevision .REV_8INCH :
357+ if self .orientation == Orientation .LANDSCAPE :
358+ image = image .rotate (270 , expand = True )
359+ elif self .orientation == Orientation .REVERSE_LANDSCAPE :
360+ image = image .rotate (90 , expand = True )
361+ elif self .orientation == Orientation .PORTRAIT :
362+ image = image .rotate (180 , expand = True )
363+ elif self .orientation == Orientation .REVERSE_PORTRAIT :
364+ pass
365+ else :
366+ if self .orientation == Orientation .PORTRAIT :
367+ image = image .rotate (90 , expand = True )
368+ elif self .orientation == Orientation .REVERSE_PORTRAIT :
369+ image = image .rotate (270 , expand = True )
370+ elif self .orientation == Orientation .REVERSE_LANDSCAPE :
371+ image = image .rotate (180 )
362372
363373 bgra_data = image_to_BGRA (image )
364374
@@ -368,24 +378,42 @@ def _generate_update_image(
368378 self , image : Image .Image , x : int , y : int , count : int , cmd : Optional [Command ] = None
369379 ) -> Tuple [bytearray , bytearray ]:
370380 x0 , y0 = x , y
371-
372- if self .orientation == Orientation .PORTRAIT :
373- image = image .rotate (90 , expand = True )
374- x0 = self .get_width () - x - image .height
375- elif self .orientation == Orientation .REVERSE_PORTRAIT :
376- image = image .rotate (270 , expand = True )
377- y0 = self .get_height () - y - image .width
378- elif self .orientation == Orientation .REVERSE_LANDSCAPE :
379- image = image .rotate (180 , expand = True )
380- y0 = self .get_width () - x - image .width
381- x0 = self .get_height () - y - image .height
382- elif self .orientation == Orientation .LANDSCAPE :
383- x0 , y0 = y , x
381+ if self .sub_revision == SubRevision .REV_8INCH :
382+ if self .orientation == Orientation .LANDSCAPE :
383+ image = image .rotate (270 , expand = True )
384+ elif self .orientation == Orientation .REVERSE_LANDSCAPE :
385+ image = image .rotate (90 , expand = True )
386+ x0 = self .get_width () - x - image .height
387+ y0 = self .get_height () - y - image .width
388+ elif self .orientation == Orientation .PORTRAIT :
389+ image = image .rotate (180 , expand = True )
390+ x0 = self .get_height () - y - image .height
391+ y0 = self .get_height () - x - image .width
392+ elif self .orientation == Orientation .REVERSE_PORTRAIT :
393+ x0 = y
394+ y0 = x
395+ else :
396+ if self .orientation == Orientation .PORTRAIT :
397+ image = image .rotate (90 , expand = True )
398+ x0 = self .get_width () - x - image .height
399+ elif self .orientation == Orientation .REVERSE_PORTRAIT :
400+ image = image .rotate (270 , expand = True )
401+ y0 = self .get_height () - y - image .width
402+ elif self .orientation == Orientation .REVERSE_LANDSCAPE :
403+ image = image .rotate (180 )
404+ y0 = self .get_width () - x - image .width
405+ x0 = self .get_height () - y - image .height
406+ elif self .orientation == Orientation .LANDSCAPE :
407+ x0 = y
408+ y0 = x
384409
385410 img_raw_data = bytearray ()
386411 bgr_data = image_to_BGR (image )
387412 for h , line in enumerate (chunked (bgr_data , image .width * 3 )):
388- img_raw_data += int (((x0 + h ) * self .display_height ) + y0 ).to_bytes (3 , "big" )
413+ if self .sub_revision == SubRevision .REV_8INCH :
414+ img_raw_data += int (((x0 + h ) * self .display_width ) + y0 ).to_bytes (3 , "big" )
415+ else :
416+ img_raw_data += int (((x0 + h ) * self .display_height ) + y0 ).to_bytes (3 , "big" )
389417 img_raw_data += int (image .width ).to_bytes (2 , "big" )
390418 img_raw_data += line
391419
0 commit comments