Exemple #1
0
 public EEGDeviceProducer(EEGDeviceAdapter adapter)
 {
     this.adapter = adapter;
 }
Exemple #2
0
 /**
  * Set the EEGDeviceAdapter that SharpBCI will use, overriding possible calls before
  * @see EEGDeviceAdapter
  */
 public SharpBCIBuilder EEGDeviceAdapter(EEGDeviceAdapter adapter)
 {
     config.adapter = adapter;
     return(this);
 }
Exemple #3
0
        // end variables

        /**
         * @param config a valid config object, generally built with SharpBCIBuilder
         * @see SharpBCIConfig
         * @see SharpBCIBuilder
         */
        public SharpBCI(SharpBCIConfig config)
        {
            Logger.Log("SharpBCI started");

            // begin check args
            if (config.adapter == null)
            {
                throw new ArgumentException("config.adapter must not be null");
            }

            if (config.adapter.channels <= 0)
            {
                throw new ArgumentException("config.channels must be > 0");
            }

            if (config.pipelineFile == null)
            {
                throw new ArgumentException("config.pipelineFile must not be null and must be valid file name");
            }

            if (config.stageScope == null)
            {
                config.stageScope = new Dictionary <string, object>();
            }

            foreach (var key in config.stageScope.Keys)
            {
                if (key.StartsWith(RESERVED_PREFIX, StringComparison.InvariantCulture))
                {
                    throw new ArgumentException(string.Format("{0} is a reserved stage scope keyword", key));
                }
            }
            // end check args

            // begin state config
            adapter           = config.adapter;
            channels          = adapter.channels;
            sampleRate        = adapter.sampleRate;
            _connectionStatus = new double[channels];
            for (int i = 0; i < channels; i++)
            {
                _connectionStatus[i] = 4;
            }
            // end state config

            // kinda a kludge: link up connection status output, flush is called in EEGDeviceProducer
            adapter.AddHandler(EEGDataType.CONTACT_QUALITY, UpdateConnectionStatus);

            // begin internal pipeline construction
            var scope = config.stageScope;

            scope.Add(SCOPE_SHARP_BCI_KEY, this);
            scope.Add(SCOPE_ADAPTER_KEY, adapter);
            scope.Add(SCOPE_CHANNELS_KEY, channels);
            scope.Add(SCOPE_SAMPLE_RATE_KEY, sampleRate);

            stages = PipelineSerializer.CreateFromFile(config.pipelineFile, scope);
            var predictorsList = new List <IPredictorPipeable>();

            foreach (var stage in stages)
            {
                if (stage is IPredictorPipeable)
                {
                    predictorsList.Add((IPredictorPipeable)stage);
                }
            }

            if (predictorsList.Count == 0)
            {
                Logger.Warning("Pipeline does not implement any IPredictors");
            }

            predictors = predictorsList.ToArray();
            // end internal pipeline construction

            // begin start associated threads & EEGDeviceAdapter
            cts         = new CancellationTokenSource();
            taskFactory = new TaskFactory(cts.Token,
                                          TaskCreationOptions.LongRunning,
                                          TaskContinuationOptions.None,
                                          TaskScheduler.Default
                                          );

            foreach (var stage in stages)
            {
                stage.Start(taskFactory, cts);
            }
            // end start associated threads & EEGDeviceAdapter
        }