private void ChannelsChangedRaise() { if (ChannelsChanged != null) { ChannelsChanged.Invoke(); } }
/// <summary> /// Waits for decoded frames, updates the <see cref="Channels"/> property and fires /// the <see cref="ChannelsChanged"/> event on a separate thread. /// </summary> private void Receiver() { while (!_stop.IsCancellationRequested) { // Run until stopped... // Wait for frame if (!_frameBuffer.TryDequeue(out PpmFrame frame)) { _frameTrigger.WaitOne(1000); continue; } // Validate var channelCount = frame.Channels.Length; if (channelCount > _channels.Length) { // Too many channels Debug.WriteLine(Resources.Strings.NavioRCInputDecoderChannelOverflow, channelCount, _channels.Length); continue; } // Copy new channel data Array.Copy(frame.Channels, _channels, channelCount); // Fire event ChannelsChanged?.Invoke(this, frame); } }
private void OnDeviceConnected() { var deviceChannels = _currentDevice.Channels .Where(x => x.Type == ChannelType.Signal) .ToDictionary(channelInfo => channelInfo.Name, channelInfo => new EegChannel(_currentDevice, channelInfo)); if (deviceChannels.ContainsKey("T3") && deviceChannels.ContainsKey("O1")) { T3O1SpectrumChannel = new SpectrumChannel(new BipolarDoubleChannel(deviceChannels["T3"], deviceChannels["O1"])); if (deviceChannels.ContainsKey("T4") && deviceChannels.ContainsKey("O2")) { T4O2SpectrumChannel = new SpectrumChannel(new BipolarDoubleChannel(deviceChannels["T4"], deviceChannels["O2"])); IndexChannel = new EegIndexChannel(deviceChannels["T3"], deviceChannels["T4"], deviceChannels["O1"], deviceChannels["O2"]); ChannelsChanged?.Invoke(this, null); } } }
private void OnDeviceConnected() { BatteryChannel = new BatteryChannel(_currentDevice); var deviceChannels = _currentDevice.Channels .Where(x => x.Type == ChannelType.Signal) .ToDictionary(channelInfo => channelInfo.Name, channelInfo => new EegChannel(_currentDevice, channelInfo)); if (deviceChannels.ContainsKey("T3") && deviceChannels.ContainsKey("O1")) { T3O1SignalChannel = new BipolarDoubleChannel(deviceChannels["T3"], deviceChannels["O1"]); T3O1SpectrumChannel = new SpectrumChannel(T3O1SignalChannel); if (deviceChannels.ContainsKey("T4") && deviceChannels.ContainsKey("O2")) { T4O21SignalChannel = new BipolarDoubleChannel(deviceChannels["T4"], deviceChannels["O2"]); T4O2SpectrumChannel = new SpectrumChannel(T4O21SignalChannel); IndexChannel = new EegIndexChannel(deviceChannels["T3"], deviceChannels["T4"], deviceChannels["O1"], deviceChannels["O2"]); IndexChannel.SetWeights(1.00, 1.00, 0.00, 0.00); IndexChannel.Delay = 0.0; IndexViewChannel = new EegIndexChannel(deviceChannels["T3"], deviceChannels["T4"], deviceChannels["O1"], deviceChannels["O2"]); IndexViewChannel.SetWeights(1.00, 1.00, 0.00, 1.00); IndexViewChannel.Delay = 0.0; AlphaLeftPowerChannel = new SpectrumPowerChannel(new List <SpectrumChannel> { T3O1SpectrumChannel }, 8, 14, "AlphaLeft"); BetaLeftPowerChannel = new SpectrumPowerChannel(new List <SpectrumChannel> { T3O1SpectrumChannel }, 14, 34, "BetaLeft"); AlphaRightPowerChannel = new SpectrumPowerChannel(new List <SpectrumChannel> { T4O2SpectrumChannel }, 8, 14, "AlphaRight"); BetaRightPowerChannel = new SpectrumPowerChannel(new List <SpectrumChannel> { T4O2SpectrumChannel }, 14, 34, "BetaRight"); ChannelsChanged?.Invoke(this, null); } } }
public virtual void OnMouseMove(TDouble x01, TDouble y01, MouseButtons mouse, KeyModifiers mods) { // default logic: save coordinate value int code = GetChannelCode(mouse, mods); InputChannel[] cs; if (_channels.TryGetValue(code, out cs)) { var ids = new List <int>(); if (cs[0] != null) { cs[0].SetValue01(x01); ids.Add(cs[0].GetId()); } if (cs[1] != null) { cs[1].SetValue01(y01); ids.Add(cs[1].GetId()); } //!!! here might be started some recursive cascade of channel affecting // our channels affected ChannelsChanged?.Invoke(ids.ToArray()); } }
public void SelectDevice(DeviceInfo deviceInfo) { _currentDevice?.Dispose(); ChannelsChanged?.Invoke(this, null); _currentDevice = new DeviceEnumerator(DeviceType.Brainbit).CreateDevice(deviceInfo); _currentDevice.Connect(); if (_currentDevice.ReadParam <DeviceState>(Parameter.State) != DeviceState.Connected) { _currentDevice.ParameterChanged += (sender, parameter) => { if (parameter == Parameter.State) { if (_currentDevice.ReadParam <DeviceState>(Parameter.State) == DeviceState.Connected) { OnDeviceConnected(); } } }; } else { OnDeviceConnected(); } }