forked from alexandrebarachant/muse-lsl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
muse-lsl.py
57 lines (46 loc) · 1.77 KB
/
muse-lsl.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
from muse import Muse
from time import sleep
from pylsl import StreamInfo, StreamOutlet, local_clock
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-a", "--address",
dest="address", type='string', default=None,
help="device mac adress.")
parser.add_option("-n", "--name",
dest="name", type='string', default=None,
help="name of the device.")
parser.add_option("-b", "--backend",
dest="backend", type='string', default="auto",
help="pygatt backend to use. can be auto, gatt or bgapi")
parser.add_option("-i", "--interface",
dest="interface", type='string', default=None,
help="The interface to use, 'hci0' for gatt or a com port for bgapi")
(options, args) = parser.parse_args()
info = info = StreamInfo('Muse', 'EEG', 5, 256, 'float32',
'Muse%s' % options.address)
info.desc().append_child_value("manufacturer", "Muse")
channels = info.desc().append_child("channels")
for c in ['TP9', 'AF7', 'AF8', 'TP10', 'Right AUX']:
channels.append_child("channel") \
.append_child_value("label", c) \
.append_child_value("unit", "microvolts") \
.append_child_value("type", "EEG")
outlet = StreamOutlet(info, 12, 360)
def process(data, timestamps):
for ii in range(12):
outlet.push_sample(data[:, ii], timestamps[ii])
muse = Muse(address=options.address, callback=process,
backend=options.backend, time_func=local_clock,
interface=options.interface, name=options.name)
muse.connect()
print('Connected')
muse.start()
print('Streaming')
while 1:
try:
sleep(1)
except:
break
muse.stop()
muse.disconnect()
print('Disonnected')