Skip to content

Commit f6e5e82

Browse files
committed
ganglion: parsing impedance
1 parent 9fb9bfe commit f6e5e82

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

open_bci_ganglion.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ class OpenBCIBoard(object):
5454
Args:
5555
port: MAC address of the Ganglion Board. "None" to attempt auto-detect.
5656
aux: enable on not aux channels (i.e. switch to 18bit mode if set)
57-
timeout: in seconds, if set will try to disconnect / reconnect after a period without new data
57+
timeout: in seconds, if set will try to disconnect / reconnect after a period without new data -- should be high if impedance check
5858
max_packets_to_skip: will try to disconnect / reconnect after too many packets are skipped
5959
baud, filter_data, daisy: Not used, for compatibility with v3
6060
"""
6161

6262
def __init__(self, port=None, baud=0, filter_data=False,
63-
scaled_output=True, daisy=False, log=True, aux=False, timeout=1, max_packets_to_skip=20):
63+
scaled_output=True, daisy=False, log=True, aux=False, timeout=5, max_packets_to_skip=20):
6464
# unused, for compatibility with Cyton v3 API
6565
self.daisy = False
6666
# these one are used
@@ -454,7 +454,7 @@ def parse(self, packet):
454454
# Impedance Channel
455455
elif start_byte >= 201 and start_byte <= 205:
456456
self.receiving_ASCII = False
457-
self.parseImpedance(start_byte, unpac[1:])
457+
self.parseImpedance(start_byte, packet[1:])
458458
# Part of ASCII -- TODO: better formatting of incoming ASCII
459459
elif start_byte == 206:
460460
print("%\t" + str(packet[1:]))
@@ -540,8 +540,15 @@ def parse18bit(self, packet_id, packet):
540540

541541

542542
def parseImpedance(self, packet_id, packet):
543-
""" Dealing with impedance data """
544-
print "impedance:", packet
543+
""" Dealing with impedance data. packet: ASCII data. NB: will take few packet (seconds) to fill"""
544+
if packet[-2:] != "Z\n":
545+
print('Wrong format for impedance check, should be ASCII ending with "Z\\n"')
546+
547+
# convert from ASCII to actual value
548+
imp_value = int(packet[:-2])
549+
# from 201 to 205 codes to the right array size
550+
self.lastImpedance[packet_id- 201] = imp_value
551+
self.pushSample(packet_id - 200, self.lastChannelData, self.lastAcceleromoter, self.lastImpedance)
545552

546553

547554
def pushSample(self, sample_id, chan_data, aux_data, imp_data):

0 commit comments

Comments
 (0)