Esempio n. 1
0
        private void Dispose(bool disposing)
        {
            if (_ledRx != null)
            {
                _ledRx.Dispose();
            }
            if (_ledTx != null)
            {
                _ledTx.Dispose();
            }

            SetPower(false);

            if (_rxThread != null)
            {
                _rxThreadStop = true;
                _rxEvent.Set();
                _rxThread.Join();
            }

            if (_hal != null)
            {
                _hal.Dispose();
                _hal = null;
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();

            var buttonReader = new ButtonReader(RunMachineLearningCode);

            buttonReader.ReadButton(cancellationTokenSource.Token);

            _ledRed   = new Led(Led.LedColor.Red);
            _ledGreen = new Led(Led.LedColor.Green);
            _ledBlue  = new Led(Led.LedColor.Blue);

            _buzzer = new Buzzer();

            // Do the test run
            _ledRed.Flash();
            _ledGreen.Flash();
            _ledBlue.Flash();

            _buzzer.Buzz();

            Console.WriteLine("Ready to get going. Press any key to stop the program.");

            try
            {
                while (!Console.KeyAvailable)
                {
                    _ledBlue.On();

                    RunMachineLearningCode(false);
                    _ledBlue.Off();

                    Task.Delay(2000).Wait();
                }
            }
            finally
            {
                cancellationTokenSource.Cancel();

                cancellationTokenSource.Dispose();
                _ledRed.Off();
                _ledGreen.Off();
                _ledBlue.Off();

                buttonReader.Dispose();
                _buzzer.Dispose();
                _ledRed.Dispose();
                _ledGreen.Dispose();
                _ledBlue.Dispose();
            }
        }