/// <summary> /// Creates an EmotivReader for device /// </summary> /// <param name="device"></param> public ConnectomeReader(IConnectomeDevice <T> device) { this.Device = device; KeepReading = false; LastTime = -1; ReadingThread = new Thread(ReadThreadLoop); }
/// <summary> /// Returns n average state after every intervals /// </summary> /// <param name="device"></param> /// <returns>State with target command average power</returns> protected override IEmotivState ReadingState(IConnectomeDevice <IEmotivState> device, long time) { IntervalStatesList = new LinkedList <IEmotivState>(); while (!ShouldReturn) { IntervalStatesList.AddFirst(device.Read(time)); } ShouldReturn = false; return(ComputeState(IntervalStatesList)); }
/// <summary> /// Attempt to disconnects device, throws exception when failing. /// </summary> /// <param name="device"></param> /// <param name="expMsg"></param> private void TryDisconnecting(IConnectomeDevice <T> device, string expMsg = "Unable to disconnect device: ") { bool didDisconnect = true; string disconnectMsg = ""; device.OnDisconnectAttempted += (b, m) => { didDisconnect = b; disconnectMsg = m; }; device.Disconnect(); if (didDisconnect == false) { ExceptionHandler?.Invoke(new Exception(expMsg + disconnectMsg)); } }
protected override IEmotivState ReadingState(IConnectomeDevice <IEmotivState> device, long time) { IEmotivState currentState = device.Read(time); if (ShouldReadNull == false) { while (currentState.Command == Enum.EmotivCommandType.NULL) { InsureMillisecondPassed(); currentState = device.Read(time); } } return(currentState); }
/// <summary> /// Sets up Device, Reader, and Sampler then start interpreters coroutine /// </summary> public virtual void Setup() { Device = GetDevice(); Reader = GetReader(); Sampler = GetSampler(); Interpeters = GetInterpreters(); DataRateCalculator = GetRateCalculator(); CalculatorConfiguration = GetCalculatorConfiguration(); Reader.OnRead += Sampler.Register; Reader.OnRead += (s) => TotalStatesRead++; Reader.StartReading(); StartCoroutine(InterpetationProcess()); StartCoroutine(UpdateStatusBar()); }
/// <summary> /// Replaces old device with a new one and starts it. Old device is stopped and disconnected. /// </summary> /// <param name="Device"></param> public void PlugDevice(IConnectomeDevice <T> Device) { if (IsReading) { StopReading(); //wait until thread is dead. ReadingThread.Join(); } if (Device != null) { OnStop += (e) => { TryDisconnecting(this.Device, "Unable to disconnect previous device: "); }; StopReading(); } //old device is disconnected and reading is off this.Device = Device; StartReading(); }
public void PlugDevice(IConnectomeDevice <IEmotivState> Device) { reader.PlugDevice(Device); }
/// <summary> /// Reads next state in device /// </summary> /// <param name="device"></param> /// <param name="prevSate"></param> /// <returns></returns> protected abstract T ReadingState(IConnectomeDevice <T> device, long time);
public override void PlugDevice(IConnectomeDevice <IEmotivState> Device) { Content.PlugDevice(Device); }
public abstract void PlugDevice(IConnectomeDevice <IEmotivState> Device);