diff --git a/eegnb/experiments/Experiment.py b/eegnb/experiments/Experiment.py index fb8b9ae5e..4d7cab119 100644 --- a/eegnb/experiments/Experiment.py +++ b/eegnb/experiments/Experiment.py @@ -27,7 +27,7 @@ class BaseExperiment(ABC): def __init__(self, exp_name, duration, eeg, save_fn, n_trials: int, iti: float, soa: float, jitter: float, - use_vr=False, use_fullscr = True, screen_num=0, stereoscopic = False): + use_vr=False, use_fullscr = True, screen_num=0, stereoscopic = False, devices = list): """ Initializer for the Base Experiment Class Args: @@ -50,6 +50,7 @@ def __init__(self, exp_name, duration, eeg, save_fn, n_trials: int, iti: float, Press spacebar to continue. \n""".format(self.exp_name) self.duration = duration self.eeg: EEG = eeg + self.devices = devices self.save_fn = save_fn self.n_trials = n_trials self.iti = iti @@ -338,6 +339,15 @@ def run(self, instructions=True): # Closing the window self.window.close() + + + def send_triggers(self, marker): + """Send timing triggers to recording device[s]""" + for dev in self.devices: + timestamp = time() + dev.push_sample(marker=marker, timestamp=timestamp) + + @property def name(self) -> str: """ This experiment's name """ diff --git a/eegnb/experiments/visual_n170/n170.py b/eegnb/experiments/visual_n170/n170.py index 66bb3e7d1..231381ff7 100644 --- a/eegnb/experiments/visual_n170/n170.py +++ b/eegnb/experiments/visual_n170/n170.py @@ -15,14 +15,13 @@ class VisualN170(Experiment.BaseExperiment): - def __init__(self, duration=120, eeg: Optional[EEG]=None, save_fn=None, - + def __init__(self, duration=120, eeg: Optional[EEG]=None, devices: Optional[list]=None,save_fn=None, n_trials = 2010, iti = 0.4, soa = 0.3, jitter = 0.2, use_vr = False): # Set experiment name exp_name = "Visual N170" # Calling the super class constructor to initialize the experiment variables - super(VisualN170, self).__init__(exp_name, duration, eeg, save_fn, n_trials, iti, soa, jitter, use_vr) + super(VisualN170, self).__init__(exp_name, duration, eeg, save_fn, n_trials, iti, soa, jitter, use_vr, devices=devices) def load_stimulus(self): @@ -45,13 +44,24 @@ def present_stimulus(self, idx: int): # Draw the image image.draw() + # Pushing the sample to the EEG if self.eeg: timestamp = time() + if self.eeg.backend == "muselsl": marker = [self.markernames[label]] else: marker = self.markernames[label] + self.eeg.push_sample(marker=marker, timestamp=timestamp) - - self.window.flip() \ No newline at end of file + + + if self.devices: + marker = self.markernames[label] + self.send_triggers(marker) + + + self.window.flip() + +