support for DOut pulse gen

master
Ondřej Hruška 7 years ago
parent f3920743aa
commit 92d3724dcd
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 15
      demo_neo2.py
  2. 9
      demo_pulse.py
  3. 3
      gex/TinyFrame.py
  4. 37
      gex/units/DOut.py
  5. 12
      test_adc.py

@ -0,0 +1,15 @@
#!/bin/env python3
import gex
import time
with gex.Client(gex.TrxRawUSB()) as client:
# Neopixel strip
strip = gex.Neopixel(client, 'neo')
# Load RGB to the strip
strip.load([0xFF0000, 0xFFFF00, 0x00FF00, 0x0000FF, 0xFF00FF])
for i in range(0,255):
strip.load([0xFF0000+i, 0xFFFF00, 0x00FF00, 0x0000FF, 0xFF00FF])
time.sleep(0.001)
strip.clear()

@ -0,0 +1,9 @@
#!/bin/env python3
import gex
import time
with gex.Client(gex.TrxRawUSB()) as client:
out = gex.DOut(client, 'out')
out.pulse_us([0], 20)
out.pulse_us([3], 10)

@ -301,7 +301,8 @@ class TinyFrame:
actual = self._cksum(self.rpayload)
if pck != actual:
print("[TF] Payload checksum mismatch")
print("[TF] Payload checksum mismatch (given %x, computed %x)" % (pck, actual))
print(self.rpayload)
self.reset_parser()
else:
self.handle_rx_frame()

@ -1,5 +1,11 @@
import gex
CMD_WRITE = 0
CMD_SET = 1
CMD_CLEAR = 2
CMD_TOGGLE = 3
CMD_PULSE = 4
class DOut(gex.Unit):
"""
Digital output port.
@ -17,22 +23,45 @@ class DOut(gex.Unit):
""" Set pins to a value - packed, as int """
pb = gex.PayloadBuilder()
pb.u16(pins)
self._send(0x00, pb.close(), confirm=confirm)
self._send(CMD_WRITE, pb.close(), confirm=confirm)
def set(self, pins, confirm=True):
""" Set pins high - packed, int or list """
pb = gex.PayloadBuilder()
pb.u16(self.pins2int(pins))
self._send(0x01, pb.close(), confirm=confirm)
self._send(CMD_SET, pb.close(), confirm=confirm)
def clear(self, pins, confirm=True):
""" Set pins low - packed, int or list """
pb = gex.PayloadBuilder()
pb.u16(self.pins2int(pins))
self._send(0x02, pb.close(), confirm=confirm)
self._send(CMD_CLEAR, pb.close(), confirm=confirm)
def toggle(self, pins, confirm=True):
""" Toggle pins - packed, int or list """
pb = gex.PayloadBuilder()
pb.u16(self.pins2int(pins))
self._send(0x03, pb.close(), confirm=confirm)
self._send(CMD_TOGGLE, pb.close(), confirm=confirm)
def pulse_ms(self, pins, length, active=True, confirm=True):
""" Send a pulse with length 1-65535 ms on selected pins """
pb = gex.PayloadBuilder()
pb.u16(self.pins2int(pins))
pb.bool(active)
pb.bool(False)
pb.u16(length)
self._send(CMD_PULSE, pb.close(), confirm=confirm)
def pulse_us(self, pins, length, active=True, confirm=True):
""" Send a pulse of 1-999 us on selected pins """
pb = gex.PayloadBuilder()
pb.u16(self.pins2int(pins))
pb.bool(active)
pb.bool(True)
pb.u16(length)
self._send(CMD_PULSE, pb.close(), confirm=confirm)

@ -11,17 +11,21 @@ with gex.Client(gex.TrxRawUSB()) as client:
adc = gex.ADC(client, 'a')
adc.set_active_channels([3])
rate=44000
rate=500
fs = adc.set_sample_rate(rate)
count = 44000*2
data = np.add(adc.capture(count) / 4096, -0.5)
count = 2000
data = adc.capture(count)
print("rx, %d samples" % len(data))
data = np.add(data / 4096, -0.5)
#
if data is not None:
# wavfile.write('file.wav', rate, data)
# print("Ok")
plt.plot(data, 'r-', lw=1)
plt.plot(data, 'r.', lw=1)
plt.show()
else:
print("Nothing rx")

Loading…
Cancel
Save