Exemplo n.º 1
0
        public MainPage()
        {
            this.InitializeComponent();

            // Инициализируем пины вывода
            var gpio = GpioController.GetDefault();

            led_pin = gpio?.OpenPin(17);
            led_pin?.SetDriveMode(GpioPinDriveMode.Output);

            // Инициализируем пин ввода
            input_pin = gpio?.OpenPin(26);
            if (input_pin != null)
            {
                input_pin.SetDriveMode(GpioPinDriveMode.InputPullUp);
                input_pin.DebounceTimeout = TimeSpan.FromMilliseconds(50);
                input_pin.ValueChanged   += ButtonPressed;
            }
            DeviceType = gpio == null ? 1 : 0;

            Window.Current.CoreWindow.KeyDown += KeyPressed;

            iothub = DeviceClient.CreateFromConnectionString(DeviceConnectionString);

            DoWork();
        }
Exemplo n.º 2
0
        public MainPage()
        {
            this.InitializeComponent();
            var gpio = GpioController.GetDefault();

            // Если приложение будет запущено на компьютере без IoT,
            // то gpio==null. Поэтому добавляем проверки на null,
            // чтобы приложение работало и на desktop/mobile
            pin = gpio?.OpenPin(17);
            pin?.SetDriveMode(GpioPinDriveMode.Output);
        }
Exemplo n.º 3
0
        static void InitButtons()
        {
            var gpioController = GpioController.GetDefault();

            ldrButton = gpioController.OpenPin(SC20260.GpioPin.PE3);
            appButton = gpioController.OpenPin(SC20260.GpioPin.PB7);
            modButton = gpioController.OpenPin(SC20260.GpioPin.PD7);

            ldrButton.SetDriveMode(GpioPinDriveMode.InputPullUp);
            appButton.SetDriveMode(GpioPinDriveMode.InputPullUp);
            modButton.SetDriveMode(GpioPinDriveMode.InputPullUp);

            new Thread(ThreadProccessButtons).Start();
        }
Exemplo n.º 4
0
        public void InitGPIO()
        {
            GpioController gpio = GpioController.GetDefault();
            GpioPin        pin  = gpio.OpenPin(5);

            pin.SetDriveMode(GpioPinDriveMode.Output);
            while (true)
            {
                pin.Write(GpioPinValue.Low);
                Thread.Sleep(600);
                pin.Write(GpioPinValue.High);
                Thread.Sleep(600);
            }
        }
        public Motor(byte in1, byte in2)
        {
            this.in1 = in1;
            this.in2 = in2;

            motorA = gpio.OpenPin(in1);
            motorB = gpio.OpenPin(in2);

            motorA.Write(GpioPinValue.Low);
            motorB.Write(GpioPinValue.Low);

            motorA.SetDriveMode(GpioPinDriveMode.Output);
            motorB.SetDriveMode(GpioPinDriveMode.Output);
        }
Exemplo n.º 6
0
        private 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.");
            }

            _pin = gpio.OpenPin(BUTTON_PIN);
            _pin.SetDriveMode(GpioPinDriveMode.Input);
            _pin.ValueChanged += PinValueChanged;
        }
Exemplo n.º 7
0
        private void InitGPIO()
        {
            pinEnable = GpioController.GetDefault().OpenPin(ENABLE_PIN);
            pinEnable.Write(GpioPinValue.Low);
            pinEnable.SetDriveMode(GpioPinDriveMode.Output);

            pinForward = GpioController.GetDefault().OpenPin(FORWARD_PIN);
            pinForward.Write(GpioPinValue.Low);
            pinForward.SetDriveMode(GpioPinDriveMode.Output);

            pinBackward = GpioController.GetDefault().OpenPin(BACKWARD_PIN);
            pinBackward.Write(GpioPinValue.Low);
            pinBackward.SetDriveMode(GpioPinDriveMode.Output);
        }
Exemplo n.º 8
0
        private void InitGPIO()
        {
            pinRed = GpioController.GetDefault().OpenPin(LED_REDPIN);
            pinRed.Write(GpioPinValue.Low);
            pinRed.SetDriveMode(GpioPinDriveMode.Output);

            pinGreen = GpioController.GetDefault().OpenPin(LED_GREENPIN);
            pinGreen.Write(GpioPinValue.Low);
            pinGreen.SetDriveMode(GpioPinDriveMode.Output);

            pinBlue = GpioController.GetDefault().OpenPin(LED_BLUEPIN);
            pinBlue.Write(GpioPinValue.Low);
            pinBlue.SetDriveMode(GpioPinDriveMode.Output);
        }
Exemplo n.º 9
0
 private static bool InitializeRight(GpioController controller)
 {
     if (!controller.TryOpenPin(3, GpioSharingMode.Exclusive, out _rightDoor, out GpioOpenStatus rightStatus))
     {
         return(false);
     }
     if (rightStatus != GpioOpenStatus.PinOpened)
     {
         return(false);
     }
     _rightDoor.SetDriveMode(GpioPinDriveMode.Output);
     _rightDoor.Write(GpioPinValue.High);
     return(true);
 }
        private static void InitGPIO(int pinNumber)
        {
            var gpio = GpioController.GetDefault();

            if (gpio == null)
            {
                return;
            }

            LED = gpio.OpenPin(pinNumber);

            LED.Write(GpioPinValue.Low);
            LED.SetDriveMode(GpioPinDriveMode.Output);
        }
Exemplo n.º 11
0
        //This method is used to initialize a GPIO pin
        private void InitializeGpio()
        {
            //Create a default GPIO controller
            GpioController gpioController = GpioController.GetDefault();

            //Use the controller to open the gpio pin of given number
            buttonPin = gpioController.OpenPin(gpioPin);
            //Debounce the pin to prevent unwanted button pressed events
            buttonPin.DebounceTimeout = new TimeSpan(1000);
            //Set the pin for input
            buttonPin.SetDriveMode(GpioPinDriveMode.Input);
            //Set a function callback in the event of a value change
            buttonPin.ValueChanged += buttonPin_ValueChanged;
        }
Exemplo n.º 12
0
        public static void Main()
        {
            // create the event NOT signalled
            _touchEvent = new ManualResetEvent(false);

            // STMPE811 touchscreen controller in STM32F429 DISCOVERY board has default I2C address 1000001 = 0x41 ...
            // ... and it's connected to I2C3 bus
            _touchController = new STMPE811(0x41, "I2C3");

            // ... INT signal is connected to PA15 with a pull-up, setup the GPIO and an event handler to handle the device interrupt requests
            var gpioController = GpioController.GetDefault();

            _touchInterrupt = gpioController.OpenPin(PinNumber('A', 15));
            _touchInterrupt.SetDriveMode(GpioPinDriveMode.Input);
            _touchInterrupt.ValueChanged += TouchScreenInterruptRequest;

            // initialize STMPE811
            if (_touchController.Initialize())
            {
                // start the touch screen controller
                _touchController.Start();

                // in the F429I DISCOVERY the INT signal has a pull-up so we need to configure the interrupt polarity to active low
                _touchController.SetInterruptPolarity(InterruptPolarity.Low);
                // as for the type better use level to improve detection
                _touchController.SetInterruptType(InterruptType.Level);

                // enable interrupts from the FIFO and the touch controller
                _touchController.EnableInterruptSource(InterruptSource.FifoAboveThreshold | InterruptSource.Touch);
                _touchController.EnableGlobalInterrupt();

                // output the ID and revision of the device
                Console.WriteLine("ChipID " + _touchController.ChipID.ToString("X4"));
                Console.WriteLine("Rev " + _touchController.RevisionNumber.ToString());

                // launch touch tracking thread
                new Thread(new ThreadStart(TouchTracking)).Start();
            }
            else
            {
                // failed to init the device
                Console.WriteLine("***** FATAL ERROR: failed to initialise the touch screen controller *****");
            }

            // infinite loop to keep main thread active
            for (; ;)
            {
                Thread.Sleep(1000);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Open pin for encoder DT, CLK and button.
        /// </summary>
        /// <param name="DT"></param>
        /// <param name="CLK"></param>
        /// <param name="btn"></param>
        public void OpenPin(int DT, int CLK, int btn)
        {
            encoderButton = GPIO.OpenPin(btn);
            encoderButton.ValueChanged   += EncoderButton_ValueChanged;
            encoderButton.DebounceTimeout = debounceTimeout;

            encoderCLK = GPIO.OpenPin(CLK);
            encoderCLK.SetDriveMode(GpioPinDriveMode.Input);
            encoderCLK.ValueChanged += EncoderCLK_ValueChanged;

            encoderDT = GPIO.OpenPin(DT);
            encoderDT.SetDriveMode(GpioPinDriveMode.Input);
            encoderDT.ValueChanged += EncoderDT_ValueChanged;
        }
Exemplo n.º 14
0
        private async void LoadUserCode(object sender, RoutedEventArgs e)
        {
            if (LightningProvider.IsLightningEnabled)
            {
                LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
            }
            else
            {
                return;
            }
            //https://github.com/Microsoft/Windows-universal-samples/blob/master/Samples/IoT-I2C/cs/Scenario1_ReadData.xaml.cs
            _gpioController = GpioController.GetDefault();
            _intPin         = _gpioController.OpenPin(INTERRUPT_PIN);
            _intPin.Write(GpioPinValue.Low);
            _intPin.SetDriveMode(GpioPinDriveMode.Input);
            _intPin.ValueChanged += _dispatcherTimer_Tick;
            _i2CController        = await I2cController.GetDefaultAsync();

            if (_i2CController == null)
            {
                return;
            }
            //TODO: make constants for device names
            _i2CConnectionSettings = new I2cConnectionSettings(0x68)//MPU-6050 address
            {
                BusSpeed = I2cBusSpeed.FastMode,
            };
            _i2CDevice = _i2CController.GetDevice(_i2CConnectionSettings);
            if (_i2CDevice == null)
            {
                return;
            }
            await Task.Delay(3);         // wait power up sequence

            WriteByte(PWR_MGMT_1, 0x80); // reset the device
            await Task.Delay(100);

            WriteByte(PWR_MGMT_1, 0x2);
            WriteByte(USER_CTRL, 0x04); //reset fifo

            WriteByte(PWR_MGMT_1, 1);   // clock source = gyro x
            WriteByte(GYRO_CONFIG, 0);  // +/- 250 degrees sec
            WriteByte(ACCEL_CONFIG, 0); // +/- 2g

            WriteByte(CONFIG, 1);       // 184 Hz, 2ms delay
            WriteByte(SMPLRT_DIV, 19);  // set rate 50Hz
            WriteByte(FIFO_EN, 0x78);   // enable accel and gyro to read into fifo
            WriteByte(USER_CTRL, 0x40); // reset and enable fifo
            WriteByte(INT_ENABLE, 0x1);
        }
Exemplo n.º 15
0
        /// <summary>
        /// 用于对输出型的GPIO进行初始化
        /// </summary>
        /// <param name="gpioPin"></param>
        /// <param name="PinID">Gpio引脚号</param>
        /// <param name="gpioPinValue">引脚初始电平值</param>
        /// <returns></returns>
        private GpioPin InitializeOutputGPIO(GpioPin gpioPin, int PinID, GpioPinValue gpioPinValue)
        {
            gpioPin = gpioController.OpenPin(GpioConstants.DoorLockPinID);
            if (gpioPin == null)
            {
                return(null);
            }

            gpioPin.SetDriveMode(GpioPinDriveMode.Output);

            //初始化引脚为低电平
            gpioPin.Write(gpioPinValue);
            return(gpioPin);
        }
Exemplo n.º 16
0
 private void InitGpio()
 {
     IoController = GpioController.GetDefault();
     if (IoController == null)
     {
         throw new Exception("GPIO does not exist on the current system.");
     }
     LatchPin = IoController.OpenPin(23);
     LatchPin.Write(GpioPinValue.Low);
     LatchPin.SetDriveMode(GpioPinDriveMode.Output);
     TogglePin = IoController.OpenPin(24);
     TogglePin.Write(GpioPinValue.High);
     TogglePin.SetDriveMode(GpioPinDriveMode.Output);
 }
Exemplo n.º 17
0
        public Task InitAsync(ILogger logger)
        {
            var gpio = GpioController.GetDefault();

            _pinUp   = gpio.OpenPin(PIN_UP);
            _pinStop = gpio.OpenPin(PIN_STOP);
            _pinDown = gpio.OpenPin(PIN_DOWN);

            _pinUp.SetDriveMode(GpioPinDriveMode.Output);
            _pinStop.SetDriveMode(GpioPinDriveMode.Output);
            _pinDown.SetDriveMode(GpioPinDriveMode.Output);

            return(Task.CompletedTask);
        }
Exemplo n.º 18
0
        public static void AddPin(int pin)
        {
            if (Pins.ContainsKey(pin))
            {
                throw new Exception("GPIO Pin already exists.");
            }

            GpioPin newPin = Controller.OpenPin(pin);

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

            Pins.Add(pin, newPin);
        }
        public UltrasonicDistanceSensor(int trigGpioPin, int echoGpioPin)
        {
            _stopwatch = new Stopwatch();

            var gpio = GpioController.GetDefault();

            _gpioPinTrig = gpio.OpenPin(trigGpioPin);
            _gpioPinEcho = gpio.OpenPin(echoGpioPin);
            _gpioPinTrig.SetDriveMode(GpioPinDriveMode.Output);
            _gpioPinEcho.SetDriveMode(GpioPinDriveMode.Input);
            _gpioPinTrig.Write(GpioPinValue.Low);

            _gpioPinEcho.ValueChanged += GpioPinEcho_ValueChanged;
        }
Exemplo n.º 20
0
        private void InitGPIO()
        {
            var gpio = GpioController.GetDefault();

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

            pin = gpio.OpenPin(LED_PIN);
            pin.Write(GpioPinValue.High);
            pin.SetDriveMode(GpioPinDriveMode.Output);
        }
Exemplo n.º 21
0
        private void initializeLimitSwitches()
        {
            /* Initialize limit switches */
            LimitSwitchPin_X1 = controller.OpenPin(LIMIT_SWITCH_PIN_X1);
            LimitSwitchPin_X2 = controller.OpenPin(LIMIT_SWITCH_PIN_X2);
            LimitSwitchPin_Y1 = controller.OpenPin(LIMIT_SWITCH_PIN_Y1);
            LimitSwitchPin_Y2 = controller.OpenPin(LIMIT_SWITCH_PIN_Y2);

            // MBM drive modes
            LimitSwitchPin_X1.SetDriveMode(GpioPinDriveMode.Input);
            LimitSwitchPin_X2.SetDriveMode(GpioPinDriveMode.Input);
            LimitSwitchPin_Y1.SetDriveMode(GpioPinDriveMode.Input);
            LimitSwitchPin_Y2.SetDriveMode(GpioPinDriveMode.Input);
        }
        public TFTMiniJoystickFeatherWingDriver(SpiDevice spiDevice, GpioPin dataCommandPin, I2cController i2cController)
        {
            _dataCommandPin = dataCommandPin;
            _dataCommandPin.SetDriveMode(GpioPinDriveMode.Output);
            _dataCommandPin.Write(GpioPinValue.Low);
            _spiDevice = spiDevice;
            _seeSaw    = i2cController.GetDevice(new I2cConnectionSettings(0x5E)
            {
                BusSpeed = I2cBusSpeed.FastMode, AddressFormat = I2cAddressFormat.SevenBit
            });
            _isRunning = false;

            Init();
        }
        private void ConfigureLoRa()
        {
            if (OpenGpioPin(EN_PIN_NUMBER, out _enPin))
            {
                _enPin.SetDriveMode(GpioPinDriveMode.Output);
                _enPin.Write(GpioPinValue.Low);
            }

            if (OpenGpioPin(SET_PIN_NUMBER, out _setPin))
            {
                _setPin.SetDriveMode(GpioPinDriveMode.Output);
                _setPin.Write(GpioPinValue.Low);
            }
        }
Exemplo n.º 24
0
        //private const int ChipSelectLine = 7;
        //private Rfm9XDevice rfm9XDevice = new Rfm9XDevice(ChipSelectLine);

        public void Run(IBackgroundTaskInstance taskInstance)
        {
            GpioController gpioController = GpioController.GetDefault();
            // Reset pin configuration then strobe briefly to factory reset
            GpioPin resetGpioPin = gpioController.OpenPin(25);

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

            for (int pinNumber = 0; pinNumber < 28; pinNumber++)
            {
                try
                {
                    using (Rfm9XDevice rfm9XDevice = new Rfm9XDevice(pinNumber))
                    {
                        byte version = rfm9XDevice.RegisterReadByte(0x42);

                        Debug.WriteLine("Pin {0} Vesion 0X{1:x2} - Bits {2}", pinNumber, version, Convert.ToString(version, 2).PadLeft(8, '0'));

                        Task.Delay(500).GetAwaiter().GetResult();
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("-------Pin open {0} failed {1}", pinNumber, ex.Message);
                }
            }

            for (byte chipSelectLine = 0; chipSelectLine < 2; chipSelectLine++)
            {
                try
                {
                    using (Rfm9XDevice rfm9XDevice = new Rfm9XDevice(chipSelectLine, ""))
                    {
                        byte version = rfm9XDevice.RegisterReadByte(0x42);

                        Debug.WriteLine("Pin {0} Vesion 0X{1:x2} - Bits {2}", chipSelectLine, version, Convert.ToString(version, 2).PadLeft(8, '0'));

                        Task.Delay(500).GetAwaiter().GetResult();
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("-------Pin open {0} failed {1}", chipSelectLine, ex.Message);
                }
            }
        }
        public MainPage()
        {
            this.InitializeComponent();

            bool isInternetConnected = NetworkInterface.GetIsNetworkAvailable();

            if (isInternetConnected == true)
            {
                conn = new SQLiteConnection(new SQLitePlatformWinRT(), path); //資料庫連接
                conn.CreateTable <Data>();                                    //建立資料表

                GpioController gpio = GpioController.GetDefault();
                Input0 = gpio.OpenPin(4);
                Input0.SetDriveMode(GpioPinDriveMode.Input);
                Input1 = gpio.OpenPin(5);
                Input1.SetDriveMode(GpioPinDriveMode.Input);
                Input2 = gpio.OpenPin(17);
                Input2.SetDriveMode(GpioPinDriveMode.Input);
                Input3 = gpio.OpenPin(18);
                Input3.SetDriveMode(GpioPinDriveMode.Input);
                Input4 = gpio.OpenPin(22);
                Input4.SetDriveMode(GpioPinDriveMode.Input);
                Input5 = gpio.OpenPin(23);
                Input5.SetDriveMode(GpioPinDriveMode.Input);
                Input6 = gpio.OpenPin(24);
                Input6.SetDriveMode(GpioPinDriveMode.Input);
                Input7 = gpio.OpenPin(25);
                Input7.SetDriveMode(GpioPinDriveMode.Input);

                timer = new DispatcherTimer
                {
                    Interval = TimeSpan.FromMilliseconds(400)
                };
                timer.Tick += Timer_Tick;
                timer.Start();



                bgwWorker.DoWork                    += new DoWorkEventHandler(bgwWorker_DoWork);
                bgwWorker.RunWorkerCompleted        += new RunWorkerCompletedEventHandler(bgwWorker_RunWorkerCompleted);
                bgwWorker.ProgressChanged           += new ProgressChangedEventHandler(bgwWorker_ProgressChanged);
                bgwWorker.WorkerReportsProgress      = true;
                bgwWorker.WorkerSupportsCancellation = true;
            }

            else
            {
                wifisettingAsync();
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// Initiates the IR remote transreceiver function to send and receive commands in NEC protocol.
        /// </summary>
        public IRRemoteController()
        {
            // Initiate the transreceiver function.
            Initialize();

            // Initiate the GPIO Controller.
            GpioController gpioController = GpioController.GetDefault();

            // Configure the pin.
            irInt = gpioController.OpenPin(18);
            irInt.SetDriveMode(GpioPinDriveMode.InputPullDown);
            irInt.DebounceTimeout = new TimeSpan(100000);
            irInt.ValueChanged   += IR_Int_ValueChanged;
        }
        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;
        }
Exemplo n.º 28
0
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            // Lade default GpioController
            gpio = GpioController.GetDefault();

            //Setze Verbindung auf den entsprechenden GPIO-Pin
            pin = gpio.OpenPin(LEDPIN);

            //Setzte Value für den Pin auf High = LED aus
            pin.Write(GpioPinValue.High);

            //Konfiguriere Pin für Ausgabe
            pin.SetDriveMode(GpioPinDriveMode.Output);
        }
Exemplo n.º 29
0
        private async Task InitGPIO()
        {
            GpioController gpio = GpioController.GetDefault();

            ledControl = gpio.OpenPin(LED_CONTROL);
            ledAlert   = gpio.OpenPin(LED_ALERT);

            // Initialize LED to the OFF state by first writing a Low value
            ledControl.Write(ledControlValue);
            ledControl.SetDriveMode(GpioPinDriveMode.Output);

            ledAlert.Write(ledAlertValue);
            ledAlert.SetDriveMode(GpioPinDriveMode.Output);
        }
Exemplo n.º 30
0
        public void ConfigureForInput(int pinNumber, Action <GpioPinEdge> callBack)
        {
            _pin = _gpio.OpenPin(pinNumber);

            _pin.DebounceTimeout = TimeSpan.FromMilliseconds(50);
            _pin.ValueChanged   += (sender, args) =>
            {
                callBack(args.Edge);

                Debug.WriteLine(args.Edge + "");
            };

            _pin.SetDriveMode(GpioPinDriveMode.Input);
        }