/// <summary> /// Constructs a panel /// </summary> public EmotivStatusCheckerPanel() : base() { this.HeadsetConnected = false; var label = new Label() { Dock = DockStyle.Fill, TextAlign = ContentAlignment.MiddleCenter }; this.Controls.Add(label); this.listener = new EEGDataListener(GUIUtils.GUIInvoker, (ignored) => { this.HeadsetConnected = true; label.Text = "Headset connected!"; label.BackColor = Color.Green; label.ForeColor = Color.Black; }, null, (ignored) => { this.HeadsetConnected = false; label.Text = "Could not connect to headset"; label.BackColor = Color.Red; label.ForeColor = Color.White; }); EmotivDataSource.Instance.AddListener(this.listener); }
/// <summary> /// Removes a listener from the data source /// </summary> public void RemoveListener(IEEGDataListener listener) { this.RemoveListeners(listener.Enumerate()); }
/// <summary> /// Add a listener to the data source /// </summary> public void AddListener(IEEGDataListener listener) { this.AddListeners(listener.Enumerate()); }
private IEnumerable <View> GetViews(Runtime runtime) { BlockingQueue <IArrayView <EEGDataEntry> > trialDataQueue; using (var trialListener = this.GetTrialDataListener(out trialDataQueue)) // create the listeners using (var rawDataListener = this.GetRawDataRecordingListener()) using (var stimuli1 = this.GetStimuli(this.StimulusClass1, runtime.Random)) // create stimulus enumerators using (var stimuli2 = this.GetStimuli(this.StimulusClass2, runtime.Random)) { // save the trial queue runtime.TrialDataQueue = trialDataQueue; // add listeners var listeners = new IEEGDataListener[] { trialListener, rawDataListener }.Where(l => l != null); this.DataSource.AddListeners(listeners); // training phase if (this.Settings.TrainingImagesPerClass > 0) { yield return(new TextView(runtime.LogLine("Training Phase"), this.Settings.InstructionTime)); runtime.LogLine(); while (runtime.TrainStimuliRemaining > 0) { stimuli1.MoveNext(); stimuli2.MoveNext(); runtime.CurrentTrial = new Trial(runtime) { IsTraining = true, Stimulus1 = stimuli1.Current, Stimulus2 = stimuli2.Current, FocusOn1 = this.GetFocusTarget(runtime), LeftHas1 = runtime.Random.NextBool() }; foreach (var view in this.ProcessStimulusPair(runtime)) { yield return(view); } runtime.LogLine(); } } // initial training if (runtime.Classifiers.Count > 0) { yield return(new TrainView(runtime.Classifiers) { Text = runtime.LogLine("Training Classifiers") }); runtime.LogLine(); } // test phase if (this.Settings.TestImages > 0) { yield return(new TextView(runtime.LogLine("Test Phase"), this.Settings.InstructionTime)); runtime.LogLine(); while (runtime.TestStimuliRemaining > 0) { stimuli1.MoveNext(); stimuli2.MoveNext(); runtime.CurrentTrial = new Trial(runtime) { IsTraining = false, Stimulus1 = stimuli1.Current, Stimulus2 = stimuli2.Current, LeftHas1 = runtime.Random.NextBool() }; foreach (var view in this.ProcessStimulusPair(runtime)) { yield return(view); } runtime.LogLine(); // periodic training if (runtime.CurrentTrial.Succeeded && (runtime.CurrentTrial.Index + 1) % this.Settings.TrainFrequency == 0 && runtime.TestStimuliRemaining > 0 && runtime.Classifiers.Count > 0) { yield return(new TrainView(runtime.Classifiers) { Text = runtime.LogLine("Re-training Classifiers") }); runtime.LogLine(); } } } this.DataSource.RemoveListeners(listeners); } }