Exemplo n.º 1
0
        public void Initialize(int PinIn1, int PinIn2, int PinPWM)
        {
            if (gpioController == null)
            {
                return;
            }
            if (pwmController == null)
            {
                return;
            }

            gpioPinIn1 = gpioController.OpenPin(PinIn1);
            gpioPinIn1.SetDriveMode(GpioPinDriveMode.Output);
            gpioPinIn1.Write(GpioPinValue.Low);

            gpioPinIn2 = gpioController.OpenPin(PinIn2);
            gpioPinIn2.SetDriveMode(GpioPinDriveMode.Output);
            gpioPinIn2.Write(GpioPinValue.Low);

            // Open pin 5 for pulse width modulation
            servoGpioPinEn = pwmController.OpenPin(PinPWM);
        }
Exemplo n.º 2
0
            static Motors()
            {
                PWM.SetDesiredFrequency(6000);

                M1PWM = PWM.OpenChannel(FEZ.PwmChannel.Controller3.D9);
                M1PWM.Stop();
                M1PWM.SetActiveDutyCyclePercentage(0.1);
                M1PWM.Start();

                M2PWM = PWM.OpenChannel(FEZ.PwmChannel.Controller3.D10);
                M2PWM.Stop();
                M2PWM.SetActiveDutyCyclePercentage(0.1);
                M2PWM.Start();

                M1DIR = GpioController.GetDefault().OpenPin(FEZ.GpioPin.D7);
                M1DIR.SetDriveMode(GpioPinDriveMode.Output);
                M1DIR.Write(GpioPinValue.High);

                M2DIR = GpioController.GetDefault().OpenPin(FEZ.GpioPin.D8);
                M2DIR.Write(GpioPinValue.High);
                M2DIR.SetDriveMode(GpioPinDriveMode.Output);
            }
Exemplo n.º 3
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            GpioController gpc       = GpioController.GetDefault();
            GpioPin        ledOccupe = gpc?.OpenPin(24);

            _appareilPhoto = new AppareilPhoto(ledOccupe);
            if (await _appareilPhoto.Initialiser(1280, 960, "MJPG"))
            {
                PrendrePhotoBTN.Visibility = Visibility.Visible;
                if (gpc != null)
                {
                    _poussoirDecl = gpc.OpenPin(18);
                    _poussoirDecl.SetDriveMode(GpioPinDriveMode.InputPullUp);
                    _poussoirDecl.DebounceTimeout = new TimeSpan(0, 0, 0, 0, 5);
                    _poussoirDecl.ValueChanged   += _poussoirDecl_ValueChanged;

                    _ledEnMarche = gpc.OpenPin(23);
                    _ledEnMarche.SetDriveMode(GpioPinDriveMode.Output);
                    _ledEnMarche.Write(GpioPinValue.High);
                }
            }
        }
Exemplo n.º 4
0
        private static void OnPinValueChanged2(object sender, PinValueChangedEventArgs e)
        {
            s_currentLedValue = s_currentLedValue == PinValue.High ? PinValue.Low : PinValue.High;
            Console.WriteLine($"Button pressed! Led value {s_currentLedValue}");

            if (sender is GpioDriver)
            {
                GpioDriver driver = sender as GpioDriver;
                driver.Output(s_ledPinNumber, s_currentLedValue);
            }
            else if (sender is GpioPin)
            {
                GpioPin        button     = sender as GpioPin;
                GpioController controller = button.Controller;
                GpioPin        led        = controller[s_ledPinNumber];
                led.Write(s_currentLedValue);
            }
            else
            {
                throw new ArgumentException(nameof(sender));
            }
        }
Exemplo n.º 5
0
        public DisplayTftSpiBase(string SpiControllerName, int chipSelectPin, int dcPin, int resetPin,
                                 uint width, uint height)
        {
            this.width  = width;
            this.height = height;
            var gpio = GpioController.GetDefault();

            chipSelectPort = gpio.OpenPin(chipSelectPin);
            chipSelectPort.SetDriveMode(GpioPinDriveMode.Output);
            chipSelectPort.Write(GpioPinValue.Low);
            var settings = new SpiConnectionSettings()
            {
                ChipSelectType = SpiChipSelectType.Gpio,
                ChipSelectLine = chipSelectPort,
                Mode           = SpiMode.Mode1,
                ClockFrequency = 4_000_000,
            };

            var controller = SpiController.FromName(SpiControllerName);

            spi = controller.GetDevice(settings);


            spiBuffer  = new byte[this.width * this.height * sizeof(ushort)];
            spiReceive = new byte[this.width * this.height * sizeof(ushort)];


            dataCommandPort = gpio.OpenPin(dcPin);
            dataCommandPort.SetDriveMode(GpioPinDriveMode.Output);
            dataCommandPort.Write(GpioPinValue.Low);

            resetPort = gpio.OpenPin(resetPin);
            resetPort.SetDriveMode(GpioPinDriveMode.Output);
            resetPort.Write(GpioPinValue.High);

            chipSelectPort = gpio.OpenPin(chipSelectPin);
            chipSelectPort.SetDriveMode(GpioPinDriveMode.Output);
            chipSelectPort.Write(GpioPinValue.Low);
        }
        private void ButtonPressed(GpioPin sender, GpioPinValueChangedEventArgs args)
        {
            if (args.Edge != GpioPinEdge.FallingEdge)
            {
                return;
            }

            _isDead = !_isDead;

            if (_isDead)
            {
                LightBulb(TrafficLightState.Broken);
                _signalRConnection.Stop();
                _signalRHub.Dispose();
                NotifyState(TrafficLightState.Broken).Wait();
            }
            else
            {
                NotifyState(TrafficLightState.Green).Wait();
                StartSignalR().Wait();
            }
        }
Exemplo n.º 7
0
        public Ssr(ComponentId id, IBeerFactoryEventHandler eventHandler, ILoggerFactory loggerFactory)
        {
            Logger        = loggerFactory.CreateLogger <Ssr>();
            _eventHandler = eventHandler;
            CurrentState  = new SsrState {
                Id = id
            };

            Enum.TryParse(id.ToString(), out SsrPin ssrPin);
            _pinNumber = (int)ssrPin;

            var gpio = GpioController.GetDefault();

            if (gpio != null)
            {
                _pin = gpio.OpenPin(_pinNumber);
                _pin.SetDriveMode(GpioPinDriveMode.Output);
                _pin.Write(GpioPinValue.Low);
            }

            _eventHandler.SubscribeToComponentStateRequest <SsrRequestState>(SsrStateRequestOccured);
        }
Exemplo n.º 8
0
        private void OnFrontIRChange(GpioPin sender, GpioPinValueChangedEventArgs args)
        {
            switch (args.Edge)
            {
            case GpioPinEdge.FallingEdge:    //low value
                FrontTotalCountInt--;
                FrontDownCountInt++;
                break;

            case GpioPinEdge.RisingEdge:    //high value
                FrontTotalCountInt++;
                FrontUpCountInt++;
                break;
            }
            var task = Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
            {
                FrontEdge.Text       = args.Edge.ToString();
                FrontDownCount.Text  = "Down: " + FrontDownCountInt.ToString();
                FrontUpCount.Text    = "Up: " + FrontUpCountInt.ToString();
                FrontTotalCount.Text = "Total: " + FrontTotalCountInt.ToString();
            });
        }
Exemplo n.º 9
0
        private void TriggerPin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
        {
            switch (args.Edge)
            {
            case GpioPinEdge.FallingEdge:    //low value
                SideTotalCount--;
                SideDownCountInt++;
                break;

            case GpioPinEdge.RisingEdge:    //high value
                SideTotalCount++;
                SideUpCountInt++;
                break;
            }
            var task = Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
            {
                SideEdge.Text      = args.Edge.ToString();
                SideDownCount.Text = "Down: " + SideDownCountInt.ToString();
                SideUpCout.Text    = "Up: " + SideUpCountInt.ToString();
                SideTotalCout.Text = "Total: " + SideTotalCount.ToString();
            });
        }
Exemplo n.º 10
0
 private void grip_step_pin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs e)
 {
     try
     {
         if (grip_step_pin.Read() == GpioPinValue.High)
         {
             if (grip_close_pin.Read() == GpioPinValue.High)
             {
                 grip_act++;
             }
             else if (grip_open_pin.Read() == GpioPinValue.Low)
             {
                 grip_act--;
             }
         }
     }
     catch
     {
         StopAll();
         throw;
     }
 }
Exemplo n.º 11
0
        public static void Main()
        {
            Debug.WriteLine("Welcome to WiFI Soft AP world!");

            GpioPin setupButton = GpioController.GetDefault().OpenPin(SETUP_PIN);

            setupButton.SetDriveMode(GpioPinDriveMode.InputPullUp);

            // If Wireless station is not enabled then start Soft AP to allow Wireless configuration
            // or Button pressed
            if (!Wireless80211.IsEnabled() || (setupButton.Read() == GpioPinValue.Low))
            {
                Wireless80211.Disable();

                if (WirelessAP.Setup() == false)
                {
                    // Reboot device to Activate Access Point on restart
                    Debug.WriteLine($"Setup Soft AP, Rebooting device");
                    Power.RebootDevice();
                }

                Debug.WriteLine($"Running Soft AP, waiting for client to connect");
                Debug.WriteLine($"Soft AP IP address :{WirelessAP.GetIP()}");

                // Link up Network event to show Stations connecting/disconnecting to Access point.
                NetworkChange.NetworkAPStationChanged += NetworkChange_NetworkAPStationChanged;;
            }
            else
            {
                Debug.WriteLine($"Running in normal mode, connecting to Access point");
                string IpAdr = Wireless80211.WaitIP();
                Debug.WriteLine($"Connected as {IpAdr}");
            }


            // Just wait for now
            // Here you would have the reset of your program using the client WiFI link
            Thread.Sleep(Timeout.Infinite);
        }
Exemplo n.º 12
0
        public RegisterManager RegisterManager = null;         // Future refactor this will be made private

        public Rfm9XDevice(byte chipSelectPin, byte resetPin, byte interruptPin)
        {
            RegisterManager = new RegisterManager(chipSelectPin);

            // Setup the reset and interrupt pins
            GpioController gpioController = GpioController.GetDefault();

            // Reset pin configuration then strobe briefly to factory reset
            GpioPin resetGpioPin = gpioController.OpenPin(resetPin);

            resetGpioPin.SetDriveMode(GpioPinDriveMode.Output);
            resetGpioPin.Write(GpioPinValue.Low);
            Task.Delay(10);
            resetGpioPin.Write(GpioPinValue.High);
            Task.Delay(10);

            // Interrupt pin for RX message, TX done etc. notifications
            InterruptGpioPin = gpioController.OpenPin(interruptPin);
            InterruptGpioPin.SetDriveMode(GpioPinDriveMode.Input);

            InterruptGpioPin.ValueChanged += InterruptGpioPin_ValueChanged;
        }
Exemplo n.º 13
0
        public RGBLed(int redPinNumber, int greenPinNumber, int bluePinNumber)
        {
            var gpio = GpioController.GetDefault();

            _redPin = gpio.OpenPin(redPinNumber);
            _redPin.SetDriveMode(GpioPinDriveMode.Output);

            _greenPin = gpio.OpenPin(greenPinNumber);
            _greenPin.SetDriveMode(GpioPinDriveMode.Output);

            _bluePin = gpio.OpenPin(bluePinNumber);
            _bluePin.SetDriveMode(GpioPinDriveMode.Output);

            _redPinValue = GpioPinValue.Low;
            _redPin.Write(_redPinValue);

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

            _bluePinValue = GpioPinValue.Low;
            _bluePin.Write(_bluePinValue);
        }
Exemplo n.º 14
0
        private void OnInterrupt(GpioPin sender, GpioPinValueChangedEventArgs e)
        {
            if (e.Edge != GpioPinEdge.RisingEdge)
            {
                return;
            }

            var ports = this.ReadRegisters(Register.InterruptPort0, 8);

            for (byte i = 0; i < 8; i++)
            {
                for (byte j = 0; j < 8; j++)
                {
                    var pin = new Pin(i, j);

                    if (this.interruptRegistrations.ContainsKey(pin) && (ports[i] & (1 << j)) != 0)
                    {
                        this.interruptRegistrations[pin](this.ReadDigital(pin));
                    }
                }
            }
        }
Exemplo n.º 15
0
        private async Task InitGPIO()
        {
            // Get the GPIO controller
            try
            {
                gpioController = await GpioController.GetDefaultAsync();
            }
            catch (Exception ex)
            {
                throw new Exception("GPIO Initialization failed.", ex);
            }

            // Setup the GPIO pins for the display
            pinReset     = CreateWritePin(RESET_PIN);
            pinPanel     = CreateWritePin(PANEL_PIN);
            pinDischarge = CreateWritePin(DISCHARGE_PIN);
            pinBorder    = CreateWritePin(BORDER_PIN);

            // Setup the Busy pin as a read
            pinBusy = gpioController.OpenPin(BUSY_PIN, GpioSharingMode.Exclusive);
            pinBusy.SetDriveMode(GpioPinDriveMode.Input);
        }
Exemplo n.º 16
0
        private async void buttonPin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs e)
        {
            if (e.Edge == GpioPinEdge.FallingEdge)
            {
                // need to invoke UI updates on the UI thread because this event
                // handler gets invoked on a separate thread.
                var task = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    // toggle the state of the LED every time the button is pressed
                    BeltConnected = true;
                });

                try
                {
                    SetSeatBeltStatusAsync(SeatBeltId, true);
                }
                catch (Exception)
                {
                    // nothing to do
                }
            }

            if (e.Edge == GpioPinEdge.RisingEdge)
            {
                var task = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    BeltConnected = false;
                });

                try
                {
                    SetSeatBeltStatusAsync(SeatBeltId, false);
                }
                catch (Exception)
                {
                    // nothing to do
                }
            }
        }
Exemplo n.º 17
0
        private void InitGPIO()
        {
            var gpio = GpioController.GetDefault();

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

            redPin      = gpio.OpenPin(RED_LED_PIN);
            redPinValue = GpioPinValue.High;
            redPin.Write(redPinValue);
            redPin.SetDriveMode(GpioPinDriveMode.Output);

            greenPin      = gpio.OpenPin(GREEN_LED_PIN);
            greenPinValue = GpioPinValue.High;
            greenPin.Write(greenPinValue);
            greenPin.SetDriveMode(GpioPinDriveMode.Output);
        }
Exemplo n.º 18
0
        private void DoorSensor_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
        {
            var client = new PiServer.ServiceSoapClient();

            if (sender.Read() == GpioPinValue.High)
            {
                client.UpdateStatusAsync("GarageDoor", "Open");
                Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    el_GarageDoor.Fill = grayBrush;
                });
            }
            else
            {
                client.UpdateStatusAsync("GarageDoor", "Closed");
                Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                                                      () =>
                {
                    el_GarageDoor.Fill = redBrush;
                });
            }
        }
Exemplo n.º 19
0
        void StopScenario()
        {
            // Stop the timer.
            if (timer != null)
            {
                timer.Stop();
                timer = null;
            }

            // Release the GPIO pins.
            if (setPin != null)
            {
                setPin.Dispose();
                setPin = null;
            }
            if (listenPin != null)
            {
                listenPin.ValueChanged -= Pin_ValueChanged;
                listenPin.Dispose();
                listenPin = null;
            }
        }
Exemplo n.º 20
0
        public PancakeDrive()
        {
            // Initialize GPIO Controller
            var gpio = GpioController.GetDefault();

            // Set X motor pins
            stepperXPulse = GpioController.GetDefault().OpenPin(23);
            stepperXPulse.SetDriveMode(GpioPinDriveMode.Output);
            stepperXPulse.Write(GpioPinValue.Low);

            stepperXDir = gpio.OpenPin(24);
            stepperXDir.SetDriveMode(GpioPinDriveMode.Output);
            stepperXDir.Write(GpioPinValue.Low);

            stepperXEn = GpioController.GetDefault().OpenPin(18);
            stepperXEn.SetDriveMode(GpioPinDriveMode.Output);
            stepperXEn.Write(GpioPinValue.Low);

            // Set Y motor pins
            stepperYPulse = GpioController.GetDefault().OpenPin(12);
            stepperYPulse.SetDriveMode(GpioPinDriveMode.Output);
            stepperYPulse.Write(GpioPinValue.Low);

            stepperYDir = gpio.OpenPin(16);
            stepperYDir.SetDriveMode(GpioPinDriveMode.Output);
            stepperYDir.Write(GpioPinValue.Low);

            stepperYEn = GpioController.GetDefault().OpenPin(1);
            stepperYEn.SetDriveMode(GpioPinDriveMode.Output);
            stepperYEn.Write(GpioPinValue.Low);

            // Set stepper motor pin
            servoPulse = GpioController.GetDefault().OpenPin(27);
            servoPulse.SetDriveMode(GpioPinDriveMode.Output);
            servoPulse.Write(GpioPinValue.Low);

            // Initialize X-Y pulse timer
            tmrPulse = new Timer(new TimerCallback(PulseTimerTick), null, 1000, 10);
        }
Exemplo n.º 21
0
        public MainPage()
        {
            InitializeComponent();

            var gpio = GpioController.GetDefault();

            pin0 = gpio.OpenPin(LED_RED);
            pin1 = gpio.OpenPin(LED_GREEN);
            pin2 = gpio.OpenPin(LED_YELLOW);
            pin3 = gpio.OpenPin(LED_BLUE);
            pin4 = gpio.OpenPin(LED_WHITE);

            pin0.SetDriveMode(GpioPinDriveMode.Output);
            pin1.SetDriveMode(GpioPinDriveMode.Output);
            pin2.SetDriveMode(GpioPinDriveMode.Output);
            pin3.SetDriveMode(GpioPinDriveMode.Output);
            pin4.SetDriveMode(GpioPinDriveMode.Output);

            pinValue  = GpioPinValue.Low;
            pinValue1 = GpioPinValue.High;
            while (true)
            {
                pin0.Write(pinValue);
                Task.Delay(100).Wait();
                pin0.Write(pinValue1);
                pin1.Write(pinValue);
                Task.Delay(100).Wait();
                pin1.Write(pinValue1);
                pin2.Write(pinValue);
                Task.Delay(100).Wait();
                pin2.Write(pinValue1);
                pin3.Write(pinValue);
                Task.Delay(100).Wait();
                pin3.Write(pinValue1);
                pin4.Write(pinValue);
                Task.Delay(100).Wait();
                pin4.Write(pinValue1);
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// initialize GPIO
        /// </summary>
        /// <returns></returns>
        private async Task <bool> InitGpio()
        {
            GpioController IoController = await GpioController.GetDefaultAsync();

            if (IoController == null)
            {
                Debug.WriteLine("GPIO does not exist on the current system");
                return(false);
            }


            _pinDataCmd = IoController.OpenPin(SPI_DATA_COMMAND_PIN);
            _pinDataCmd.Write(GpioPinValue.High);
            _pinDataCmd.SetDriveMode(GpioPinDriveMode.Output);

            /* Initialize a pin as output for the hardware Reset line on the display */
            _pinReset = IoController.OpenPin(SPI_RESET_PIN);
            _pinReset.Write(GpioPinValue.High);
            _pinReset.SetDriveMode(GpioPinDriveMode.Output);
            Debug.WriteLine("GPIO initialized");
            return(true);
        }
Exemplo n.º 23
0
        //Method to initialize the TCS34725 sensor
        public async Task Initialize()
        {
            Debug.WriteLine("TCS34725::Initialize");

            try
            {
                //Instantiate the I2CConnectionSettings using the device address of the TCS34725
                I2cConnectionSettings settings = new I2cConnectionSettings(TCS34725_Address);

                //Set the I2C bus speed of connection to fast mode
                settings.BusSpeed = I2cBusSpeed.FastMode;

                //Use the I2CBus device selector to create an advanced query syntax string
                string aqs = I2cDevice.GetDeviceSelector(I2CControllerName);

                //Use the Windows.Devices.Enumeration.DeviceInformation class to create a
                //collection using the advanced query syntax string
                DeviceInformationCollection dis = await DeviceInformation.FindAllAsync(aqs);

                //Instantiate the the TCS34725 I2C device using the device id of the I2CBus
                //and the I2CConnectionSettings
                colorSensor = await I2cDevice.FromIdAsync(dis[0].Id, settings);

                //Create a default GPIO controller
                gpio = GpioController.GetDefault();
                //Open the LED control pin using the GPIO controller
                LedControlGPIOPin = gpio.OpenPin(LedControlPin);
                //Set the pin to output
                LedControlGPIOPin.SetDriveMode(GpioPinDriveMode.Output);

                //Initialize the known color list
                initColorList();
            }
            catch (Exception e)
            {
                Debug.WriteLine("Exception: " + e.Message + "\n" + e.StackTrace);
                throw;
            }
        }
Exemplo n.º 24
0
        SparkfunArdumoto(int PinD2, int PinD4, int PinD3, int PinD11, string PWM1Id, string PWM3Id)
        {
            var GPIO = GpioController.GetDefault();

            MotorA.SetDriveMode(GpioPinDriveMode.Output);
            MotorB.SetDriveMode(GpioPinDriveMode.Output);
            MotorA = GPIO.OpenPin(PinD2);
            MotorB = GPIO.OpenPin(PinD4);

            var PWM1 = PwmController.FromId(PWM1Id);
            var PWM3 = PwmController.FromId(PWM3Id);

            SpeedA = PWM1.OpenPin(PinD3);
            SpeedB = PWM3.OpenPin(PinD11);
            PWM1.SetDesiredFrequency(5000);
            PWM3.SetDesiredFrequency(5000);

            SpeedA.Start();
            SpeedB.Start();
            ChangeSpeed(0.0, 0.0);
            ChangeDirection(MoveDirection.Forward);
        }
Exemplo n.º 25
0
        static void Main(string[] args)
        {
            foreach (GpioPin pin in Pi.Gpio.OrderBy(x => x.BcmPinNumber))
            {
                Console.WriteLine(pin.Name);
                Console.WriteLine(pin.BcmPinNumber);
                Console.WriteLine(pin.PinMode);
                Console.WriteLine(pin.ReadValue());
            }

            GpioPin gpioPin = Pi.Gpio.GetGpioPinByBcmPinNumber(2);

            gpioPin.PinMode = GpioPinDriveMode.Output;

            while (true)
            {
                gpioPin.Write(GpioPinValue.Low);
                Thread.Sleep(500);
                gpioPin.Write(GpioPinValue.High);
                Thread.Sleep(500);
            }
        }
Exemplo n.º 26
0
        private GpioPin InitializeInputGPIO(GpioPin gpioPin, int PinID)
        {
            gpioPin = gpioController.OpenPin(PinID);
            if (gpioPin == null)
            {
                return(null);
            }

            gpioPin.DebounceTimeout = TimeSpan.FromMilliseconds(25);

            if (gpioPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
            {
                // Take advantage of built in pull-up resistors of Raspberry Pi 2 and DragonBoard 410c
                //利用树莓派内置的上拉电阻
                gpioPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            }
            else
            {
                gpioPin.SetDriveMode(GpioPinDriveMode.Input);
            }
            return(gpioPin);
        }
Exemplo n.º 27
0
        private async void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            // initialize the ping pong controller and choose GPIO 23 and GPIO 24
            // as the switches for the players
            gpio = await GpioController.GetDefaultAsync();

            btn1 = gpio.OpenPin(22);
            btn2 = gpio.OpenPin(18);

            // add event handlers so we can listen for button presses
            btn1.ValueChanged += Btn1_ValueChanged;
            btn2.ValueChanged += Btn2_ValueChanged;

            // setup the pins for the leds
            ledPins = new int[] { 2, 3, 4, 17, 27, 23 }.Select(a => gpio.OpenPin(a)).ToArray();
            // add ellipses to the gui and save them so we can show them on screen
            ellipses = ledPins.Select(a =>
            {
                var ellipse = new Ellipse()
                {
                    Margin = new Thickness(10),
                    Width  = 20,
                    Height = 20,
                    Fill   = new SolidColorBrush(Colors.Red)
                };
                ledPanel.Children.Add(ellipse);
                return(ellipse);
            }).ToArray();

            // set the led pins as outputs
            foreach (var p in ledPins)
            {
                p.SetDriveMode(GpioPinDriveMode.Output);
                p.Write(GpioPinValue.Low);
            }

            // start the ping pong loop
            PingPongLoop();
        }
Exemplo n.º 28
0
        public Rfm9XDevice(int busId, int chipSelectPin, int resetPin)
        {
            var settings = new SpiConnectionSettings(busId, chipSelectPin)
            {
                ClockFrequency = 500000,
                //DataBitLength = 8,
                Mode        = SpiMode.Mode0,// From SemTech docs pg 80 CPOL=0, CPHA=0
                SharingMode = SpiSharingMode.Shared,
            };

            rfm9XLoraModem = new SpiDevice(settings);

            // Factory reset pin configuration
            GpioController gpioController = new GpioController();
            GpioPin        resetGpioPin   = gpioController.OpenPin(resetPin);

            resetGpioPin.SetPinMode(PinMode.Output);
            resetGpioPin.Write(PinValue.Low);
            Thread.Sleep(10);
            resetGpioPin.Write(PinValue.High);
            Thread.Sleep(10);
        }
Exemplo n.º 29
0
        public void InitGPIO()
        {
            var gpio = GpioController.GetDefault();

            stepPin = gpio.OpenPin(STEP_PIN);
            stepPin.SetDriveMode(GpioPinDriveMode.Output);
            stepPinValue = GpioPinValue.Low;
            stepPin.Write(stepPinValue);

            directionPin = gpio.OpenPin(DIR_PIN);
            directionPin.SetDriveMode(GpioPinDriveMode.Output);
            directionPinValue = GpioPinValue.Low;
            directionPin.Write(directionPinValue);

            if (ENABLE_PIN != 0)
            {
                enablePin = gpio.OpenPin(ENABLE_PIN);
                enablePin.SetDriveMode(GpioPinDriveMode.Output);
                enablePinValue = GpioPinValue.High;
                enablePin.Write(enablePinValue);
            }
        }
Exemplo n.º 30
0
        private void InitGPIO()
        {
            // init LEDs
            ledPins = new List <GpioPin>()
            {
                GpioController.GetDefault().OpenPin(PIN_RED),
                GpioController.GetDefault().OpenPin(PIN_BLUE),
                GpioController.GetDefault().OpenPin(PIN_GREEN)
            };

            foreach (var pin in ledPins)
            {
                // designate pins for Output
                pin.SetDriveMode(GpioPinDriveMode.Output);

                // Turn LED off, initially
                pin.Write(GpioPinValue.Low);
            }

            // init Photo cell
            photoPin = GpioController.GetDefault().OpenPin(PIN_PHOTO);
        }