@@ -119,6 +119,9 @@ class SubRevision(Enum):
119119 REV_8INCH = "chs_88inch"
120120
121121
122+ WAKE_RETRIES = 15
123+
124+
122125# This class is for Turing Smart Screen 2.1" / 5" / 8" screens
123126class LcdCommRevC (LcdComm ):
124127 def __init__ (self , com_port : str = "AUTO" , display_width : int = 480 , display_height : int = 800 ,
@@ -132,22 +135,18 @@ def __del__(self):
132135
133136 @staticmethod
134137 def auto_detect_com_port () -> Optional [str ]:
135- com_ports = comports ()
136-
137- # First, try to find sleeping device and wake it up
138- for com_port in com_ports :
138+ # If sleeping device is detected through serial number or vid/pid, try to wake it up
139+ for com_port in comports ():
139140 if com_port .serial_number == 'USB7INCH' or com_port .serial_number == 'CT21INCH' :
140141 LcdCommRevC ._wake_up_device (com_port )
141- return LcdCommRevC .auto_detect_com_port ()
142- if com_port .vid == 0x1a86 and com_port .pid == 0xca21 :
142+ elif com_port .vid == 0x1a86 and com_port .pid == 0xca21 :
143143 LcdCommRevC ._wake_up_device (com_port )
144- return LcdCommRevC .auto_detect_com_port ()
145144
146- return LcdCommRevC ._get_awake_com_port (com_ports )
145+ return LcdCommRevC ._get_awake_com_port (comports () )
147146
148147 @staticmethod
149148 def _get_awake_com_port (com_ports ) -> Optional [str ]:
150- # Then try to find awake device through serial number or vid/pid
149+ # Try to find awake device through serial number or vid/pid
151150 for com_port in com_ports :
152151 if com_port .serial_number == '20080411' :
153152 return com_port .device
@@ -160,10 +159,10 @@ def _get_awake_com_port(com_ports) -> Optional[str]:
160159
161160 @staticmethod
162161 def _wake_up_device (com_port ):
163- # this device enumerates differently when off, we need to connect once to reset it to correct COM device
162+ # Connect to the device to wake it up
164163 logger .debug (f"Waiting for device { com_port } to be turned ON..." )
165164
166- for i in range (15 ):
165+ for i in range (WAKE_RETRIES ):
167166 try :
168167 # Try to connect every second, since it takes sometimes multiple connect to wake up the device
169168 serial .Serial (com_port .device , 115200 , timeout = 1 , rtscts = True )
@@ -172,9 +171,13 @@ def _wake_up_device(com_port):
172171
173172 if LcdCommRevC ._get_awake_com_port (comports ()) is not None :
174173 time .sleep (1 )
174+ logger .debug (f"Detected screen turned ON" )
175175 return
176+
176177 time .sleep (1 )
177178
179+ logger .error (f"Could not turn screen on after { WAKE_RETRIES } seconds, aborting." )
180+
178181 def _send_command (self , cmd : Command , payload : Optional [bytearray ] = None , padding : Optional [Padding ] = None ,
179182 bypass_queue : bool = False , readsize : Optional [int ] = None ):
180183 message = bytearray ()
@@ -431,7 +434,7 @@ def _generate_update_image(
431434 img_data , pixel_size = image_to_BGRA (image )
432435 else :
433436 # BGRA mode on 3 bytes: [6-bit B + 2-bit A, 6-bit G + 2-bit A, 8-bit R]
434- #img_data, pixel_size = image_to_compressed_BGRA(image)
437+ # img_data, pixel_size = image_to_compressed_BGRA(image)
435438 # For now use simple BGR that is more optimized, because this program does not support transparent background
436439 img_data , pixel_size = image_to_BGR (image )
437440
0 commit comments