Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            int pin = 17;
            int lightTimeInMilliseconds = 1000;
            int dimTimeInMilliseconds   = 500;

            Console.WriteLine($"Let's blink an LED!");

            using (GpioController controller = new GpioController())
            {
                controller.OpenPin(pin, PinMode.Output);
                Console.WriteLine($"GPIO pin set to output: {pin}");

                Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs eventArgs) =>
                {
                    controller.Dispose();
                };

                while (true)
                {
                    Console.WriteLine($"Light for {lightTimeInMilliseconds}ms");
                    controller.Write(pin, PinValue.High);
                    Thread.Sleep(lightTimeInMilliseconds);

                    Console.WriteLine($"Dim for {dimTimeInMilliseconds}ms");
                    controller.Write(pin, PinValue.Low);
                    Thread.Sleep(dimTimeInMilliseconds);
                }
            }
        }
Ejemplo n.º 2
0
 public void Dispose()
 {
     _i2cDevice?.Dispose();
     _i2cDevice = null;
     _masterGpioController?.Dispose();
     _masterGpioController = null;
 }
Ejemplo n.º 3
0
 public void Dispose()
 {
     _gpioController?.Dispose();
     _gpioController = null;
     _spiDevice?.Dispose();
     _spiDevice = null;
 }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            //vars
            int pin     = 17;
            int onTime  = 1000; //time light will remain on in milliseconds
            int offTime = 1000; //time light will be off in milliseconds

            //initialize GPIO controller
            using (GpioController rPiController = new GpioController())
            {
                rPiController.OpenPin(pin, PinMode.Output);

                Console.WriteLine("Hello World!");
                Console.WriteLine("Starting blinker...");

                Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs eventArgs) =>
                {
                    rPiController.Dispose(); //release the resources being used
                };

                while (true)
                {
                    rPiController.Write(pin, PinValue.High); //turn on the light
                    Thread.Sleep(onTime);                    //wait
                    Console.WriteLine("On");
                    rPiController.Write(pin, PinValue.Low);  //turn off the light
                    Thread.Sleep(offTime);                   //wait
                    Console.WriteLine("Off");
                }
            }
        }
Ejemplo n.º 5
0
        private static void PwmRaspiTest(RaspberryPiBoard raspi)
        {
            int pinNumber = 12; // PWM0 pin

            Console.WriteLine("Blinking and dimming an LED - Press any key to quit");
            while (!Console.KeyAvailable)
            {
                GpioController ctrl = raspi.CreateGpioController();
                ctrl.OpenPin(pinNumber);
                ctrl.SetPinMode(pinNumber, PinMode.Output);
                ctrl.Write(pinNumber, PinValue.Low);
                Thread.Sleep(500);
                ctrl.Write(pinNumber, PinValue.High);
                Thread.Sleep(1000);
                ctrl.ClosePin(pinNumber);
                ctrl.Dispose();

                var pwm = raspi.CreatePwmChannel(0, 0, 9000, 0.1);
                pwm.Start();
                for (int i = 0; i < 10; i++)
                {
                    pwm.DutyCycle = i * 0.1;
                    Thread.Sleep(500);
                }

                pwm.Stop();
                pwm.Dispose();
            }

            Console.ReadKey(true);
        }
Ejemplo n.º 6
0
 static void Main(string[] args)
 {
     Task.Factory.StartNew(BlinkLight, ct);
     Console.ReadKey();
     cts.Cancel();
     controller.Dispose();
 }
Ejemplo n.º 7
0
        internal void Exit()
        {
            Console.WriteLine("Closing pins.");
            gpioController.ClosePin(upPinNum);
            gpioController.ClosePin(downPinNum);

            gpioController.Dispose();
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Releases the resources used by the <see cref="DCMotor"/> instance.
 /// </summary>
 /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         Controller?.Dispose();
         Controller = null;
     }
 }
Ejemplo n.º 9
0
 /// <inheritdoc/>
 public void Dispose()
 {
     if (_shouldDispose)
     {
         _controller?.Dispose();
         _controller = null !;
     }
 }
Ejemplo n.º 10
0
 /// <inheritdoc/>
 public void Dispose()
 {
     if (_controller != null)
     {
         _controller.Dispose();
         _controller = null;
     }
 }
Ejemplo n.º 11
0
 public virtual void Dispose()
 {
     if (_masterGpioController != null)
     {
         _masterGpioController.Dispose();
         _masterGpioController = null;
     }
 }
Ejemplo n.º 12
0
 /// <inheritdoc/>
 protected override void Dispose(bool disposing)
 {
     _masterGpioController?.Dispose();
     _masterGpioController = null;
     _bus?.Dispose();
     _bus = null;
     base.Dispose(disposing);
 }
Ejemplo n.º 13
0
 static void Main(string[] args)
 {
     try
     {
         var drvGpio = new LibGpiodDriver(GPIOCHIP);
         controller = new GpioController(PinNumberingScheme.Logical, drvGpio);
         //set value
         if (!controller.IsPinOpen(LED_PIN) && !controller.IsPinOpen(BUTTON_PIN))
         {
             controller.OpenPin(LED_PIN, PinMode.Output);
             controller.OpenPin(BUTTON_PIN, PinMode.Input);
         }
         else
         {
             Console.WriteLine("LED_PIN or BUTTON_PIN is busy");
             exitCode = -1;
             return;
         }
         controller.Write(LED_PIN, ledPinValue); //LED OFF
         //
         Console.WriteLine("CTRL+C to interrupt the read operation:");
         controller.RegisterCallbackForPinValueChangedEvent(BUTTON_PIN, PinEventTypes.Rising, (o, e) =>
         {
             ledPinValue = !ledPinValue;
             controller.Write(LED_PIN, ledPinValue);
             Console.WriteLine($"Press button, LED={ledPinValue}");
         });
         //Console
         ConsoleKeyInfo cki;
         while (true)
         {
             Console.Write("Press any key, or 'X' to quit, or ");
             Console.WriteLine("CTRL+C to interrupt the read operation:");
             // Start a console read operation. Do not display the input.
             cki = Console.ReadKey(true);
             // Announce the name of the key that was pressed .
             Console.WriteLine($"  Key pressed: {cki.Key}\n");
             // Exit if the user pressed the 'X' key.
             if (cki.Key == ConsoleKey.X)
             {
                 break;
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine($"Error: {ex}");
         exitCode = -2;
     }
     finally
     {
         if (controller is not null)
         {
             controller.Dispose();
         }
     }
     Environment.Exit(exitCode);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Cleanup.
 /// Failing to dispose this class, especially when callbacks are active, may lead to undefined behavior.
 /// </summary>
 public void Dispose()
 {
     // this condition only applies to GPIO devices
     if (_shouldDispose)
     {
         _gpioController?.Dispose();
         _gpioController = null !;
     }
 }
Ejemplo n.º 15
0
        /// <inheritdoc/>
        public void Dispose()
        {
            if (_shouldDispose)
            {
                _controller?.Dispose();
            }

            _i2cDevice?.Dispose();
        }
Ejemplo n.º 16
0
 /// <inheritdoc/>
 public void Dispose()
 {
     Stop();
     if (_shouldDispose)
     {
         _controller?.Dispose();
         _controller = null;
     }
 }
Ejemplo n.º 17
0
 /// <inheritdoc/>
 public void Dispose()
 {
     _i2cDevice?.Dispose();
     _i2cDevice = null !;
     if (_shouldDispose)
     {
         _controller?.Dispose();
         _controller = null;
     }
 }
Ejemplo n.º 18
0
 public void Dispose()
 {
     _running = false;
     _gpioController?.ClosePin(_pin);
     if (_shouldDispose)
     {
         _gpioController?.Dispose();
         _gpioController = null;
     }
 }
            protected override void Dispose(bool disposing)
            {
                if (_shouldDispose)
                {
                    _controller?.Dispose();
                    _controller = null;
                }

                base.Dispose(disposing);
            }
Ejemplo n.º 20
0
 /// <inheritdoc/>
 public void Dispose()
 {
     if (_disposeGpioController)
     {
         _gpioDevice?.Dispose();
         _gpioDevice = null;
     }
     _spiDevice?.Dispose();
     _spiDevice = null;
 }
Ejemplo n.º 21
0
        /// <inheritdoc/>
        protected override void Dispose(bool disposing)
        {
            if (_shouldDispose)
            {
                _controller?.Dispose();
            }

            Device.Dispose();
            base.Dispose(disposing);
        }
Ejemplo n.º 22
0
        /// <inheritdoc/>
        public void Dispose()
        {
            if (_shouldDispose)
            {
                _gpioController?.Dispose();
                _gpioController = null;
            }

            _spiDevice?.Dispose();
            _spiDevice = null;
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Disposes the <see cref="ExplorerHat"/> instance
        /// </summary>
        public void Dispose()
        {
            Lights.Dispose();
            Motors.Dispose();

            if (_shouldDispose)
            {
                _controller?.Dispose();
                _controller = null !;
            }
        }
        /// <summary>
        ///     Reset the I2C switch.
        /// </summary>
        public void Reset()
        {
            GpioController gpio = new GpioController();

            gpio.OpenPin(ResetPin, PinMode.Output);
            gpio.Write(ResetPin, PinValue.Low);
            Thread.Sleep(1); // wait 1ms before setting the pin high again
            gpio.Write(ResetPin, PinValue.High);
            Thread.Sleep(1); // wait another 1ms for the reset to complete
            gpio.Dispose();
        }
Ejemplo n.º 25
0
        public void Dispose()
        {
            foreach (var pin in _changeHandlers)
            {
                _controller.UnregisterCallbackForPinValueChangedEvent(pin, PinFalling);
                _controller.UnregisterCallbackForPinValueChangedEvent(pin, PinRising);
            }

            _controller.Dispose();
            _pinChanged.Dispose();
        }
Ejemplo n.º 26
0
        /// <inheritdoc/>
        public void Dispose()
        {
            if (_shouldDispose)
            {
                _gpioDevice?.Dispose();
                _gpioDevice = null !;
            }

            _spiDevice?.Dispose();
            _spiDevice = null !;
        }
Ejemplo n.º 27
0
 public void CleanUp()
 {
     childSocket.Close();
     controller.ClosePin(26);
     controller.ClosePin(19);
     controller.ClosePin(16);
     controller.ClosePin(20);
     controller.ClosePin(21);
     controller.Dispose();
     running = false;
 }
Ejemplo n.º 28
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    _controller.Dispose();
                }

                disposedValue = true;
            }
        }
Ejemplo n.º 29
0
 protected virtual void Dispose(bool isDisposing)
 {
     if (!isDisposed)
     {
         if (isDisposing)
         {
             controller.Dispose();
             controller = null;
         }
         isDisposed = true;
     }
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Dispose method.
 /// </summary>
 public void Dispose()
 {
     // Dispose the connection with Azure IoT Hub.
     _deviceClient?.Dispose();
     _deviceClient = null;
     // Dispose the Raspberry Pi controller.
     _gpioController?.Dispose();
     _gpioController = null;
     // Dispose temperature sensor.
     _temperatureSensor?.Dispose();
     _temperatureSensor = null;
 }