public void TurnLEDsOff()
 {
     greenPinValue = GpioPinValue.High;
     greenPin.Write(greenPinValue);
     redPinValue = GpioPinValue.High;
     redPin.Write(redPinValue);
 }
Example #2
0
        private double PulseIn(GpioPin echoPin, GpioPinValue value)
        {
            var t = Task.Run(() =>
            {
                //Recieve pusle
                while (this.echoPin.Read() != value)
                {
                }
                timeWatcher.Start();

                while (this.echoPin.Read() == value)
                {
                }
                timeWatcher.Stop();
                //Calculating distance
                double distance = timeWatcher.Elapsed.TotalSeconds * 17000;
                return distance;
            });
            bool didComplete = t.Wait(TimeSpan.FromMilliseconds(100));
            if(didComplete)
            {
                return t.Result;
            }
            else
            {
                return 0.0;                
            }
        }
Example #3
0
        public int CheckNum()
        {
            var inputs = new GpioPinValue[4];
            inputs[0] = irPins[0].Read();
            inputs[1] = irPins[1].Read();
            inputs[2] = irPins[2].Read();
            inputs[3] = irPins[3].Read();
            int returnValue = 0;

            if (inputs[0] == GpioPinValue.High)
            {
                returnValue += 1;
            }
            if (inputs[1] == GpioPinValue.High)
            {
                returnValue += 2;
            }
            if (inputs[2] == GpioPinValue.High)
            {
                returnValue += 4;
            }
            if (inputs[3] == GpioPinValue.High)
            {
                returnValue += 8;
            }

            return returnValue;
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="pin">oin the value is for.</param>
 /// <param name="interruptOccurred">True when interrupt occurs, false otherwise.</param>
 /// <param name="edge">Edge that occurred</param>
 /// <param name="currentValue">Current value.</param>
 internal PinInterruptValue(int pin, bool interruptOccurred, GpioPinEdge edge, GpioPinValue currentValue)
 {
     this.Pin = pin;
     this.InterruptOccurred = interruptOccurred;
     this.Edge = edge;
     this.CurrentValue = currentValue;
 }
        public void Write(byte[] data)
        {
            var bits = new GpioPinValue[data.Length * 8];

            for (int i = 0; i < data.Length; i++)
            {
                var datumValues = GetBits(data[i]);
                datumValues.CopyTo(bits, i * 8);
            }

            _csPin.Write(GpioPinValue.Low);
            SyncWaitInterval();

            foreach(var bit in bits)
            {
                _mosiPin.Write(bit);
                _clkPin.Write(GpioPinValue.High);
                SyncWaitInterval();
                _clkPin.Write(GpioPinValue.Low);
                SyncWaitInterval();
            }

            _csPin.Write(GpioPinValue.High);
            SyncWaitInterval();
        }
Example #6
0
 public void WriteOutputPinValue(int pinNumber, GpioPinValue pinValue)
 {
     foreach (var c in _controls.Where(r => r.PinNumber == pinNumber))
     {
         c.WriteOutputPinValue(pinValue);
     }
 }
Example #7
0
        private void InitGPIO()
        {
            GpioController gpio = null;
            try
            {
                gpio = GpioController.GetDefault();
            }
            catch (Exception e)
            {
                GpioStatus.Text = e.Message;
            }

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

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

            GpioStatus.Text = "GPIO pin intitialized correctly.";
        }
Example #8
0
		public void InitializeColumn(TimeSpan debounceTime)
		{
			this.GpioPin = GpioController.GetDefault().OpenPin(this.PinNumber);
            this.GpioPin.SetDriveMode(GpioPinDriveMode.InputPullDown);
			this.PreviousValue = this.GpioPin.Read();
			this.GpioPin.DebounceTimeout = debounceTime;
		}
Example #9
0
        public void SetValue(GpioPinValue value)
        {
            if(pin == null)
                throw new Exception("GPIO Pin not initalized!");

            pin.Write(value);
        }
Example #10
0
        private void InitGPIO()
        {
            var gpio = GpioController.GetDefault();

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

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

            waterPin = gpio.OpenPin(WATER_PIN);
            waterPinValue = GpioPinValue.High;
            //waterPin.Read(waterPinValue);
            waterPin.SetDriveMode(GpioPinDriveMode.Input);

            GpioStatus.Text = "GPIO pin initialized correctly.";

        }
Example #11
0
        private void InitGPIO()
        {
            var mygpio = GpioController.GetDefault();

            // Show an error if there is no GPIO controller
            if (mygpio == null)
            {
                buttonPin = null;
                ledPin = null;
                return;
            }
            ledPin = mygpio.OpenPin(LEDPINNBR);
            ledPin.Write(GpioPinValue.Low); //initialize Led to On as wired in active Low config (+3.3-Led-GPIO)
            ledPin.SetDriveMode(GpioPinDriveMode.Output);

            buttonPin = mygpio.OpenPin(BUTTONPINNBR);
            buttonPin.Write(GpioPinValue.High);
            buttonPin.SetDriveMode(GpioPinDriveMode.Output);
            buttonPinValCurrent = buttonPin.Read();
            buttonPin.SetDriveMode(GpioPinDriveMode.Input);
            buttonPinValPrior = GpioPinValue.High;

            Debug.WriteLine("ButtonPin Value at Init: " + buttonPin.Read() + ",      with Pin ID = " + buttonPin.PinNumber);

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

            // Register for the ValueChanged event so our buttonPin_ValueChanged
            // function is called when the button is pressed
            buttonPin.ValueChanged += buttonPressAction;
        }
Example #12
0
 public void Sleep()
 {
     if (pin != null)
     {
         pinValue = GpioPinValue.High;
         pin.Write(pinValue);
     }
 }
Example #13
0
 public void Reset()
 {
     if (pin != null)
     {
         pinValue = GpioPinValue.Low;
         pin.Write(pinValue);
     }
 }
Example #14
0
        public Led(GpioPin pin)
        {
            _pin = pin;

            _pin.SetDriveMode(GpioPinDriveMode.Output);

            _pinValue = GpioPinValue.Low;
            _pin.Write(_pinValue);
        }
Example #15
0
        public Led(int pinNumber)
        {
            var gpio = GpioController.GetDefault();
            _pin = gpio.OpenPin(pinNumber);
            _pin.SetDriveMode(GpioPinDriveMode.Output);

            _pinValue = GpioPinValue.Low;
            _pin.Write(_pinValue);
        }
Example #16
0
        public AccelStepper(GpioPin motorPinEntity, GpioPin directionPinEntity, GpioPinValue clockwiseVal)
        {
            motorPin = motorPinEntity;
            directionPin = directionPinEntity;
            clockwiseValue = clockwiseVal;

            stopwatch = new Stopwatch();
            stopwatch.Start();
        }
        public void SignalOutputPin(int pinId, GpioPinValue value)
        {
            if (_pin == null)
            {
                _pin = _gpioController.OpenPin(pinId);
                _pin.SetDriveMode(GpioPinDriveMode.Output);
            }

            _pin.Write(value);
        }
Example #18
0
 private void BlimkTimer_Tick(object sender, object e)
 {
     this.button.Fill = grayBrush;
     this.blinkTimer.Stop();
     if (bGpioStatus)
     {
         pinValue = GpioPinValue.Low;
         pin.Write(pinValue);
     }
 }
Example #19
0
        public void TurnGreen()
        {
            _redPinValue = GpioPinValue.Low;
            _redPin.Write(_redPinValue);

            _greenPinValue = GpioPinValue.High;
            _greenPin.Write(_greenPinValue);

            _bluePinValue = GpioPinValue.Low;
            _bluePin.Write(_bluePinValue);
        }
Example #20
0
 public void WriteValue(int c, int r, GpioPinValue value)
 {
     try
     {
         matrix[c, r].Write(value);
     }
     catch
     {
         // TODO: Handle this
     }
 }
        private async void InitializeGPIO()
        {
            try
            {
                GpioController controller = GpioController.GetDefault();

                if (null != controller)
                {
                    // Create and initialize color sensor instance
                    _colorSensor = new TCS34725(RGB_LED_PIN);
                    await _colorSensor.Initialize();
                    _colorSensor.LedState = TCS34725.eLedState.Off;

                    // Setup button pin
                    _gpioPushbutton = controller.OpenPin(PUSH_BUTTON_PIN);
                    _gpioPushbutton.DebounceTimeout = TimeSpan.FromMilliseconds(100); // 100 ms
                    _gpioPushbutton.SetDriveMode(GpioPinDriveMode.Input);
                    _gpioPushbutton.ValueChanged += gpioPushbutton_ValueChanged;

                    // Setup LEDs
                    // Red
                    _gpioRedLED = controller.OpenPin(RED_LED_PIN);
                    _gpioRedLED.SetDriveMode(GpioPinDriveMode.Output);
                    _pinValRed = SetGpioPinState(_gpioRedLED, GpioPinValue.High); // HIGH == ON

                    _timerRed = new DispatcherTimer();
                    _timerRed.Tick += timerRed_Tick;

                    // Green
                    _gpioGreenLED = controller.OpenPin(GREEN_LED_PIN);
                    _gpioGreenLED.SetDriveMode(GpioPinDriveMode.Output);
                    _pinValGreen = SetGpioPinState(_gpioGreenLED, GpioPinValue.High); // HIGH == ON

                    _timerGreen = new DispatcherTimer();
                    _timerGreen.Tick += timerGreen_Tick;

                    // Blue
                    _gpioBlueLED = controller.OpenPin(BLUE_LED_PIN);
                    _gpioBlueLED.SetDriveMode(GpioPinDriveMode.Output);
                    _pinValBlue = SetGpioPinState(_gpioBlueLED, GpioPinValue.High); // HIGH == ON

                    _timerBlue = new DispatcherTimer();
                    _timerBlue.Tick += timerBlue_Tick;

                    _isInitialized = true;
                    Debug.WriteLine("All pins initialized");
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
        private GpioPinValue[] GetBits(byte data)
        {
            var array = new GpioPinValue[8];
            byte mask = 0x01;
            for (int i = 0; i < 8; i++)
            {
                array[i] = (data & mask) > 0 ? GpioPinValue.High : GpioPinValue.Low;
                mask <<= 1;
            }

            return array;
        }
Example #23
0
 private void InitGPIO()
 {
     var gpio = GpioController.GetDefault();
     if (gpio == null)
     {
         throw new Exception("Gpio expected on this device");
     }
     ledPin = gpio.OpenPin(ledPinNumber);
     ledPin.SetDriveMode(GpioPinDriveMode.Output);
     ledPin.Write(GpioPinValue.Low);
     ledVal = GpioPinValue.Low;
 }
 public void ToggleGreen(bool on)
 {
     if (on)
     {
         greenPinValue = GpioPinValue.Low;                
     }
     else
     {
         greenPinValue = GpioPinValue.High;
     }
     greenPin.Write(greenPinValue);
 }
 /// <summary>
 /// Waits until the value of the pin changes to the requested value.
 /// </summary>
 /// <param name="pin">Pin to check the value of.</param>
 /// <param name="value">The value to wait for.</param>
 /// <param name="timeout">How long to wait.</param>
 /// <remarks>This can be quite expensive. Better approach would be to use the pin's events.</remarks>
 public static void WaitFor(this GpioPin pin, GpioPinValue value, int timeout = 0)
 {
     timeout = timeout == 0 ? 4000 : timeout;
     var endTicks = DateTime.UtcNow.Ticks + (timeout * TimeSpan.TicksPerMillisecond);
     
     while (pin.Read() != value)
     {
         if (DateTime.UtcNow.Ticks > endTicks)
         {
             throw new TimeoutException("WaitFor timed out.");
         }
     }
 }
        public void ToggleRed(bool on)
        {
            if (on)
            {
                redPinValue = GpioPinValue.Low;                
            }
            else
            {
                redPinValue = GpioPinValue.High;
            }

            redPin.Write(redPinValue);
        }
Example #27
0
        public LEDPin(int pin, GpioPinValue value)
        {
            this.pin = pin;
            this.value = value;

            var gpio = GpioController.GetDefault();
            ledPin = gpio.OpenPin(pin);

            // Initialize LED to the OFF state by first writing a HIGH value
            // We write HIGH because the LED is wired in a active LOW configuration
            ledPin.Write(this.value);
            ledPin.SetDriveMode(GpioPinDriveMode.Output);
        }
        private void FlipLED()
        {
            pinValue_ms = pin_ms.Read();

            if (pinValue_ms == GpioPinValue.High)
            {
                pin.Write(GpioPinValue.High);
            }
            else
            {
                pin.Write(GpioPinValue.Low);
            }
        }
Example #29
0
 private void Timer_Tick(object sender, object e)
 {            
     if(ledVal == GpioPinValue.High)
     {
         ledPin.Write(GpioPinValue.Low);
         ledVal = GpioPinValue.Low;
     }
     else
     {
         ledPin.Write(GpioPinValue.High);
         ledVal = GpioPinValue.High;
     }
 }
        private void FlipLED()
        {
            pushButtonValue = pushButton.Read();
            lsButtonValue = lsButton.Read();

            if (pushButtonValue == GpioPinValue.High && lsButtonValue == GpioPinValue.High)
            {
                pin.Write(GpioPinValue.High);
            }
            else
            {
                pin.Write(GpioPinValue.Low);
            }
        }
Example #31
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="testPin"></param>
        /// <param name="n"></param>
        /// <returns></returns>
        public float measureTicksPerRead(GpioPin testPin, int n)
        {
            testPin.SetDriveMode(GpioPinDriveMode.Input);
            long t1 = cronometer_.ticks;

            for (int i = 1; i < n; i++)
            {
                GpioPinValue val = testPin.Read();
            }
            long t2 = cronometer_.ticks;

            ticksPerRead_ = t2 - t1;
            usPerRead_    = (float)cronometer_.ticksToUs(ticksPerRead_) / (float)n;
            return(usPerRead_);
        }
Example #32
0
        private GpioPinValue InvertGpioPinValue(GpioPinValue currentPinValue)
        {
            GpioPinValue invertedGpioPinValue;

            if (currentPinValue == GpioPinValue.High)
            {
                invertedGpioPinValue = GpioPinValue.Low;
            }
            else
            {
                invertedGpioPinValue = GpioPinValue.High;
            }

            return(invertedGpioPinValue);
        }
        private void InitGPIO()
        {
            var gpio = GpioController.GetDefault();

            // Show an error if there is no GPIO controller
            if (gpio == null)
            {
                _pin = null;
                return;
            }
            _pin      = gpio.OpenPin(LED_PIN);
            _pinValue = GpioPinValue.High;
            _pin.Write(_pinValue);
            _pin.SetDriveMode(GpioPinDriveMode.Output);
        }
Example #34
0
        private static void InitializePins()
        {
            pins = new Dictionary <int, GpioPin>();

            foreach (var gpioPinNumber in GpioPinNumbers)
            {
                var gpioPin = InitializePin(gpioPinNumber, GpioPinValue.High, GpioPinDriveMode.Output);
                pins.Add(gpioPinNumber, gpioPin);
            }

            _currentPushButtonValue       = GpioPinValue.Low;
            pushButtonPin                 = InitializePin(GPIO_PUSH_BUTTON, _currentPushButtonValue, GpioPinDriveMode.InputPullUp);
            pushButtonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);
            pushButtonPin.ValueChanged   += PushButtonPin_ValueChanged;
        }
 private void BedRoomTimer_Tick(object sender, object e)
 {
     if (BedRoomLED_GpioPinValue == GpioPinValue.High)
     {
         BedRoomLED_GpioPinValue = GpioPinValue.Low;
         BedRoomLED_GpioPin.Write(BedRoomLED_GpioPinValue);
         //LED.Fill = redBrush;
     }
     else
     {
         BedRoomLED_GpioPinValue = GpioPinValue.High;
         BedRoomLED_GpioPin.Write(BedRoomLED_GpioPinValue);
         //LED.Fill = grayBrush;
     }
 }
 private void Timer_Tick(object sender, object e)
 {
     if (_pinValue == GpioPinValue.High)
     {
         _pinValue = GpioPinValue.Low;
         _pin.Write(_pinValue);
         LED.Fill = _redBrush;
     }
     else
     {
         _pinValue = GpioPinValue.High;
         _pin.Write(_pinValue);
         LED.Fill = _grayBrush;
     }
 }
        public void InitalizeLed()
        {
            Debug.WriteLine("InternetLed::InitalizeLed");

            // Now setup the LedControlPin
            gpio = GpioController.GetDefault();

            LedControlGPIOPin = gpio.OpenPin(LedControlPin);
            LedControlGPIOPin.SetDriveMode(GpioPinDriveMode.Output);

            // Get the current pin value
            GpioPinValue startingValue = LedControlGPIOPin.Read();

            _LedState = (startingValue == GpioPinValue.Low) ? eLedState.On : eLedState.Off;
        }
Example #38
0
        private void Gpio_Init()
        {
            var gpio = GpioController.GetDefault();

            // Show an error if there is no GPIO controller
            if (gpio == null)
            {
                pin = null;
                return;
            }
            pin      = gpio.OpenPin(gpioPin);
            pinValue = GpioPinValue.High;
            pin.Write(pinValue);
            pin.SetDriveMode(GpioPinDriveMode.Output);
        }
 private void KITCHENTimer_Tick(object sender, object e)
 {
     if (kITCHENLED_GpioPinValue == GpioPinValue.High)
     {
         kITCHENLED_GpioPinValue = GpioPinValue.Low;
         kITCHENLED_GpioPin.Write(kITCHENLED_GpioPinValue);
         //LED.Fill = redBrush;
     }
     else
     {
         kITCHENLED_GpioPinValue = GpioPinValue.High;
         kITCHENLED_GpioPin.Write(kITCHENLED_GpioPinValue);
         //LED.Fill = grayBrush;
     }
 }
Example #40
0
 private void Timer_Tick_two(object sender, object e)
 {
     if (pinValue == GpioPinValue.High)
     {
         pinValue = GpioPinValue.Low;
         pin_two.Write(pinValue);
         LED2.Fill = redBrush;
     }
     else
     {
         pinValue = GpioPinValue.High;
         pin_two.Write(pinValue);
         LED2.Fill = grayBrush;
     }
 }
        private void InitGPIO()
        {
            var gpio = GpioController.GetDefault();

            if (gpio == null)
            {
                pin = null;
                throw new Exception("Init FAILED.");
            }

            pin      = gpio.OpenPin(FAN_PIN);
            pinValue = GpioPinValue.Low;
            pin.Write(pinValue);
            pin.SetDriveMode(GpioPinDriveMode.Output);
        }
Example #42
0
 public void Timer_Tick(object sender, object e)
 {
     if (pinValue == GpioPinValue.High)
     {
         pinValue = GpioPinValue.Low;
         pin.Write(pinValue);
         Page.LED.Fill = greenBrush;
     }
     else
     {
         pinValue = GpioPinValue.High;
         pin.Write(pinValue);
         Page.LED.Fill = grayBrush;
     }
 }
Example #43
0
        /// <summary>
        /// Initialize pins and relay for work
        /// </summary>
        public void InitializeRelay()
        {
            var gpio = GpioController.GetDefault();

            if (gpio == null)
            {
                _pin = null;
                return;
            }

            _pin      = gpio.OpenPin(RelayPin);
            _pinValue = GpioPinValue.High;
            _pin.Write(_pinValue);
            _pin.SetDriveMode(GpioPinDriveMode.Output);
        }
Example #44
0
        private void InitGPIO()
        {
            var gpio = GpioController.GetDefault();

            if (gpio == null)
            {
                pin = null;
                return;
            }

            pin      = gpio.OpenPin(LED_PIN);
            pinValue = GpioPinValue.Low;
            pin.Write(pinValue);
            pin.SetDriveMode(GpioPinDriveMode.Output);
        }
Example #45
0
 private void Timer_Tick(object sender, object e)
 {
     if (pinValue == GpioPinValue.High)
     {
         pinValue = GpioPinValue.Low;
         pin.Write(pinValue);
         //timer.Interval = TimeSpan.FromMilliseconds(2000);
     }
     else
     {
         pinValue = GpioPinValue.High;
         pin.Write(pinValue);
         //timer.Interval = TimeSpan.FromMilliseconds(100);
     }
 }
        private async void buttonPin_ValueChangedAsync(GpioPin sender, GpioPinValueChangedEventArgs e)
        {
            MyAzureClass myAzureClass = new MyAzureClass();

            // toggle the state of the LED every time the button is pressed
            if (e.Edge == GpioPinEdge.FallingEdge)
            {
                ledPinValue = (ledPinValue == GpioPinValue.Low) ?
                              GpioPinValue.High : GpioPinValue.Low;
                ledPin.Write(ledPinValue);
                MainDevice.Status = Convert.ToBoolean(ledPinValue);
                myAzureClass.UpdateRecordInTable(MainDevice);
                AzureIoTHub.SendDeviceToCloudMessageAsync();
            }
        }
Example #47
0
        private UInt32 ExpectPulse(GpioPinValue level)
        {
            UInt32 count = 0;

            while (_dataPin.Read() == (level == GpioPinValue.High))
            {
                count++;
                //WaitMicroseconds(1);
                if (count == 10000)
                {
                    return(0);
                }
            }
            return(count);
        }
Example #48
0
 /// <summary>
 /// Change the red LED value every 1/2 second
 /// </summary>
 private void Timer_Tick(object sender, object e)
 {
     if (pinValue == GpioPinValue.High)
     {
         pinValue = GpioPinValue.Low;
         pin.Write(pinValue);
         LED.Fill = redBrush;  //UI
     }
     else
     {
         pinValue = GpioPinValue.High;
         pin.Write(pinValue);
         LED.Fill = grayBrush;  //UI
     }
 }
Example #49
0
        public Sprinkler(int SprNum, bool isinverted = false)
        {
            IsInverted      = isinverted;
            MyTimerCallBack = new Timer(MyTimerCallBack_Tick, this, Timeout.Infinite, Timeout.Infinite);
            //MyTimerCallBack.Tick += MyTimerCallBack_Tick;

            MySprinklerNumber = SprNum;
            MyTicksWait       = DateTime.Now.Ticks;
            var gpio = GpioController.GetDefault();

            switch (SprNum)
            {
            case 0:
                MySprOpen = gpio.OpenPin(GPIO_PIN_D0);
                pinValue  = IsInverted ? GpioPinValue.High : GpioPinValue.Low;
                MySprOpen.Write(pinValue);
                MySprOpen.SetDriveMode(GpioPinDriveMode.Output);
                break;

            case 1:
                MySprOpen = gpio.OpenPin(GPIO_PIN_D1);
                pinValue  = IsInverted ? GpioPinValue.High : GpioPinValue.Low;
                MySprOpen.Write(pinValue);
                MySprOpen.SetDriveMode(GpioPinDriveMode.Output);
                break;

            case 2:
                MySprOpen = gpio.OpenPin(GPIO_PIN_D2);
                pinValue  = IsInverted ? GpioPinValue.High : GpioPinValue.Low;
                MySprOpen.Write(pinValue);
                MySprOpen.SetDriveMode(GpioPinDriveMode.Output);
                break;

            case 3:
                MySprOpen = gpio.OpenPin(GPIO_PIN_D3);
                pinValue  = IsInverted ? GpioPinValue.High : GpioPinValue.Low;
                MySprOpen.Write(pinValue);
                MySprOpen.SetDriveMode(GpioPinDriveMode.Output);
                break;

            case 4:
                MySprOpen = gpio.OpenPin(GPIO_PIN_D4);
                pinValue  = IsInverted ? GpioPinValue.High : GpioPinValue.Low;
                MySprOpen.Write(pinValue);
                MySprOpen.SetDriveMode(GpioPinDriveMode.Output);
                break;
            }
        }
        private bool InitPins()
        {
            //SpiConnectionSettings(0)

            MyPins[] pins = (MyPins[])Enum.GetValues(typeof(MyPins));
            var      gpio = GpioController.GetDefault();

            mapZoneToPinNo.Add(1, MyPins.Led6);
            mapZoneToPinNo.Add(2, MyPins.Led5);
            mapZoneToPinNo.Add(3, MyPins.Led25);
            mapZoneToPinNo.Add(4, MyPins.Led24);
            mapZoneToPinNo.Add(5, MyPins.Led23);
            mapZoneToPinNo.Add(6, MyPins.Led22);
            mapZoneToPinNo.Add(7, MyPins.Led18);
            mapZoneToPinNo.Add(8, MyPins.Led17);
            mapZoneToPinNo.Add(9, MyPins.Led12);
            mapZoneToPinNo.Add(10, MyPins.Led13);
            mapZoneToPinNo.Add(11, MyPins.Led19);
            mapZoneToPinNo.Add(12, MyPins.Led26);
            mapZoneToPinNo.Add(13, MyPins.Led16);
            mapZoneToPinNo.Add(14, MyPins.Led20);
            mapZoneToPinNo.Add(15, MyPins.Led21);


            foreach (int zone in mapZoneToPinNo.Keys)
            {
                MyPins id = mapZoneToPinNo[zone];
                try
                {
                    GpioPin pin = gpio.OpenPin((int)id);

                    GpioPinValue pinValue = GpioPinValue.High;
                    pin.Write(pinValue);
                    pin.SetDriveMode(GpioPinDriveMode.Output);

                    mapZoneToPin.Add(zone, pin);

                    zoneOffOnList[zone - 1] = false;
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Unable to open pin: " + id);
                    System.Diagnostics.Debug.WriteLine(ex.StackTrace);
                }
            }

            return(true);
        }
Example #51
0
        private GpioPin InitPin(int number,
                                GpioPinDriveMode mode     = GpioPinDriveMode.Output,
                                GpioPinValue initialValue = GpioPinValue.Low)
        {
            var gpio = GpioController.GetDefault();
            var pin  = gpio.OpenPin(number);

            pin.SetDriveMode(mode);

            if (mode == GpioPinDriveMode.Output)
            {
                pin.Write(initialValue);
            }

            return(pin);
        }
Example #52
0
        public void Write(PinValue value)
        {
            GpioPinValue newValue = GpioPinValue.High;

            switch (value)
            {
            case PinValue.High:
                newValue = GpioPinValue.High;
                break;

            case PinValue.Low:
                newValue = GpioPinValue.Low;
                break;
            }
            _pin.Write(newValue);
        }
 private void BlinkTimer_Tick(object sender, object e)
 {
     // If pin is on, turn it off
     if (this.pinValue == GpioPinValue.High)
     {
         this.led_indicator.Fill = grayBrush;
         this.pinValue           = GpioPinValue.Low;
     }
     // else turn it on
     else
     {
         this.led_indicator.Fill = greenBrush;
         this.pinValue           = GpioPinValue.High;
     }
     this.pin.Write(this.pinValue);
 }
        /// <summary>
        /// Updates the LEDs according to the bridge status.
        /// </summary>
        private void UpdateLEDs()
        {
            GpioPinValue on  = GpioPinValue.Low;
            GpioPinValue off = GpioPinValue.High;

            if (isOpen)
            {
                greenPin.Write(on); // Green ON
                redPin.Write(off);  // Red OFF
            }
            else
            {
                redPin.Write(on);    // Green ON
                greenPin.Write(off); // Red OFF
            }
        }
Example #55
0
        private void GPIOInit()
        {
            GpioController gpio = GpioController.GetDefault();

            if (gpio == null)
            {
                //kill program if no gpio controller
                p = null;
                return;
            }

            p    = gpio.OpenPin(LED_PIN);
            pVal = GpioPinValue.High;
            p.Write(pVal);
            p.SetDriveMode(GpioPinDriveMode.Output);
        }
Example #56
0
        private void InitialiseGpio()
        {
            var controller = GpioController.GetDefault();

            if (controller != null)
            {
                _pin = controller.OpenPin(LED);
                _pin.SetDriveMode(GpioPinDriveMode.Output);
                _pin.Write(GpioPinValue.Low);
                _pinvalue = GpioPinValue.Low;
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("Target Device Does Not Have Gpio pins");
            }
        }
Example #57
0
        private void in_Click(object sender, RoutedEventArgs e)
        {
            Button button   = sender as Button;
            var    pinEntry = button.DataContext as GpioPinEntry;

            if (pinEntry.pin != null)
            {
                pinEntry.pin.SetDriveMode(GpioPinDriveMode.Input);
                GpioPinValue value = pinEntry.pin.Read();
                pinEntry.value = value;
            }
            else
            {
                status.Log(string.Format(LocalizableStrings.IOT_GPIO_PIN_NOTOPEN, pinEntry.num));
            }
        }
 private void Timer_Tick(ThreadPoolTimer timer)
 {
     if (_cancelRequested == false)
     {
         value = (value == GpioPinValue.High) ? GpioPinValue.Low : GpioPinValue.High;
         pin.Write(value);
     }
     else
     {
         timer.Cancel();
         //
         // Indicate that the background task has completed.
         //
         deferral.Complete();
     }
 }
Example #59
0
                public void Write(GpioPinValue value)
                {
                    switch (value)
                    {
                    case GpioPinValue.High:
                        _pin.Write(1);
                        break;

                    case GpioPinValue.Low:
                        _pin.Write(0);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(value), value, null);
                    }
                }
Example #60
0
 private void Timer_Tick(object sender, object e)
 {
     if (pinValue == GpioPinValue.High)
     {
         pinValue = GpioPinValue.Low;
         pin.Write(pinValue);
         //Update brush colour depending on LED
         LED.Fill = blueBrush;
     }
     else
     {
         pinValue = GpioPinValue.High;
         pin.Write(pinValue);
         LED.Fill = whiteBrush;
     }
 }