@@ -151,14 +151,17 @@ def __init__(self, firmware, signature, version, device="/dev/serial0", debug=Fa
151
151
self.cb.start()
152
152
153
153
# Drop timeout value to 1s
154
+ listevt = threading.Event()
154
155
self.ser.timeout = 1
155
- self.th = threading.Thread(target=self.loop, args=(self.cond, self.state == HatState.FIRMWARE, self.cbqueue))
156
+ self.th = threading.Thread(target=self.loop, args=(self.cond, self.state == HatState.FIRMWARE, self.cbqueue, listevt ))
156
157
self.th.daemon = True
157
158
self.th.start()
158
159
159
160
if self.state == HatState.FIRMWARE:
160
161
self.write(b"port 0 ; select ; port 1 ; select ; port 2 ; select ; port 3 ; select ; echo 0\r")
162
+ time.sleep(3.5)
161
163
self.write(b"list\r")
164
+ listevt.set()
162
165
elif self.state == HatState.NEEDNEWFIRMWARE or self.state == HatState.BOOTLOADER:
163
166
self.write(b"reboot\r")
164
167
@@ -292,7 +295,7 @@ def callbackloop(self, q):
292
295
cb[0]()(cb[1])
293
296
q.task_done()
294
297
295
- def loop(self, cond, uselist, q):
298
+ def loop(self, cond, uselist, q, listevt ):
296
299
"""Event handling for Build HAT
297
300
298
301
:param cond: Condition used to block user's script till we're ready
@@ -312,20 +315,20 @@ def loop(self, cond, uselist, q):
312
315
self.connections[portid].update(typeid, True)
313
316
if typeid == 64:
314
317
self.write(f"port {portid} ; on\r".encode())
315
- if uselist:
318
+ if uselist and listevt.is_set() :
316
319
count += 1
317
320
elif cmp(msg, BuildHAT.CONNECTEDPASSIVE):
318
321
typeid = int(line[2 + len(BuildHAT.CONNECTEDPASSIVE):], 16)
319
322
self.connections[portid].update(typeid, True)
320
- if uselist:
323
+ if uselist and listevt.is_set() :
321
324
count += 1
322
325
elif cmp(msg, BuildHAT.DISCONNECTED):
323
326
self.connections[portid].update(-1, False)
324
327
elif cmp(msg, BuildHAT.DEVTIMEOUT):
325
328
self.connections[portid].update(-1, False)
326
329
elif cmp(msg, BuildHAT.NOTCONNECTED):
327
330
self.connections[portid].update(-1, False)
328
- if uselist:
331
+ if uselist and listevt.is_set() :
329
332
count += 1
330
333
elif cmp(msg, BuildHAT.RAMPDONE):
331
334
with self.rampcond[portid]:
0 commit comments