diff --git a/buildhat/serinterface.py b/buildhat/serinterface.py index 55a1d87..42747a2 100644 --- a/buildhat/serinterface.py +++ b/buildhat/serinterface.py @@ -31,6 +31,7 @@ def cmp(str1, str2): class BuildHAT: CONNECTED=": connected to active ID" + CONNECTEDPASSIVE=": connected to passive ID" DISCONNECTED=": disconnected" DEVTIMEOUT=": timeout during data phase: disconnecting" NOTCONNECTED=": no device detected" @@ -89,7 +90,7 @@ def __init__(self, firmware, signature, version): else: self.write(b"version\r") # Use to force hat reset - #self.state = HatState.NEEDNEWFIRMWARE + self.state = HatState.NEEDNEWFIRMWARE if self.state == HatState.NEEDNEWFIRMWARE: self.resethat() self.loadfirmware(firmware, signature) @@ -200,11 +201,14 @@ def callbackloop(self, q): q.task_done() def loop(self, cond, uselist, q): + tmp = open("/tmp/serial.txt", "a") count = 0 while self.running: line = b"" try: line = self.ser.readline().decode('utf-8', 'ignore') + print(line, file=tmp, end='') + tmp.flush() except serial.SerialException: pass if len(line) == 0: @@ -219,6 +223,11 @@ def loop(self, cond, uselist, q): self.write("port {} ; on\r".format(portid).encode()) if uselist: count += 1 + elif cmp(msg, BuildHAT.CONNECTEDPASSIVE): + typeid = int(line[2+len(BuildHAT.CONNECTEDPASSIVE):],16) + self.connections[portid].update(typeid, True) + if uselist: + count += 1 elif cmp(msg, BuildHAT.DISCONNECTED): self.connections[portid].update(-1, False) elif cmp(msg, BuildHAT.DEVTIMEOUT): diff --git a/test/loadingtest.py b/test/loadingtest.py new file mode 100755 index 0000000..04c0710 --- /dev/null +++ b/test/loadingtest.py @@ -0,0 +1,14 @@ +#!/usr/bin/python3 + +import datetime +from buildhat import Hat + +try: + print("{} Starting".format(datetime.datetime.now().strftime("%H:%M:%S"))) + h = Hat() + print(h.get()) + print("Fin") +except Exception as err: + print(err) + with open('/tmp/test', 'w'): + pass diff --git a/test/loadingtest.sh b/test/loadingtest.sh new file mode 100755 index 0000000..e80eb8e --- /dev/null +++ b/test/loadingtest.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +rm "/tmp/test" + +while [[ 1 ]]; +do + rm /tmp/serial.txt + + ./loadingtest.py + + if [ -f "/tmp/test" ]; then + break + fi + sleep 1 +done + +cat /tmp/serial.txt