Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 44 additions & 4 deletions eegnb/devices/eeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

from serial import Serial, EIGHTBITS, PARITY_NONE, STOPBITS_ONE

import pyxid2

from eegnb.devices.utils import (
get_openbci_usb,
create_stim_array,
Expand Down Expand Up @@ -57,7 +59,9 @@
"muse2016_bfb",
]


xid_devices = [
"nirsport2"
]

class EEG:
device_name: str
Expand All @@ -68,6 +72,7 @@ def __init__(
device=None,
serial_port=None,
serial_num=None,
xid_num=None,
mac_addr=None,
other=None,
ip_addr=None,
Expand All @@ -88,6 +93,7 @@ def __init__(
self.serial_num = serial_num
self.serial_port = serial_port
self.mac_address = mac_addr
self.xid_num = xid_num
self.ip_addr = ip_addr
self.other = other
self.config = config
Expand All @@ -112,7 +118,8 @@ def initialize_backend(self):
self._init_kf()
elif self.backend == "serialport":
self._init_serial()

elif self.backend == "xidport":
self._init_xid()

def _get_backend(self, device_name):
if device_name in brainflow_devices:
Expand All @@ -123,6 +130,8 @@ def _get_backend(self, device_name):
return "kernelflow"
elif device_name in ["biosemi"]:
return "serialport"
elif device_name in ["nirsport2"]:
return "xidport"


#####################
Expand Down Expand Up @@ -606,6 +615,33 @@ def _serial_open_port(self,PORT_ID="COM4", BAUD=115200):



################################
# Cedrus XID port functions #
################################


def _init_xid(self):
if self.xid_num is not None: # if an xis device number is supplied, open and init that device
xids_list = pyxid2.get_xid_devices()
xid = xids_list[self.xid_num]
xid.init_device()
# (otherwise, don't open; assuming an xid attribute will be
# manually added later)

xid.set_pulse_duration(1000) # [ is this needed / optimal in all cases ? ]

print("\nOpened XID Device #%s:\n%s" %(self.xid_num, xid))

self.xid = xid


def _xid_push_sample(self, marker):

if not (0 <= marker <= 255): raise ValueError("marker code must be 045255")
self.xid.activate_line(lines=[marker])




#################################
# Highlevel device functions #
Expand All @@ -628,7 +664,10 @@ def start(self, fn, duration=None):
elif self.backend == "kernelflow":
self._start_kf()
elif self.backend == "serialport":
pass
pass
elif self.backend == "xidport":
pass



def push_sample(self, marker, timestamp, marker_name=None):
Expand All @@ -647,7 +686,8 @@ def push_sample(self, marker, timestamp, marker_name=None):
self._kf_push_sample(marker=marker,timestamp=timestamp, marker_name=marker_name)
elif self.backend == "serialport":
self._serial_push_sample(marker=marker)

elif self.backend == "xidport":
self._xid_push_sample(marker=marker)

def stop(self):
if self.backend == "brainflow":
Expand Down
3 changes: 3 additions & 0 deletions eegnb/devices/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"freeeeg32": [f"eeg_{i}" for i in range(0, 32)],
"kernelflow": [],
"biosemi": [],
"nirsport2": [],
}

BRAINFLOW_CHANNELS = {
Expand Down Expand Up @@ -60,6 +61,7 @@
"freeeeg32": BoardShim.get_eeg_channels(BoardIds.FREEEEG32_BOARD.value),
"kernelflow": [],
"biosemi": [],
"nirsport2": [],
}

SAMPLE_FREQS = {
Expand All @@ -84,6 +86,7 @@
"freeeeg32": BoardShim.get_sampling_rate(BoardIds.FREEEEG32_BOARD.value),
"kernelflow": [],
"biosemi": [],
"nirsport2": [],
}


Expand Down
Loading