Skip to content

Commit c33b088

Browse files
Merge pull request #314 from JohnGriffiths/add_multidevice
Add multidevice
2 parents 0d81ce9 + 12825e8 commit c33b088

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

eegnb/experiments/Experiment.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
class BaseExperiment(ABC):
2828

2929
def __init__(self, exp_name, duration, eeg, save_fn, n_trials: int, iti: float, soa: float, jitter: float,
30-
use_vr=False, use_fullscr = True, screen_num=0, stereoscopic = False):
30+
use_vr=False, use_fullscr = True, screen_num=0, stereoscopic = False, devices = list):
3131
""" Initializer for the Base Experiment Class
3232
3333
Args:
@@ -50,6 +50,7 @@ def __init__(self, exp_name, duration, eeg, save_fn, n_trials: int, iti: float,
5050
Press spacebar to continue. \n""".format(self.exp_name)
5151
self.duration = duration
5252
self.eeg: EEG = eeg
53+
self.devices = devices
5354
self.save_fn = save_fn
5455
self.n_trials = n_trials
5556
self.iti = iti
@@ -338,6 +339,15 @@ def run(self, instructions=True):
338339
# Closing the window
339340
self.window.close()
340341

342+
343+
344+
def send_triggers(self, marker):
345+
"""Send timing triggers to recording device[s]"""
346+
for dev in self.devices:
347+
timestamp = time()
348+
dev.push_sample(marker=marker, timestamp=timestamp)
349+
350+
341351
@property
342352
def name(self) -> str:
343353
""" This experiment's name """

eegnb/experiments/visual_n170/n170.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@
1515

1616
class VisualN170(Experiment.BaseExperiment):
1717

18-
def __init__(self, duration=120, eeg: Optional[EEG]=None, save_fn=None,
19-
18+
def __init__(self, duration=120, eeg: Optional[EEG]=None, devices: Optional[list]=None,save_fn=None,
2019
n_trials = 2010, iti = 0.4, soa = 0.3, jitter = 0.2, use_vr = False):
2120

2221
# Set experiment name
2322
exp_name = "Visual N170"
2423
# Calling the super class constructor to initialize the experiment variables
25-
super(VisualN170, self).__init__(exp_name, duration, eeg, save_fn, n_trials, iti, soa, jitter, use_vr)
24+
super(VisualN170, self).__init__(exp_name, duration, eeg, save_fn, n_trials, iti, soa, jitter, use_vr, devices=devices)
2625

2726
def load_stimulus(self):
2827

@@ -45,13 +44,24 @@ def present_stimulus(self, idx: int):
4544
# Draw the image
4645
image.draw()
4746

47+
4848
# Pushing the sample to the EEG
4949
if self.eeg:
5050
timestamp = time()
51+
5152
if self.eeg.backend == "muselsl":
5253
marker = [self.markernames[label]]
5354
else:
5455
marker = self.markernames[label]
56+
5557
self.eeg.push_sample(marker=marker, timestamp=timestamp)
56-
57-
self.window.flip()
58+
59+
60+
if self.devices:
61+
marker = self.markernames[label]
62+
self.send_triggers(marker)
63+
64+
65+
self.window.flip()
66+
67+

0 commit comments

Comments
 (0)