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. 1
      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[cod]
*$py.class *$py.class
*.wav
.idea/ .idea/
# C extensions # C extensions

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

@ -23,7 +23,7 @@ class PayloadParser:
def _slice(self, n:int) -> bytearray: def _slice(self, n:int) -> bytearray:
""" Extract a slice and advance the read pointer for the next slice """ """ Extract a slice and advance the read pointer for the next slice """
if self.ptr + n > len(self.buf): 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] slice = self.buf[self.ptr:self.ptr + n]
self.ptr += n self.ptr += n

@ -361,6 +361,7 @@ class ADC(gex.Unit):
def lst(frame): def lst(frame):
pp = gex.PayloadParser(frame.data) pp = gex.PayloadParser(frame.data)
if frame.type == EVT_CAPT_MORE or len(frame.data) != 0:
index = pp.u8() index = pp.u8()
if index != self._bcap_next_id: if index != self._bcap_next_id:
self._bcap_done = True 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) pp = gex.PayloadParser(data)
return pp.i16() * 0.0625 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: while True:
a = meas(6558392391241695016) (a, b) = meas2(6558392391241695016, 1802309978572980008)
b = meas(1802309978572980008) # a = meas(6558392391241695016)
# b = meas(1802309978572980008)
print("in: %.2f °C, out: %f °C" % (a, b)) print("in: %.2f °C, out: %f °C" % (a, b))
Loading…
Cancel
Save