Skip to content

Commit

Permalink
Allow gain to be set and channels to be disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
mesca committed Jul 8, 2020
1 parent 9bdd46b commit 9978ecb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
6 changes: 4 additions & 2 deletions examples/cyton.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ graphs:
params:
board: cyton
serial_port: /dev/cu.usbserial-DQ0084BO
channels: [ Fpz, AF7, AF8, Oz, O1, O2, P7, P8 ]
debug: false
channels: [ Fpz, AF7, AF8, Oz, O1, O2, P7, P8 ] # Rename EEG channels
disable: [ 2 ] # Disable channel 2
gain: 8
debug: true
- id: display
module: timeflux.nodes.debug
class: Display
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ keywords = timeflux, openbci
[options]
packages = find:
install_requires =
timeflux_brainflow>=0.1
timeflux_brainflow>=0.4
timeflux>=0.5.3

[options.extras_require]
Expand Down
32 changes: 31 additions & 1 deletion timeflux_openbci/nodes/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ class OpenBCI(BrainFlow):
board (string): The OpenBCI board type.
Allowed values: ``synthetic``, ``cyton``, ``ganglion``, ``cyton_daisy``,
``ganglion_wifi``, ``cyton_wifi``, ``cyton_daisy_wifi``
channels (list): The EEG channel labels.
channels (list of string): The EEG channel labels.
If not set, incrementing numbers will be used.
gain (int): The amplifier gain. Only for Cyton-based boards.
Possible values: 1, 2, 4, 6, 8, 12, 24.
Default: 24.
disable (list of int): Disable given channels. Only for Cyton-based boards.
Default: None
debug (boolean): Print debug messages.
**kwargs: The parameters specific for each board.
Allowed arguments: ``serial_port``, ``mac_address``, ``ip_address``,
Expand All @@ -25,3 +30,28 @@ class OpenBCI(BrainFlow):
.. literalinclude:: /../examples/synthetic.yaml
:language: yaml
"""

def __init__(
self, board, channels=None, gain=24, disable=None, debug=False, **kwargs
):

# Prepare command
command = None
if board.startswith("cyton"):
gains = {1: 0, 2: 1, 4: 2, 6: 3, 8: 4, 12: 5, 6: 24}
if "daisy" in board:
chans = "12345678QWERTYUI"
else:
chans = "12345678"
if not isinstance(disable, list):
disable = []
if gain in gains:
command = ""
for chan_num, chan_id in enumerate(chans, start=1):
enable = 1 if chan_num in disable else 0
command += f"x{chan_id}{enable}{gains[gain]}0110X"
else:
self.logger.warn("Invalid gain")

# Initialize
super().__init__(board, channels, command, debug, **kwargs)

0 comments on commit 9978ecb

Please sign in to comment.