diff --git a/gex/__init__.py b/gex/__init__.py index 5c45986..023e08a 100644 --- a/gex/__init__.py +++ b/gex/__init__.py @@ -15,6 +15,7 @@ from gex.units.Neopixel import Neopixel from gex.units.I2C import I2C from gex.units.SPI import SPI from gex.units.USART import USART +from gex.units.OneWire import OneWire # General, low level diff --git a/gex/transport.py b/gex/transport.py index 8c2000d..d747d34 100644 --- a/gex/transport.py +++ b/gex/transport.py @@ -193,8 +193,8 @@ class TrxRawUSB (BaseGexTransport): # Using time.sleep() would block for too long. Instead we release the semaphore on each Rx chunk of data # and then check if it's what we wanted (let TF handle it and call the listener) start = time.time() - while time.time() - start < timeout: - self.dataSem.acquire() + while (time.time() - start) < timeout: + self.dataSem.acquire(True, 0.1) if testfunc is None or testfunc(): break pass diff --git a/gex/units/OneWire.py b/gex/units/OneWire.py new file mode 100644 index 0000000..deb2633 --- /dev/null +++ b/gex/units/OneWire.py @@ -0,0 +1,12 @@ +import gex + +class OneWire(gex.Unit): + """ + Dallas 1-Wire master + """ + + def _type(self): + return '1WIRE' + + def test(self): + return self._query(0x00) diff --git a/main.py b/main.py index c6229ce..6ea4e35 100644 --- a/main.py +++ b/main.py @@ -12,6 +12,16 @@ with gex.Client(transport) as client: print(s) client.ini_write(s) + if True: + ow = gex.OneWire(client, 'ow') + resp = ow.test() + print(resp) + + pp = gex.PayloadParser(resp.data) + print("Temperature %f" % (pp.i16()/2)) + print("Count_remain %d" % pp.u8()) + print("Count_per_deg %d" % pp.u8()) + if False: buf = client.bulk_read(gex.MSG_INI_READ) print(buf.decode('utf-8')) @@ -105,7 +115,7 @@ with gex.Client(transport) as client: while True: client.poll() - if True: + if False: print(client.ini_read()) trig = gex.DIn(client, 'trig')