private void InitGpio()
        {
            var gpio = GpioController.GetDefault();

            // show an error if there is no GPIO controller
            if (gpio == null)
            {
                GpioStatus.Text = "There is no GPIO controller on this device.";
                return;
            }

            buttonPin = gpio.OpenPin(BUTTON_PIN);
            ledPin    = gpio.OpenPin(LED_PIN);

            ledPin.Write(GpioPinValue.Low);
            ledPin.SetDriveMode(GpioPinDriveMode.Output);

            if (buttonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
            {
                buttonPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            }
            else
            {
                buttonPin.SetDriveMode(GpioPinDriveMode.Input);
            }

            buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);

            buttonPin.ValueChanged += buttonPin_ValueChanged;

            GpioStatus.Text = "GPIO pins initialized correctly.";
        }
Beispiel #2
0
        public void InitGPIO()
        {
            var gpio = GpioController.GetDefault();

            // Show an error if there is no GPIO controller
            if (gpio == null)
            {
                throw new InvalidOperationException("There is no GPIO controller on this device.");
            }

            gpioPin = gpio.OpenPin(pinNumber);
            // Check if input pull-up resistors are supported
            if (gpioPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
            {
                gpioPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            }
            else
            {
                gpioPin.SetDriveMode(GpioPinDriveMode.Input);
            }
            // Set a debounce timeout to filter out switch bounce noise from a button press
            gpioPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);
            // Register for the ValueChanged event so our buttonPin_ValueChanged
            // function is called when the button is pressed
            gpioPin.ValueChanged += pin_ValueChanged;
        }
Beispiel #3
0
        public MainPage()
        {
            InitializeComponent();

            try
            {
                var gpioController = GpioController.GetDefault();

                _inputPin  = gpioController.OpenPin(INDEX_INPUT_PIN, GpioSharingMode.Exclusive);
                _outputPin = gpioController.OpenPin(INDEX_OUTPUT_PIN, GpioSharingMode.Exclusive);

                // Use InputPullUp if supported, otherwise fall back to Input (floating)
                _inputDriveMode =
                    _inputPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp) ?
                    GpioPinDriveMode.InputPullUp : GpioPinDriveMode.Input;

                _inputPin.SetDriveMode(_inputDriveMode);

                _outputPin.Write(GpioPinValue.Low);
                _outputPin.SetDriveMode(GpioPinDriveMode.Output);

                _changeReader = new GpioChangeReader(_inputPin, 43)
                {
                    Polarity = GpioChangePolarity.Falling,
                };

                _timer          = new DispatcherTimer();
                _timer.Interval = TimeSpan.FromMilliseconds(INTERVAL_DATA_READING);
                _timer.Tick    += HandleEvent_DispatcherTimer_Tick;
            }
            catch (Exception ex)
            {
                UpdateStatus(ex.Message);
            }
        }
Beispiel #4
0
        private void InitializeGpio()
        {
            _gpio = GpioController.GetDefault();
            if (_gpio == null)
            {
                return;
            }

            // Initialize Red Led
            _redLedPin = _gpio.OpenPin(RED_LED_PIN);
            _redLedPin.Write(GpioPinValue.High);
            _redLedPin.SetDriveMode(GpioPinDriveMode.Output);

            // Initialize Yellow Led
            _yellowLedPin = _gpio.OpenPin(YLW_LED_PIN);
            _yellowLedPin.Write(GpioPinValue.High);
            _yellowLedPin.SetDriveMode(GpioPinDriveMode.Output);

            // Initialize Yellow Button
            _yellowButtonPin = _gpio.OpenPin(YLW_BTN_PIN);

            if (_yellowButtonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
            {
                _yellowButtonPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            }
            else
            {
                _yellowButtonPin.SetDriveMode(GpioPinDriveMode.Input);
            }

            _yellowButtonPin.DebounceTimeout = TimeSpan.FromMilliseconds(100);
            _yellowButtonPin.ValueChanged   += _yellowButtonPin_ValueChanged;
        }
Beispiel #5
0
        /// <summary>Constructs a new instance.</summary>
        /// <param name="DigitalPin3">The mainboard pin that has digital pin.</param>
        /// <param name="DigitalPin4">The mainboard pin that has digital pin.</param>
        public Button(int DigitalPin3, int DigitalPin4)
        {
            //Socket socket = Socket.GetSocket(socketNumber, true, this, null);

            //socket.EnsureTypeIsSupported(new char[] { 'X', 'Y' }, this);

            this.currentMode = LedMode.Off;
            var controller = GpioController.GetDefault();

            this.led = controller.OpenPin(DigitalPin4);
            this.led.SetDriveMode(GpioPinDriveMode.Output);

            this.input = controller.OpenPin(DigitalPin3);//GTI.InterruptInputFactory.Create(socket, GT.Socket.Pin.Three, GTI.GlitchFilterMode.On, GTI.ResistorMode.PullUp, GTI.InterruptMode.RisingAndFallingEdge, this);
            if (input.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
            {
                input.SetDriveMode(GpioPinDriveMode.InputPullUp);
            }
            else
            {
                input.SetDriveMode(GpioPinDriveMode.Input);
            }

            //this.input.Interrupt += this.OnInterrupt;
            input.ValueChanged += Input_ValueChanged;;
        }
Beispiel #6
0
        private void InitGPIO()
        {
            var gpio = GpioController.GetDefault();

            // Show an error if there is no GPIO controller
            if (gpio == null)
            {
                WindStatus.Text = "There is no GPIO controller on this device.";
                return;
            }

            sensorPin = gpio.OpenPin(BUTTON_PIN);

            // Check if input pull-up resistors are supported
            if (sensorPin.IsDriveModeSupported(GpioPinDriveMode.InputPullDown))
            {
                sensorPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            }
            else
            {
                sensorPin.SetDriveMode(GpioPinDriveMode.Input);
            }

            // Set a debounce timeout to filter out switch bounce noise from a button press
            sensorPin.DebounceTimeout = TimeSpan.FromMilliseconds(10);

            // Register for the ValueChanged event so our buttonPin_ValueChanged
            // function is called when the button is pressed
            sensorPin.ValueChanged += windsensorTriggered;

            WindStatus.Text = "GPIO pins initialized correctly.";

            // calculate windspeed every second
            windsensorTimer = new Timer(windsensorTimerCallback, null, 1000, 1000);
        }
Beispiel #7
0
        private GpioPin doorSensorPin;                                                          // A reference where the doorSensor object will be stored in

        // Initialize the door sensor pin
        private Boolean initDoorSensor()
        {
            GpioController gpio = GpioController.GetDefault();                                  // Get the default Gpio Controller

            if (gpio == null)                                                                   // Check whether the device has a Gpio Controller
            {
                Debug.WriteLine("There is no Gpio controller on this device");
                return(false);
            }

            doorSensorPin = gpio.OpenPin(DOOR_PIN);                                             // Open the door sensor pin

            // Set the doorpin's drive mode to input and pullup (if supported)
            if (doorSensorPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
            {
                doorSensorPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            }
            else
            {
                doorSensorPin.SetDriveMode(GpioPinDriveMode.Input);
            }

            doorSensorPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);                      // Set a debounce timeout of 50ms
            doorSensorPin.ValueChanged   += doorValueHasChanged;                                // Add a callback

            Debug.WriteLine("The misc gpio has been initialized");
            return(true);
        }
Beispiel #8
0
        private void InitGPIO()
        {
            var gpio = GpioController.GetDefault();

            // Show an error if there is no GPIO controller
            if (gpio == null)
            {
                state.Text = "There is no GPIO controller on this device.";
                return;
            }

            buttonPin = gpio.OpenPin(BUTTON_PIN);

            // Check if input pull-up resistors are supported
            if (buttonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
            {
                buttonPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            }
            else
            {
                buttonPin.SetDriveMode(GpioPinDriveMode.Input);
            }

            // Set a debounce timeout to filter out switch bounce noise from a button press
            buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);

            //button interrupt by delegate
            buttonPin.ValueChanged += buttonPin_ValueChanged;

            state.Text = "GPIO pins initialized correctly.";
        }
Beispiel #9
0
        /// <summary>Constructs a new instance.</summary>
        /// <param name="DataReadyIntPin">The GPIO pin on the FEZ board that will connect to the DRDY (Data Ready, Interupt) pin on the slave device.</param>
        public Compass(int DataReadyIntPin)
        {
            this.writeBuffer1 = new byte[1];
            this.readBuffer6  = new byte[6];

            // Device I2C1 Slave address
            I2cConnectionSettings Setting = new I2cConnectionSettings(I2C_SLAVE_ADDRESS);

            Setting.BusSpeed = I2cBusSpeed.StandardMode; // 100kHz

            var ctrler = I2cController.FromName(FEZ.I2cBus.I2c1);
            var device = ctrler.GetDevice(Setting);

            i2c = device;

            TimerInterval = new TimeSpan(0, 0, 0, 0, 200);
            autoEvent     = new AutoResetEvent(false);
            var controller = GpioController.GetDefault();

            this.dataReady = controller.OpenPin(DataReadyIntPin);//GTI.InterruptdataReadyFactory.Create(socket, GT.Socket.Pin.Three, GTI.GlitchFilterMode.On, GTI.ResistorMode.PullUp, GTI.InterruptMode.RisingAndFallingEdge, this);

            if (dataReady.IsDriveModeSupported(DataReadyIntPin, GpioPinDriveMode.InputPullUp))
            {
                dataReady.SetDriveMode(GpioPinDriveMode.InputPullUp);
            }
            else
            {
                dataReady.SetDriveMode(GpioPinDriveMode.Input);
            }

            dataReady.ValueChanged += OnInterrupt;
        }
        private void InitGPIO()
        {
            var gpio = GpioController.GetDefault();

            // Show an error if there is no GPIO controller


            buttonPin = gpio.OpenPin(BUTTON_PIN);
            if (buttonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
            {
                buttonPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            }
            else
            {
                buttonPin.SetDriveMode(GpioPinDriveMode.Input);
            }



            // ledPin = gpio.OpenPin(LED_PIN1);
            //  ledPin.Write(GpioPinValue.High);
            // ledPin.SetDriveMode(GpioPinDriveMode.Output);


            // Set a debounce timeout to filter out switch bounce noise from a button press
            buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);

            // Register for the ValueChanged event so our buttonPin_ValueChanged
            // function is called when the button is pressed
            buttonPin.ValueChanged += buttonPin_ValueChangedAsync;
            ledPin = gpio.OpenPin(LED_PIN1);

            ledPin.SetDriveMode(GpioPinDriveMode.Output);
            ledPin.Write(GpioPinValue.High);
        }
Beispiel #11
0
        /// <summary>Constructs a new instance.</summary>
        /// <param name="socketNumber">The mainboard socket that has the module plugged into it.</param>
        public Joystick(int AnalogPin4, int AnalogPin5, int DigitalPin3)
        {
            //Socket socket = Socket.GetSocket(socketNumber, true, this, null);
            //socket.EnsureTypeIsSupported('A', this);
            var controller = AdcController.GetDefault();

            this.inputX = controller.OpenChannel(AnalogPin4); //GTI.AnalogInputFactory.Create(socket, Socket.Pin.Four, this);
            this.inputY = controller.OpenChannel(AnalogPin5); //GTI.AnalogInputFactory.Create(socket, Socket.Pin.Five, this);
            var DigitalController = GpioController.GetDefault();

            this.input = DigitalController.OpenPin(DigitalPin3);//GTI.InterruptInputFactory.Create(socket, GT.Socket.Pin.Three, GTI.GlitchFilterMode.On, GTI.ResistorMode.PullUp, GTI.InterruptMode.RisingAndFallingEdge, this);
            if (input.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
            {
                input.SetDriveMode(GpioPinDriveMode.InputPullUp);
            }
            else
            {
                input.SetDriveMode(GpioPinDriveMode.Input);
            }
            input.ValueChanged += Input_ValueChanged;
            //this.input = GTI.InterruptInputFactory.Create(socket, GT.Socket.Pin.Three, GTI.GlitchFilterMode.On, GTI.ResistorMode.PullUp, GTI.InterruptMode.RisingAndFallingEdge, this);
            //this.input.Interrupt += (a, b) => this.OnJoystickEvent(this, b ? ButtonState.Released : ButtonState.Pressed);

            this.offsetX = 0;
            this.offsetY = 0;
            this.samples = 5;
        }
Beispiel #12
0
        private void InitPico()
        {
            // Set the DebounceTimeout to ignore noisey signals
            clockPin.DebounceTimeout = TimeSpan.FromMilliseconds(BOUNCE_TIME);
            pulsePin.DebounceTimeout = TimeSpan.FromMilliseconds(BOUNCE_TIME);

            clockPin.SetDriveMode(clockPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp)
                ? GpioPinDriveMode.InputPullUp
                : GpioPinDriveMode.Input);

            pulsePin.Write(GpioPinValue.High);
            pulsePin.SetDriveMode(GpioPinDriveMode.Output);

            // Add listener
            clockPin.ValueChanged += Pin_ValueChanged;
        }
Beispiel #13
0
        private void InitGPIO()
        {
            var gpio = GpioController.GetDefault();

            // Show an error if there is no GPIO controller
            if (gpio == null)
            {
                //status.Text = "There is no GPIO controller on this device.";
                return;
            }

            buttonPin = gpio.OpenPin(BUTTON_PIN);



            // Check if input pull-up resistors are supported
            if (buttonPin.IsDriveModeSupported(Windows.Devices.Gpio.GpioPinDriveMode.InputPullUp))
            {
                buttonPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            }
            else
            {
                buttonPin.SetDriveMode(GpioPinDriveMode.Input);
            }

            // Set a debounce timeout to filter out switch bounce noise from a button press
            buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);

            // Register for the ValueChanged event so our buttonPin_ValueChanged
            // function is called when the button is pressed
            buttonPin.ValueChanged += buttonPin_ValueChanged;
        }
Beispiel #14
0
        private void InitGPIO()
        {
            var gpio = GpioController.GetDefault();

            if (gpio == null)
            {
                GpioStatus.Text = "There is no GPIO controller on this device.";
                return;
            }
            pushButton = gpio.OpenPin(PB_PIN);
            aButton    = gpio.OpenPin(A_PIN);
            aButton.SetDriveMode(GpioPinDriveMode.Input);

            if (pushButton.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
            {
                pushButton.SetDriveMode(GpioPinDriveMode.InputPullUp);
            }
            else
            {
                pushButton.SetDriveMode(GpioPinDriveMode.Input);
            }

            pushButton.DebounceTimeout = TimeSpan.FromMilliseconds(50);

            pushButton.ValueChanged += GpioAct;
            GpioStatus.Text          = "GPIO pins initialized correctly.";
        }
Beispiel #15
0
        private void InitGPIO()
        {
            var gpio = GpioController.GetDefault();

            if (gpio == null)
            {
                _pin          = null;
                GpioText.Text = "There is no GPIO controller on this device.";
                return;
            }

            _pin = gpio.OpenPin(LED_PIN);
            _pin.Write(GpioPinValue.High);
            _pin.SetDriveMode(GpioPinDriveMode.Output);

            _buttonPin = gpio.OpenPin(BUTTON_PIN);
            _buttonPin.SetDriveMode(
                _buttonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp)
                  ? GpioPinDriveMode.InputPullUp
                  : GpioPinDriveMode.Input);
            _buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);
            _buttonPin.ValueChanged   += buttonPin_ValueChanged;

            GpioText.Text = "GPIO pin initialized correctly.";
        }
Beispiel #16
0
        public void Init(GpioPin gpioPin)
        {
            // Use InputPullUp if supported, otherwise fall back to Input (floating)
            inputDriveMode =
                gpioPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp) ?
                GpioPinDriveMode.InputPullUp : GpioPinDriveMode.Input;

            gpioPin.SetDriveMode(inputDriveMode);
            pin = gpioPin;
        }
Beispiel #17
0
 /// <summary>
 /// Sets a drive mode with a fallback mode if the requested mode is not supported.
 /// </summary>
 /// <param name="pin">
 /// The pin to set.
 /// </param>
 /// <param name="driveMode">
 /// The requested drive mode.
 /// </param>
 /// <param name="fallbackMode">
 /// The fallback drive mode.
 /// </param>
 static public void SetDriveModeWithFallback(this GpioPin pin, GpioPinDriveMode driveMode, GpioPinDriveMode fallbackMode)
 {
     if (pin.IsDriveModeSupported(driveMode))
     {
         pin.SetDriveMode(driveMode);
     }
     else
     {
         pin.SetDriveMode(fallbackMode);
     }
 }
Beispiel #18
0
        void _init()
        {
            _pin = _gpio.OpenPin(_pinNumber, _sharingMode);

            if (!_pin.IsDriveModeSupported(_driveMode))
            {
                throw new NotSupportedException($"Drive mode {_driveMode} not supported on pin {_pinNumber}");
            }

            _pin.SetDriveMode(_driveMode);
        }
Beispiel #19
0
        /// <summary>
        /// Attempts to initialize Gpio for application. This includes doorbell interaction and locking/unlccking of door.
        /// Returns true if initialization is successful and Gpio can be utilized. Returns false otherwise.
        /// </summary>
        public bool Initialize()
        {
            // Gets the GpioController
            gpioController = GpioController.GetDefault();
            if (gpioController == null)
            {
                // There is no Gpio Controller on this device, return false.
                return(false);
            }

            // Opens the GPIO pin that interacts with the doorbel button
            doorbellPin = gpioController.OpenPin(GpioConstants.ButtonPinID);

            if (doorbellPin == null)
            {
                // Pin wasn't opened properly, return false
                return(false);
            }

            // Set a debounce timeout to filter out switch bounce noise from a button press
            doorbellPin.DebounceTimeout = TimeSpan.FromMilliseconds(75);

            if (doorbellPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
            {
                // Take advantage of built in pull-up resistors of Raspberry Pi 2 and DragonBoard 410c
                doorbellPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            }
            else
            {
                // MBM does not support PullUp as it does not have built in pull-up resistors
                doorbellPin.SetDriveMode(GpioPinDriveMode.Input);
            }

            //Initialize PIR Sensor
            pirSensor = new PirSensor(GpioConstants.PirSensorPinID, PirSensor.SensorType.ActiveHigh);
            pirSensor.motionDetected += PirSensor_motionDetected;

            /*       // Opens the GPIO pin that interacts with the door lock system
             *     doorLockPin = gpioController.OpenPin(GpioConstants.DoorLockPinID);
             *     if(doorLockPin == null)
             *     {
             *         // Pin wasn't opened properly, return false
             *         return false;
             *     }
             *     // Sets doorbell pin drive mode to output as pin will be used to output information to lock
             *     doorLockPin.SetDriveMode(GpioPinDriveMode.Output);
             *     // Initializes pin to high voltage. This locks the door.
             *     doorLockPin.Write(GpioPinValue.High);*/

            //Initialization was successfull, return true
            return(true);
        }
Beispiel #20
0
        /**
         * @brief
         *
         * @details
         *
         *
         * @param in aPin    GPIO Pin assigned to Single-bus Data Pin
         */
        public void Initialize(GpioPin aPin)
        {
            /// @par Process Design Language
            /// -# Determine the input drive mode
            ///   - Use InputPullUp if supported, otherwise fall back to Input (floating)
            this.inputDriveMode = aPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp) ?
                                  this.inputDriveMode = GpioPinDriveMode.InputPullUp :
                                                        this.inputDriveMode = GpioPinDriveMode.Input;

            /// -# Store the Input Pin and set the Input Pin Drive Mode
            this.pin = aPin;
            this.pin.SetDriveMode(GpioPinDriveMode.Output);
        }
Beispiel #21
0
        /// <summary>Constructs a new TouchC8 sensor.</summary>
        /// <param name="socketNumber">The socket number the sensor is plugged into.</param>
        public TouchC8(string I2CBus, int DigitalPin3, int DigitalPin6)
        {
            this.readBuffer    = new byte[1];
            this.writeBuffer   = new byte[2];
            this.addressBuffer = new byte[1];

            //this.socket = GT.Socket.GetSocket(socketNumber, false, this, "I");
            //this.reset = GpioPinFactory.Create(this.socket, GT.Socket.Pin.Six, true, this);
            var controller = GpioController.GetDefault();

            this.reset = controller.OpenPin(DigitalPin6);
            this.reset.SetDriveMode(GpioPinDriveMode.Output);


            this.Reset();
            var Devices = DeviceInformation.FindAll(I2CBus);
            // Device I2C1 Slave address
            I2cConnectionSettings Setting = new I2cConnectionSettings(TouchC8.I2C_ADDRESS);

            Setting.BusSpeed = I2cBusSpeed.StandardMode; // 100kHz
            this.device      = I2cDevice.FromId(Devices[0].Id, Setting);
            //this.device = I2cDeviceFactory.Create(this.socket, TouchC8.I2C_ADDRESS, TouchC8.I2C_CLOCK_RATE, this);

            //this.interrupt = GpioPinFactory.Create(socket, GT.Socket.Pin.Three, GTI.GlitchFilterMode.Off, GTI.ResistorMode.PullUp, GTI.InterruptMode.FallingEdge, this);
            //this.interrupt.Interrupt += this.OnInterrupt;

            this.interrupt = controller.OpenPin(DigitalPin3);//GTI.InterruptInputFactory.Create(socket, GT.Socket.Pin.Three, GTI.GlitchFilterMode.On, GTI.ResistorMode.PullUp, GTI.InterruptMode.RisingAndFallingEdge, this);
            if (interrupt.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
            {
                interrupt.SetDriveMode(GpioPinDriveMode.InputPullUp);
            }
            else
            {
                interrupt.SetDriveMode(GpioPinDriveMode.Input);
            }

            //this.input.Interrupt += this.OnInterrupt;
            interrupt.ValueChanged += Interrupt_ValueChanged;


            this.previousWheelDirection = (Direction)(-1);
            this.previousWheelPosition  = 0;
            this.previousWheelTouched   = false;
            this.previousButton1Touched = false;
            this.previousButton2Touched = false;
            this.previousButton3Touched = false;

            Thread.Sleep(250);

            this.ConfigureSPM();
        }
        public ButtonListener(GpioController controller, int pin)
        {
            _gpio = controller.OpenPin(pin);

            var driveMode = _gpio.IsDriveModeSupported(GpioPinDriveMode.InputPullUp)
                ? GpioPinDriveMode.InputPullUp
                : GpioPinDriveMode.Input;

            _gpio.SetDriveMode(driveMode);

            _gpio.DebounceTimeout = TimeSpan.FromMilliseconds(50);

            _gpio.ValueChanged += GpioOnValueChanged;
        }
Beispiel #23
0
 private void SetupPhotoresistor()
 {
     resistorPin = gpioController.OpenPin(RESISTOR_PIN);
     if (resistorPin.IsDriveModeSupported(GpioPinDriveMode.InputPullDown))
     {
         resistorPin.SetDriveMode(GpioPinDriveMode.InputPullDown);
     }
     else
     {
         resistorPin.SetDriveMode(GpioPinDriveMode.Input);
     }
     resistorPin.DebounceTimeout = new TimeSpan(100);
     resistorPin.ValueChanged   += PhotoresistorChanged;
 }
Beispiel #24
0
        private void InitGPIO()
        {
            var gpio = GpioController.GetDefault();

            // Show an error if there is no GPIO controller
            if (gpio == null)
            {
                ledPin  = null;
                ledPin2 = null;
                return;
            }

            //Init pins
            ledPin      = gpio.OpenPin(LED_PIN);
            ledPin2     = gpio.OpenPin(LED_PIN2);
            solenoidPin = gpio.OpenPin(SOLENOID_PIN);
            buttonPin   = gpio.OpenPin(BUTTON_PIN);
            relayPin    = gpio.OpenPin(RELAY_PIN);
            signPin     = gpio.OpenPin(SIGN_PIN);
            ledPin.SetDriveMode(GpioPinDriveMode.Output);
            ledPin2.SetDriveMode(GpioPinDriveMode.Output);
            solenoidPin.SetDriveMode(GpioPinDriveMode.Output);
            relayPin.SetDriveMode(GpioPinDriveMode.Output);
            signPin.SetDriveMode(GpioPinDriveMode.Output);
            // Check if input pull-up resistors are supported
            if (buttonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
            {
                buttonPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            }
            else
            {
                //buttonpin.SetDriveMode(GpioPinDriveMode.Input);
                Debug.WriteLine("Could not set Pull up pin state");
                return;
            }
            buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);
            // Register for the ValueChanged event so our buttonPin_ValueChanged
            // function is called when the button is pressed
            buttonPin.ValueChanged += buttonpin_ValueChanged;

            //Init LEDs High (Off)
            ledPin.Write(GpioPinValue.Low);
            ledPin2.Write(GpioPinValue.Low);
            //Init solenoid Low (Off)
            solenoidPin.Write(GpioPinValue.Low);
            //Init relay Low (Off)
            relayPin.Write(GpioPinValue.Low);
            signPin.Write(GpioPinValue.Low);
        }
Beispiel #25
0
        private void InitLedButtonSetup()
        {
            buttonPin = gpioController.OpenPin(BUTTON_PIN);
            ledPin    = gpioController.OpenPin(LED_PIN);
            ledPin.Write(GpioPinValue.High);
            ledPin.SetDriveMode(GpioPinDriveMode.Output);

            if (buttonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
            {
                buttonPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            }

            buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);
            buttonPin.ValueChanged   += ButtonPin_ValueChanged;
        }
Beispiel #26
0
        private void InitGPIO()
        {
            if (gpio == null)
            {
                pinL = null;
                pinR = null;
                return;
            }

            pinL      = gpio.OpenPin(17);
            pinLValue = GpioPinValue.High;
            pinL.SetDriveMode(GpioPinDriveMode.Output);


            pinR      = gpio.OpenPin(18);
            pinRValue = GpioPinValue.High;
            pinR.SetDriveMode(GpioPinDriveMode.Output);


            pin1 = gpio.OpenPin(Button_PIN);
            pin1.SetDriveMode(GpioPinDriveMode.Input);

            pin2 = gpio.OpenPin(Button_PIN2);
            pin2.SetDriveMode(GpioPinDriveMode.Input);

            if (pin1.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
            {
                pin1.SetDriveMode(GpioPinDriveMode.InputPullUp);
            }
            else
            {
                pin1.SetDriveMode(GpioPinDriveMode.Input);
            }
            pin1.DebounceTimeout = TimeSpan.FromMilliseconds(50);
            pin1.ValueChanged   += buttonPin_ValueChanged_R;

            if (pin2.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
            {
                pin2.SetDriveMode(GpioPinDriveMode.InputPullUp);
            }
            else
            {
                pin2.SetDriveMode(GpioPinDriveMode.Input);
            }
            pin2.DebounceTimeout = TimeSpan.FromMilliseconds(50);
            pin2.ValueChanged   += buttonPin_ValueChanged_L;
        }
        public void Start()
        {
            gpio    = GpioController.GetDefault();
            gpioPin = gpio.OpenPin(4);         // pin4

            if (gpioPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
            {
                gpioPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            }
            else
            {
                gpioPin.SetDriveMode(GpioPinDriveMode.Input);
            }

            gpioPin.Write(GpioPinValue.High);
            gpioPin.DebounceTimeout = TimeSpan.FromMilliseconds(25);
            gpioPin.ValueChanged   += Pin_ValueChanged;
        }
Beispiel #28
0
        public void Initialize()
        {
            if (IsInitialized)
            {
                return;
            }
            //IsInitialized = true;

            int pinNumber = Int32.Parse(CalibrationSettings[FlowGPIOPinNumberSetting].ToString());

            var c = GpioController.GetDefault();

            if (c != null)
            {
                try
                {
                    _pin = c.OpenPin(pinNumber);
                    if (_pin != null)
                    {
                        if (_pin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
                        {
                            _pin.SetDriveMode(GpioPinDriveMode.InputPullUp);
                        }

                        _pin.ValueChanged += _pin_ValueChanged;
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine($"Exception:{ex.Message}");
                    KegLogger.KegLogException(ex, "Flow:Initialize", SeverityLevel.Critical);

                    KegLogger.KegLogTrace(ex.Message, "Flow:Initialize", SeverityLevel.Error,
                                          new Dictionary <string, string>()
                    {
                        { "PinNumber", CalibrationSettings[FlowGPIOPinNumberSetting].ToString() }
                    });
                    //Pin used exception
                    //TODO
                }
            }

            IsInitialized = true;
        }
        private void InitGPIO()
        {
            GpioController gpio = GpioController.GetDefault();

            if (gpio == null)
            {
                //TODO: handle GPIO INIT Failure
                return;
            }
            buttonPin = gpio.OpenPin(BUTTON_PIN);
            buttonPin.SetDriveMode(buttonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp)
                ? GpioPinDriveMode.InputPullUp
                : GpioPinDriveMode.Input);

            buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);
            buttonPin.ValueChanged   += buttonPin_ValueChanged;

            StatusBlock.Text = "READY";
        }
        private void StartListening()
        {
            _gpio = GpioController.GetDefault();


            _lightPin = _gpio.OpenPin(4);
            _lightPin.SetDriveMode(GpioPinDriveMode.Output);

            _buttonPin = _gpio.OpenPin(21);
            if (_buttonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
            {
                _buttonPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            }
            else
            {
                _buttonPin.SetDriveMode(GpioPinDriveMode.Input);
            }
            _buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);

            var buttonState = _buttonPin.Read();

            _lightPin.Write((buttonState == GpioPinValue.High) ? GpioPinValue.Low : GpioPinValue.High);

            _buttonPin.ValueChanged += (s, e) =>
            {
                // we are just going to check to see if the button is being pressed first
                if (e.Edge == GpioPinEdge.FallingEdge)
                {
                    var task = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
                    {
                        _messages.Add($"button pressed {_buttonPin.Read().ToString()}");
                        var pinValue = _buttonPin.Read();
                        Debug.WriteLine($"Button pressed: {pinValue.ToString()}");
                        var currentLightValue = _lightPin.Read();
                        var newLightValue     = (currentLightValue == GpioPinValue.High) ? GpioPinValue.Low : GpioPinValue.High;
                        Debug.WriteLine($"light set to: {newLightValue.ToString()}");
                        _lightPin.Write(newLightValue);
                        await SendMessageToIOTHub((newLightValue == GpioPinValue.High), "There was an alert");
                    });
                }
            };
        }