private async Task RunAlphaDetectedTask(CancellationToken cancelToken) { var timer = new System.Diagnostics.Stopwatch(); timer.Start(); try { while (!cancelToken.IsCancellationRequested) { if (EnableLights) { await GpioPinManager.LightStringMaster.SetLevel(Math.Min(timer.Elapsed.Seconds, 5)); } if (EnableMotor && timer.Elapsed.Seconds > 0) { GpioPinManager.HapticMotorEnable(true); if (timer.Elapsed.Seconds < 5) { await Task.Delay(100 *timer.Elapsed.Seconds, cancelToken); GpioPinManager.HapticMotorEnable(false); await Task.Delay(1000 - (100 * timer.Elapsed.Seconds), cancelToken); } } await Task.Delay(1); } } catch (OperationCanceledException) { } }
private void checkBoxHapticMotor_CheckedChanged(object sender, EventArgs e) { EnableMotor = checkBoxHapticMotor.Checked; if (!EnableMotor) { GpioPinManager.HapticMotorEnable(false); } }
async Task StopAlphaDetected() { if (AlphaCancelTokenSource != null) { AlphaCancelTokenSource.Cancel(); await AlphaDetectedTask; GpioPinManager.HapticMotorEnable(false); AlphaCancelTokenSource = null; await StartLightSequence(); } }
private void OnDetectedBlink(object sender, DetectedBlinkEventArgs e) { if (EnableLights) { switch (e.Eye) { case Eyes.Left: { switch (e.State) { case WinkState.Rising: GpioPinManager.LightLeftRising(); break; case WinkState.Falling: GpioPinManager.LightLeftFalling(); break; case WinkState.Wink: GpioPinManager.LightLeftBlink(); break; } } break; case Eyes.Right: { switch (e.State) { case WinkState.Rising: GpioPinManager.LightRightRising(); break; case WinkState.Falling: GpioPinManager.LightRightFalling(); break; case WinkState.Wink: GpioPinManager.LightRightBlink(); break; } } break; } } }
public Form1() { InitializeComponent(); FormClosing += OnFormClosing; PlatformHelper.PlatformHelper.GetLibraryEnvironment(); HostName = GpioPinManager.LoadFromConfigFile(); GpioPinManager.SetupGpio(); textBoxHostName.Text = HostName; ConnectToServer = false; ActiveClient = null; EnableMotor = true; EnableLights = true; checkBoxHapticMotor.Checked = true; checkBoxLightsAuto.Checked = true; ServersMonitor = new HatServersMonitor(); ServersMonitor.Log += OnLog; ServersMonitor.HatConnectionStatusUpdate += OnHatStatusUpdate; ServersMonitor.HatConnectionChanged += OnHatConnectionChanged; BlinkDetector = new BlinkDetector(); BlinkDetector.DetectedBlink += OnDetectedBlink; SeekingAlpha = new AlphaWaveDetector(); SeekingAlpha.DetectedBrainWave += OnDetectedBrainWave; _ = Task.Run(async() => { //await GpioPinManager.TestConfig(); await ServersMonitor.StartMonitorAsync(); await SeekingAlpha.StartDetectorAsync(); await StartLightFlash(); }); }
private async void checkBoxLightsAuto_CheckedChanged(object sender, EventArgs e) { EnableLights = checkBoxLightsAuto.Checked; if (EnableLights) { if (IsConnected) { await StartLightSequence(); } else { await StartLightFlash(); } } else { await GpioPinManager.LightStringMaster.Stop(); GpioPinManager.AllLightsOff(); } }
private async void OnFormClosing(object sender, FormClosingEventArgs e) { await GpioPinManager.LightStringMaster.Stop(); GpioPinManager.AllOff(); }