Ejemplo n.º 1
0
        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)
            { }
        }
Ejemplo n.º 2
0
 private void checkBoxHapticMotor_CheckedChanged(object sender, EventArgs e)
 {
     EnableMotor = checkBoxHapticMotor.Checked;
     if (!EnableMotor)
     {
         GpioPinManager.HapticMotorEnable(false);
     }
 }
Ejemplo n.º 3
0
        async Task StopAlphaDetected()
        {
            if (AlphaCancelTokenSource != null)
            {
                AlphaCancelTokenSource.Cancel();
                await AlphaDetectedTask;
                GpioPinManager.HapticMotorEnable(false);
                AlphaCancelTokenSource = null;

                await StartLightSequence();
            }
        }
Ejemplo n.º 4
0
        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;
                }
            }
        }
Ejemplo n.º 5
0
        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();
            });
        }
Ejemplo n.º 6
0
        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();
            }
        }
Ejemplo n.º 7
0
        private async void OnFormClosing(object sender, FormClosingEventArgs e)
        {
            await GpioPinManager.LightStringMaster.Stop();

            GpioPinManager.AllOff();
        }