example with auto + cleaning

doublebuf
Ondřej Hruška 7 years ago
parent 634093507f
commit f3920743aa
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 2
      .gitignore
  2. 0
      demo_ndir_leds.py
  3. 0
      demo_ndir_usart.py
  4. 63
      demo_neopixel.py
  5. 0
      demo_pymodoro.py
  6. 2
      gex/PayloadParser.py
  7. 15
      gex/units/ADC.py
  8. 28
      test_adc.py
  9. 0
      test_freq_cap.py
  10. 19
      test_onewire.py
  11. 0
      test_pwmdim_music.py
  12. 0
      test_pwmdim_sweep.py
  13. 0
      test_sipo_omicron.py
  14. 0
      test_touch.py

2
.gitignore vendored

@ -4,6 +4,8 @@ __javascript__/
*.py[cod]
*$py.class
*.wav
.idea/
# C extensions

@ -1,36 +1,35 @@
#!/bin/env python3
import gex
client = gex.Client(port='/dev/ttyACM0')
# Neopixel strip
strip = gex.Neopixel(client, 'npx')
# Load RGB to the strip
strip.load([0xFF0000, 0x00FF00, 0x0000FF, 0xFF00FF])
# I2C bus
i2c = gex.I2C(client, 'i2c')
# Read device register
print(i2c.read_reg(address=0x76, reg=0xD0))
# Write value to a register
i2c.write_reg(address=0x76, reg=0xF4, value=0xFA)
# SPI
spi = gex.SPI(client, 'spi')
# Query slave 0
print(spi.query(0, [0xAA, 0xBB, 0xCC, 0xDD], rlen=2, rskip=4))
# Write slaves 0 and 2
spi.multicast(0b101, [0xDE, 0xAD, 0xBE, 0xEF])
# USART
usart = gex.USART(client, 'serial')
# Handle received data
usart.listen(lambda x: print(x, end='', flush=True))
# Write a string
usart.write("AHOJ\r\n")
# Digital output (8 pins)
display = gex.DOut(client, 'display')
display.write(0b10110011)
display.toggle(0b00010010)
with gex.Client(gex.TrxRawUSB()) as client:
# Neopixel strip
strip = gex.Neopixel(client, 'npx')
# Load RGB to the strip
strip.load([0xFF0000, 0x00FF00, 0x0000FF, 0xFF00FF])
#
# # I2C bus
# i2c = gex.I2C(client, 'i2c')
# # Read device register
# print(i2c.read_reg(address=0x76, reg=0xD0))
# # Write value to a register
# i2c.write_reg(address=0x76, reg=0xF4, value=0xFA)
#
# # SPI
# spi = gex.SPI(client, 'spi')
# # Query slave 0
# print(spi.query(0, [0xAA, 0xBB, 0xCC, 0xDD], rlen=2, rskip=4))
# # Write slaves 0 and 2
# spi.multicast(0b101, [0xDE, 0xAD, 0xBE, 0xEF])
#
# # USART
# usart = gex.USART(client, 'serial')
# # Handle received data
# usart.listen(lambda x: print(x, end='', flush=True))
# # Write a string
# usart.write("AHOJ\r\n")
#
# # Digital output (8 pins)
# display = gex.DOut(client, 'display')
# display.write(0b10110011)
# display.toggle(0b00010010)

@ -23,7 +23,7 @@ class PayloadParser:
def _slice(self, n:int) -> bytearray:
""" Extract a slice and advance the read pointer for the next slice """
if self.ptr + n > len(self.buf):
raise Exception("Payload parser underrun")
raise Exception("Payload parser underrun - frame: %s" % str(self.buf))
slice = self.buf[self.ptr:self.ptr + n]
self.ptr += n

@ -361,15 +361,16 @@ class ADC(gex.Unit):
def lst(frame):
pp = gex.PayloadParser(frame.data)
index = pp.u8()
if index != self._bcap_next_id:
self._bcap_done = True
raise Exception("Lost capture data frame! Expected %d, got %d" % (self._bcap_next_id, index))
#return TF.CLOSE XXX
if frame.type == EVT_CAPT_MORE or len(frame.data) != 0:
index = pp.u8()
if index != self._bcap_next_id:
self._bcap_done = True
raise Exception("Lost capture data frame! Expected %d, got %d" % (self._bcap_next_id, index))
#return TF.CLOSE XXX
self._bcap_next_id = (self._bcap_next_id + 1) % 256
self._bcap_next_id = (self._bcap_next_id + 1) % 256
buffer.extend(pp.tail())
buffer.extend(pp.tail())
if frame.type == EVT_CAPT_DONE:
self._bcap_done = True

@ -0,0 +1,28 @@
#!/bin/env python3
import time
import gex
import numpy as np
from matplotlib import pyplot as plt
from scipy.io import wavfile
with gex.Client(gex.TrxRawUSB()) as client:
adc = gex.ADC(client, 'a')
adc.set_active_channels([3])
rate=44000
fs = adc.set_sample_rate(rate)
count = 44000*2
data = np.add(adc.capture(count) / 4096, -0.5)
if data is not None:
# wavfile.write('file.wav', rate, data)
# print("Ok")
plt.plot(data, 'r-', lw=1)
plt.show()
else:
print("Nothing rx")

@ -15,9 +15,24 @@ with gex.Client(gex.TrxRawUSB()) as client:
pp = gex.PayloadParser(data)
return pp.i16() * 0.0625
def meas2(addr, addr2):
ow.write([0x44], addr=addr)
ow.write([0x44], addr=addr2)
ow.wait_ready()
data = ow.query([0xBE], 9, addr=addr)
pp = gex.PayloadParser(data)
a = pp.i16() * 0.0625
data = ow.query([0xBE], 9, addr=addr2)
pp = gex.PayloadParser(data)
b = pp.i16() * 0.0625
return a, b
while True:
a = meas(6558392391241695016)
b = meas(1802309978572980008)
(a, b) = meas2(6558392391241695016, 1802309978572980008)
# a = meas(6558392391241695016)
# b = meas(1802309978572980008)
print("in: %.2f °C, out: %f °C" % (a, b))
Loading…
Cancel
Save