-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathone_channel_plot.py
67 lines (55 loc) · 1.65 KB
/
one_channel_plot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/python3
"""
Plots channel 7 of the Attys in two different windows. Requires pyqtgraph.
"""
import sys
sys.path.append('cpp')
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import pyattyscomm
# read from 2nd Analogue channel
channel = pyattyscomm.AttysComm.INDEX_Analogue_channel_2
s = pyattyscomm.AttysScan()
s.scan()
c = s.getAttysComm(0)
if not c:
print("No Attys connected and/or paired")
sys.exit()
c.start()
# now let's plot the data
fig, ax = plt.subplots()
# that's our plotbuffer
plotbuffer = np.zeros(500)
# plots an empty line
line, = ax.plot(plotbuffer)
# axis
ax.set_ylim(-2, 2)
# receives the data from the generator below
def update(data):
global plotbuffer
global ax
plotbuffer=np.append(plotbuffer,data)
# only keep the 500 newest ones and discard the old ones
plotbuffer=plotbuffer[-500:]
# set the new 500 points of channel 9
line.set_ydata(plotbuffer)
dy = (plotbuffer.max() - plotbuffer.min())/10
ax.set_ylim(plotbuffer.min() - dy,plotbuffer.max() + dy)
return line,
# this checks in an endless loop if there is data in the ringbuffer
# of there is data then emit it to the update funnction above
def data_gen():
#endless loop which gets data
while True:
data = np.zeros(0)
while (c.hasSampleAvailable()):
sample = c.getSampleFromBuffer()
data = np.append(data,sample[channel])
yield data
# start the animation
ani = animation.FuncAnimation(fig, update, data_gen, interval=100)
# show it
plt.show()
c.quit()
print("finished")