-
Notifications
You must be signed in to change notification settings - Fork 13
/
live_flow.py
69 lines (48 loc) · 1.69 KB
/
live_flow.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
from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
import scipy.signal
from PySide import QtCore
from bdf import BDFReader, BDFWriter
from acquisition import BDFThread, OpenBCIThread, UDPThread
import sys, imp
from flow import Context
app = QtGui.QApplication.instance()
if not app:
app = QtGui.QApplication(sys.argv)
# Enable antialiasing for prettier plots
pg.setConfigOptions(antialias=True)
protocol_name = sys.argv[1]
from protocols import ProtocolLauncher
context = Context()
context.register_channel('Channel 1')
context.register_channel('Channel 2')
launcher = ProtocolLauncher(context, protocol_name)
#sourceThread = BDFThread(sys.argv[2])
#sourceThread = OpenBCIThread(sys.argv[2])
sourceThread = UDPThread()
def handlePacket(packet):
context.append_channel_data('Channel 1', [packet[0]])
context.append_channel_data('Channel 2', [packet[1]])
context.process()
sourceThread.newPacket.connect(handlePacket)
sourceThread.start()
def updateGUI():
for child in launcher.widget.children():
if hasattr(child, 'block'):
child.block.updateGUI()
guiTimer = QtCore.QTimer()
guiTimer.timeout.connect(updateGUI)
guiTimer.start(0)
try:
write_file = file(sys.argv[2], 'wb')
import bdf
writer = bdf.BDFWriter(8)
sourceThread.newPacket.connect(writer.append_sample)
QtGui.QApplication.instance().aboutToQuit.connect(lambda: writer.write_file(write_file))
except IndexError:
print "No log file specified"
## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()