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(); } }