forked from malfarasplux/biofeatures
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pnr_bitalino.py
89 lines (68 loc) · 1.99 KB
/
pnr_bitalino.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from pynodered import node_red
import numpy as np
import time
from bitalino import BITalino
isAcquiring = 0
data = []
@node_red(category="pyfuncs")
def BITalinoNode(node, msg):
global isAcquiring, data
if msg['payload']['pyJSON'] == True:
if msg['payload']['type']=="BITalino":
if msg['payload']['macAddress']!="":
launch_acquisition(msg)
elif msg['payload']['type']=="stop":
isAcquiring = 0
elif msg['payload']['type']=="print":
a = 1+1
return msg
def set_acquisition():
# This example will collect data for 5 sec.
running_time = 5
batteryThreshold = 30
acqChannels = [0, 1, 2, 3, 4, 5]
samplingRate = 1000
nSamples = 10
digitalOutput = [1,1]
# Connect to BITalino
device = BITalino(macAddress)
# Set battery threshold
device.battery(batteryThreshold)
def acquire():
device.read(nSamples)
def launch_acquisition(msg):
global isAcquiring
isAcquiring = 1
macAddress = msg['payload']['macAddress']
# This example will collect data for 5 sec.
running_time = 9
batteryThreshold = 30
acqChannels = [0, 1, 2, 3, 4, 5]
samplingRate = 1000
nSamples = 10
digitalOutput = [1,1]
# Connect to BITalino
device = BITalino(macAddress)
# Set battery threshold
device.battery(batteryThreshold)
# Read BITalino version
print(device.version())
# ON/OFF
device.trigger([1,1])
device.trigger([0,0])
# Start Acquisition
device.start(samplingRate, acqChannels)
start = time.time()
end = time.time()
while (end - start) < running_time and isAcquiring == 1 :
# Read samples
data = device.read(nSamples)
print(data)
msg['payload']['val']=data.tolist()
end = time.time()
# Stop acquisition
device.stop()
# Close connection
device.close()
isAcquiring = 0
return ("success")