some convenience improvements

master
Ondřej Hruška 7 years ago
parent d8cf016f87
commit ae1bdde11c
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 8
      gex/units/DOut.py
  2. 4
      gex/units/SPI.py

@ -43,22 +43,22 @@ class DOut(gex.Unit):
pb.u16(self.pins2int(pins)) pb.u16(self.pins2int(pins))
self._send(CMD_TOGGLE, pb.close(), confirm=confirm) self._send(CMD_TOGGLE, pb.close(), confirm=confirm)
def pulse_ms(self, pins, length, active=True, confirm=True): def pulse_ms(self, ms, pins=0b01, active=True, confirm=True):
""" Send a pulse with length 1-65535 ms on selected pins """ """ Send a pulse with length 1-65535 ms on selected pins """
pb = gex.PayloadBuilder() pb = gex.PayloadBuilder()
pb.u16(self.pins2int(pins)) pb.u16(self.pins2int(pins))
pb.bool(active) pb.bool(active)
pb.bool(False) pb.bool(False)
pb.u16(length) pb.u16(ms)
self._send(CMD_PULSE, pb.close(), confirm=confirm) self._send(CMD_PULSE, pb.close(), confirm=confirm)
def pulse_us(self, pins, length, active=True, confirm=True): def pulse_us(self, us, pins=1, active=True, confirm=True):
""" Send a pulse of 1-999 us on selected pins """ """ Send a pulse of 1-999 us on selected pins """
pb = gex.PayloadBuilder() pb = gex.PayloadBuilder()
pb.u16(self.pins2int(pins)) pb.u16(self.pins2int(pins))
pb.bool(active) pb.bool(active)
pb.bool(True) pb.bool(True)
pb.u16(length) pb.u16(us)
self._send(CMD_PULSE, pb.close(), confirm=confirm) self._send(CMD_PULSE, pb.close(), confirm=confirm)

@ -14,6 +14,8 @@ class SPI(gex.Unit):
If rskip is -1 (default), the tbytes length will be used. If rskip is -1 (default), the tbytes length will be used.
Set it to 0 to skip nothing. Set it to 0 to skip nothing.
slave is 0-based index
""" """
if rskip == -1: if rskip == -1:
rskip = len(tbytes) rskip = len(tbytes)
@ -24,7 +26,7 @@ class SPI(gex.Unit):
pb.u16(rlen) pb.u16(rlen)
pb.blob(tbytes) pb.blob(tbytes)
# SPI does not respond if rlen is 0, but can be envorced using 'confirm' # SPI does not respond if rlen is 0, but can be enforced using 'confirm'
if rlen > 0: if rlen > 0:
resp = self._query(0x00, pb.close()) resp = self._query(0x00, pb.close())
return resp.data return resp.data

Loading…
Cancel
Save