@@ -146,7 +146,16 @@ def __del__(self):
146146 def auto_detect_com_port () -> Optional [str ]:
147147 com_ports = comports ()
148148
149- # Try to find awake device through serial number or vid/pid
149+ # First, try to find sleeping device and wake it up
150+ for com_port in com_ports :
151+ if com_port .serial_number == 'USB7INCH' or com_port .serial_number == 'CT21INCH' :
152+ LcdCommRevC ._connect_to_reset_device_name (com_port )
153+ return LcdCommRevC .auto_detect_com_port ()
154+ if com_port .vid == 0x1a86 and com_port .pid == 0xca21 :
155+ LcdCommRevC ._connect_to_reset_device_name (com_port )
156+ return LcdCommRevC .auto_detect_com_port ()
157+
158+ # Then try to find awake device through serial number or vid/pid
150159 for com_port in com_ports :
151160 if com_port .serial_number == '20080411' :
152161 return com_port .device
@@ -155,14 +164,6 @@ def auto_detect_com_port() -> Optional[str]:
155164 if com_port .vid == 0x1d6b and (com_port .pid == 0x0121 or com_port .pid == 0x0106 ):
156165 return com_port .device
157166
158- # Try to find sleeping device and wake it up
159- for com_port in com_ports :
160- if com_port .serial_number == 'USB7INCH' or com_port .serial_number == 'CT21INCH' :
161- LcdCommRevC ._connect_to_reset_device_name (com_port )
162- return LcdCommRevC .auto_detect_com_port ()
163- if com_port .serial_number == '20080411' :
164- return com_port .device
165-
166167 return None
167168
168169 @staticmethod
@@ -292,12 +293,12 @@ def SetOrientation(self, orientation: Orientation = Orientation.PORTRAIT):
292293 self .orientation = orientation
293294 # logger.info(f"Call SetOrientation to: {self.orientation.name}")
294295
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 )
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 )
301302
302303 def DisplayPILImage (
303304 self ,
0 commit comments