Exemplo n.º 1
0
        void Clear()
        {
            if (OpenVibeController.IsRunning)
            {
                OpenVibeController.Stop();
            }

            openVibeWorker.CancelAsync();
            //InitOpenVibeWorker();

            buttonStart.Text    = "Start";
            buttonStart.Enabled = true;

            of = null;
            tf = null;
            cf = null;

            ow = null;
            ew = null;
            cw = null;

            currentForm   = null;
            currentWindow = null;
        }
Exemplo n.º 2
0
        private void buttonStart_Click(object sender, EventArgs e)
        {
            buttonStart.Enabled = false;
            SelectedScenario    = comboBoxScenarioType.SelectedIndex;

            try
            {
                #region 1 Configure start

                IDigitalSignalProcessor dsp = null;
                if (cbEmotivDSP.Checked && cbEmotivDspMethod.SelectedIndex == 0)
                {
                    dsp = new BasicSignalProcessor();
                }
                if (cbFieldTripDSP.Checked && cbFieldTripDspMethod.SelectedIndex == 0)
                {
                    dsp = new BasicSignalProcessor();
                }

                if (rbuttonEmotiv.Checked)
                {
                    if (rbuttonEmotivSignal.Checked)
                    {
                        dataReader = new EmotivRawDataReader();
                    }
                    else
                    {
                        dataReader = new EmotivFileSystemDataReader(textBoxEmotivFile.Text);
                    }

                    int scenario = comboBoxScenarioType.SelectedIndex;
                    if (scenario == 1 || scenario == 2)                              //train and classify
                    {
                        IEpoching epocher = new TimeEpochGenerator(dataReader, 300); //this value depends on your BCI scenario
                        featureGenerator = new EigenVectorFeatureGenerator(epocher);
                    }
                }
                else if (rbuttonOpenVibe.Checked)
                {
                    dataReader = new OpenVibeRawDataReader();
                    int scenario = comboBoxScenarioType.SelectedIndex;
                    //if (scenario==5 || scenario==6) //these two acquire signal from OpenVibe
                    //{
                    //   IEpoching epocher = new CountEpochGenerator(dataReader, samples_per_chunk);
                    //   featureGenerator = new EigenVectorFeatureGenerator(epocher);
                    //}
                    //else
                    featureGenerator = new OpenVibeFeatureGenerator();
                }
                else if (rbuttonFieldTrip.Checked)
                {
                    dataReader = new FieldTripRawDataReader(this.tboxFieldTripHost.Text, Convert.ToInt32(this.ndFieldTripPort.Value));
                    int scenario = comboBoxScenarioType.SelectedIndex;
                    if (scenario == 1 || scenario == 2)
                    {
                        IEpoching epocher = new TimeEpochGenerator(dataReader, 300);//this value depends on your BCI scenario
                        featureGenerator = new EigenVectorFeatureGenerator(epocher);
                    }
                }

                if (dsp != null)
                {
                    dataReader.SetDspProcessor(dsp);
                }
                #endregion

                #region 2 Instantiate and run

                if (rbuttonExperimentator.Checked)
                {
                    //window created without background thread
                    ew = new WPF.ExperimentsWindow(); ew.Show(); currentWindow = ew;

                    currentWindow.Closed += delegate(object wsender, EventArgs we)
                    {
                        buttonStart.Text    = "Start";
                        buttonStart.Enabled = true;
                        ew = null;
                    };
                }
                else
                if (rbuttonEmotiv.Checked || rbuttonOpenVibe.Checked || rbuttonFieldTrip.Checked)
                {
                    switch (comboBoxScenarioType.SelectedIndex)
                    {
                    case 0:        //chart signal
                        if (rbuttonWPFcharting.Checked)
                        {
                            ow = new WPF.OutputWindow(dataReader, -1, -1); ow.Show(); currentWindow = ow;
                        }
                        else if (rbuttonWindowsFormsCharting.Checked)
                        {
                            of = new OutputForm(dataReader); of.Show(); of.Start(); currentForm = of;
                        }
                        break;

                    case 1: tf = new TrainForm(featureGenerator); tf.Show(); currentForm = tf; break;

                    case 2: cf = new ClassifyForm(featureGenerator); cf.Show(); currentForm = cf; break;

                    case 3: ow = new WPF.OutputWindow(dataReader, 165, 830); ow.Show(); currentWindow = ow; break; //xDAWN

                    case 4: ow = new WPF.OutputWindow(dataReader, 250, 830); ow.Show(); currentWindow = ow; break; //CSP

                    case 5: tf = new TrainForm(featureGenerator); tf.Show(); currentForm = tf; break;              //train

                    case 6: cf = new ClassifyForm(featureGenerator); cf.Show(); currentForm = cf; break;           //classify
                    }

                    if (rbuttonOpenVibe.Checked)
                    {
                        openVibeWorker.RunWorkerAsync();
                    }

                    if (currentForm != null)
                    {
                        currentForm.FormClosed += new FormClosedEventHandler(currentForm_FormClosed);
                    }
                    if (currentWindow != null)
                    {
                        currentWindow.Closed += new EventHandler(currentWindow_Closed);
                    }
                }

                if (currentWindow != null)
                {
                    System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(currentWindow);
                }
                #endregion
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                if (ex.Message.IndexOf("edk.dll") >= 0)
                {
                    MessageBox.Show(ex.Message + "\r\n You need edk.dll and edk_utils.dll from the Emotiv Reseach SDK placed in Adastra's installation folder.");
                }
                else
                {
                    MessageBox.Show(ex.Message);
                }

                buttonStart.Enabled = true;
            }
            // }
        }