Skip to content

Commit 64999d3

Browse files
committed
Stub for some support of impedance check.
1 parent 4acfbf8 commit 64999d3

File tree

6 files changed

+48
-18
lines changed

6 files changed

+48
-18
lines changed

open_bci_ganglion.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def __init__(self, port=None, baud=0, filter_data=False,
8585
# number of EEG channels and (optionally) accelerometer channel
8686
self.eeg_channels_per_sample = 4
8787
self.aux_channels_per_sample = 3
88+
self.imp_channels_per_sample = 0
8889
self.read_state = 0
8990
self.log_packet_count = 0
9091
self.packets_dropped = 0
@@ -220,12 +221,17 @@ def getSampleRate(self):
220221
return SAMPLE_RATE
221222

222223
def getNbEEGChannels(self):
223-
return self.eeg_channels_per_sample
224+
"""Will not get new data on impedance check."""
225+
return self.eeg_channels_per_sample
224226

225227
def getNbAUXChannels(self):
226228
"""Might not be used depending on the mode."""
227229
return self.aux_channels_per_sample
228230

231+
def getNbImpChannels(self):
232+
"""Might not be used depending on the mode."""
233+
return self.imp_channels_per_sample
234+
229235
def start_streaming(self, callback, lapse=-1):
230236
"""
231237
Start handling streaming data from the board. Call a provided callback
@@ -387,9 +393,10 @@ def reconnect(self):
387393
class OpenBCISample(object):
388394
"""Object encapulsating a single sample from the OpenBCI board."""
389395
def __init__(self, packet_id, channel_data, aux_data):
390-
self.id = packet_id;
391-
self.channel_data = channel_data;
392-
self.aux_data = aux_data;
396+
self.id = packet_id
397+
self.channel_data = channel_data
398+
self.aux_data = aux_data
399+
self.imp_data = []
393400

394401

395402
class GanglionDelegate(DefaultDelegate):

open_bci_v3.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def handle_sample(sample):
1313
NOTE: If daisy modules is enabled, the callback will occur every two samples, hence "packet_id" will only contain even numbers. As a side effect, the sampling rate will be divided by 2.
1414
1515
FIXME: at the moment we can just force daisy mode, do not check that the module is detected.
16-
16+
TODO: enable impedance
1717
1818
"""
1919
import serial
@@ -97,6 +97,7 @@ def __init__(self, port=None, baud=115200, filter_data=True,
9797
self.scaling_output = scaled_output
9898
self.eeg_channels_per_sample = 8 # number of EEG channels per sample *from the board*
9999
self.aux_channels_per_sample = 3 # number of AUX channels per sample *from the board*
100+
self.imp_channels_per_sample = 0 # impedance check not supported at the moment
100101
self.read_state = 0
101102
self.daisy = daisy
102103
self.last_odd_sample = OpenBCISample(-1, [], []) # used for daisy
@@ -140,6 +141,9 @@ def getNbEEGChannels(self):
140141
def getNbAUXChannels(self):
141142
return self.aux_channels_per_sample
142143

144+
def getNbImpChannels(self):
145+
return self.imp_channels_per_sample
146+
143147
def start_streaming(self, callback, lapse=-1):
144148
"""
145149
Start handling streaming data from the board. Call a provided callback
@@ -594,10 +598,11 @@ def find_port(self):
594598
return openbci_port
595599

596600
class OpenBCISample(object):
597-
"""Object encapulsating a single sample from the OpenBCI board."""
601+
"""Object encapulsating a single sample from the OpenBCI board. NB: dummy imp for plugin compatiblity"""
598602
def __init__(self, packet_id, channel_data, aux_data):
599-
self.id = packet_id;
600-
self.channel_data = channel_data;
601-
self.aux_data = aux_data;
603+
self.id = packet_id
604+
self.channel_data = channel_data
605+
self.aux_data = aux_data
606+
self.imp_data = []
602607

603608

plugin_interface.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ class PluginExample(plugintypes.IPluginExtended):
2222

2323
class IPluginExtended(IPlugin):
2424
# args: passed by command line
25-
def pre_activate(self, args, sample_rate=250, eeg_channels=8, aux_channels=3):
25+
def pre_activate(self, args, sample_rate=250, eeg_channels=8, aux_channels=3, imp_channels=0):
2626
self.args = args
2727
self.sample_rate = sample_rate
2828
self.eeg_channels = eeg_channels
2929
self.aux_channels = aux_channels
30+
self.imp_channels = imp_channels
3031
# by default we say that activation was okay -- inherited from IPlugin
3132
self.is_activated = True
3233
self.activate()

plugins/print.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ def activate(self):
77
# called with each new sample
88
def __call__(self, sample):
99
if sample:
10-
sample_string = "ID: %f\n%s\n%s" %(sample.id, str(sample.channel_data)[1:-1], str(sample.aux_data)[1:-1])
10+
# print impedance if supported
11+
if self.imp_channels > 0:
12+
sample_string = "ID: %f\n%s\n%s\%s" %(sample.id, str(sample.channel_data)[1:-1], str(sample.aux_data)[1:-1], str(sample.imp_data)[1:-1])
13+
else:
14+
sample_string = "ID: %f\n%s\n%s" %(sample.id, str(sample.channel_data)[1:-1], str(sample.aux_data)[1:-1])
1115
print "---------------------------------"
1216
print sample_string
1317
print "---------------------------------"
@@ -19,4 +23,4 @@ def __call__(self, sample):
1923
# print "Not a ascii-encoded unicode string"
2024
# else:
2125
# print sample_string
22-
26+

plugins/streamer_lsl.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
from pylsl import StreamInfo, StreamOutlet
77
import plugin_interface as plugintypes
88

9-
# Use LSL protocol to broadcast data using one stream for EEG and one stream for AUX
9+
# Use LSL protocol to broadcast data using one stream for EEG, one stream for AUX, one last for impedance testing (on supported board, if enabled)
1010
class StreamerLSL(plugintypes.IPluginExtended):
1111
# From IPlugin
1212
def activate(self):
1313
eeg_stream = "OpenBCI_EEG"
1414
eeg_id = "openbci_eeg_id1"
1515
aux_stream = "OpenBCI_AUX"
1616
aux_id = "openbci_aux_id1"
17+
imp_stream = "OpenBCI_Impedance"
18+
imp_id = "openbci_imp_id1"
1719

1820
if len(self.args) > 0:
1921
eeg_stream = self.args[0]
@@ -23,23 +25,34 @@ def activate(self):
2325
aux_stream = self.args[2]
2426
if len(self.args) > 3:
2527
aux_id = self.args[3]
28+
if len(self.args) > 4:
29+
imp_stream = self.args[4]
30+
if len(self.args) > 5:
31+
imp_id = self.args[5]
2632

2733
# Create a new streams info, one for EEG values, one for AUX (eg, accelerometer) values
2834
print "Creating LSL stream for EEG. Name:", eeg_stream, "- ID:", eeg_id, "- data type: float32.", self.eeg_channels, "channels at", self.sample_rate, "Hz."
2935
info_eeg = StreamInfo(eeg_stream, 'EEG', self.eeg_channels,self.sample_rate,'float32',eeg_id);
3036
# NB: set float32 instead of int16 so as OpenViBE takes it into account
3137
print "Creating LSL stream for AUX. Name:", aux_stream, "- ID:", aux_id, "- data type: float32.", self.aux_channels, "channels at", self.sample_rate, "Hz."
3238
info_aux = StreamInfo(aux_stream, 'AUX', self.aux_channels,self.sample_rate,'float32',aux_id);
33-
39+
3440
# make outlets
3541
self.outlet_eeg = StreamOutlet(info_eeg)
3642
self.outlet_aux = StreamOutlet(info_aux)
37-
43+
44+
if self.imp_channels > 0:
45+
print "Creating LSL stream for Impedance. Name:", imp_stream, "- ID:", imp_id, "- data type: float32.", self.imp_channels, "channels at", self.sample_rate, "Hz."
46+
info_imp = StreamInfo(imp_stream, 'Impedance', self.imp_channels,self.sample_rate,'float32',imp_id);
47+
self.outlet_imp = StreamOutlet(info_imp)
48+
3849
# send channels values
3950
def __call__(self, sample):
4051
self.outlet_eeg.push_sample(sample.channel_data)
4152
self.outlet_aux.push_sample(sample.aux_data)
53+
if self.imp_channels > 0:
54+
self.outlet_imp.push_sample(sample.imp_data)
4255

4356
def show_help(self):
44-
print """Optional arguments: [EEG_stream_name [EEG_stream_ID [AUX_stream_name [AUX_stream_ID]]]]
45-
\t Defaults: "OpenBCI_EEG" / "openbci_eeg_id1" and "OpenBCI_AUX" / "openbci_aux_id1"."""
57+
print """Optional arguments: [EEG_stream_name [EEG_stream_ID [AUX_stream_name [AUX_stream_ID [Impedance_steam_name [Impedance_stream_ID]]]]]]
58+
\t Defaults: "OpenBCI_EEG" / "openbci_eeg_id1" and "OpenBCI_AUX" / "openbci_aux_id1" / "OpenBCI_Impedance" / "openbci_imp_id1"."""

user.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
print ("Error: [ " + plug_name + " ] not found or could not be loaded. Check name and requirements.")
150150
else:
151151
print ("\nActivating [ " + plug_name + " ] plugin...")
152-
if not plug.plugin_object.pre_activate(plug_args, sample_rate=board.getSampleRate(), eeg_channels=board.getNbEEGChannels(), aux_channels=board.getNbAUXChannels()):
152+
if not plug.plugin_object.pre_activate(plug_args, sample_rate=board.getSampleRate(), eeg_channels=board.getNbEEGChannels(), aux_channels=board.getNbAUXChannels(), imp_channels=board.getNbImpChannels()):
153153
print ("Error while activating [ " + plug_name + " ], check output for more info.")
154154
else:
155155
print ("Plugin [ " + plug_name + "] added to the list")

0 commit comments

Comments
 (0)