/// <summary>
        /// 
        /// </summary>
        private void InitGpio()
        {
            var gpio = GpioController.GetDefault();
            if (gpio== null)
            {
                Debug.WriteLine("Can't find GpioController.");
                return;
            }

            pin = gpio.OpenPin(inputPin);

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

            Debug.WriteLine("GPIO initializing...");

            //Sleep
            for (int i = 0; i <= 10000; i++) { }

            //Event
            pin.ValueChanged += Pin_ValueChanged;

            Debug.WriteLine("GPIO initialized.");
        }
Example #2
0
        private void InitGPIO()
        {
            var gpio = GpioController.GetDefault();

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

            button1Pin = gpio.OpenPin(BUTTON1_PIN);
            led1Pin = gpio.OpenPin(LED1_PIN);

            // Initialize LED to the OFF state by first writing a HIGH value
            led1Pin.Write(GpioPinValue.High);
            led1Pin.SetDriveMode(GpioPinDriveMode.Output);

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

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

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

            GpioStatus.Text = "GPIO pins initialized correctly.";
        }
Example #3
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 #4
0
        public override void Init()
        {
            Debug.WriteLine("Initializing push button.");

            try
            {
                _pushButtonPin = _gpioController.OpenPin(Pin);

                if (_pushButtonPin == null)
                {
                    Debug.WriteLine(string.Format("Push button pin not found at GPIO {0}.", Pin));
                    throw new Exception(string.Format("Push button pin not found at GPIO {0}.", Pin));
                }
                else
                {
                    Debug.WriteLine(string.Format("Push button initialized at GPIO {0}.", Pin));
                }

                if (_pushButtonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
                    _pushButtonPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
                else
                    _pushButtonPin.SetDriveMode(GpioPinDriveMode.Input);

                _pushButtonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);

                _pushButtonPin.ValueChanged += _pushButtonPin_ValueChanged;

                Debug.WriteLine("Push button initialized.");
            }
            catch
            {
                Debug.WriteLine("Failed to initialize push button.");
                throw new Exception("Failed to initialize push button.");
            }
        }
        private void InitGPIO()
        {
            var gpio = GpioController.GetDefault();

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

            _buttonpin = gpio.OpenPin(BUTTON_PIN);
            _buzzerpin = gpio.OpenPin(BUZZER_PIN);

            if (_buttonpin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
                _buttonpin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            else
                _buttonpin.SetDriveMode(GpioPinDriveMode.Input);

            _buttonpin.DebounceTimeout = TimeSpan.FromMilliseconds(50);
            _buttonpin.ValueChanged += Buttonpin_ValueChanged;

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

            GpioStatus.Text = "GPIO button and buzzer pin initialized correctly.";
        }
Example #6
0
        int RCTime(GpioPin pin, int max)
        {
            pin.SetDriveMode(GpioPinDriveMode.Output);
            pin.Write(GpioPinValue.Low);

            pin.SetDriveMode(GpioPinDriveMode.Input);
            int reading = 0;
            while (pin.Read() == GpioPinValue.Low)
            {
                reading++;
                if (reading >= max) break;
            }
            return reading;
        }
        /// <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(25);

            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);
            }

            // 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;
        }
        /// <summary>
        ///   Initializes SPI connection and control pins
        /// </summary>
        public void Initialize(SpiMode spiMode, int chipSelectPin, int chipEnablePin, int interruptPin)
        {
            var gpio = GpioController.GetDefault();
            // Chip Select : Active Low
            // Clock : Active High, Data clocked in on rising edge
            _spiDevice = InitSpi(chipSelectPin, spiMode).Result;

            _irqPin = gpio.OpenPin(interruptPin);
            _irqPin.SetDriveMode(GpioPinDriveMode.InputPullUp);

            // Initialize IRQ Port
            // _irqPin = new InterruptPort(interruptPin, false, Port.ResistorMode.PullUp,
            //                            Port.InterruptMode.InterruptEdgeLow);
            _irqPin.ValueChanged += _irqPin_ValueChanged;

            _cePin = gpio.OpenPin(chipEnablePin);
            // Initialize Chip Enable Port
            _cePin.SetDriveMode(GpioPinDriveMode.Output);

            // Module reset time
            var task = Task.Delay(100);
            task.Wait();

            _initialized = true;
        }
 private void InitGPIO()
 {
     var gpio = GpioController.GetDefault();
     _pinMotion = gpio.OpenPin(LED_MOTION);
     _pinMotion.SetDriveMode(GpioPinDriveMode.Input);
     _pinMotion.ValueChanged += _pinMotion_ValueChanged;
 }
        private bool initGPIO() {
            //Czy jest GPIO?
            if (!Windows.Foundation.Metadata.ApiInformation.IsApiContractPresent("Windows.Devices.DevicesLowLevelContract",1))
                return false;
            if (!Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Devices.Gpio.GpioController"))
                return false;
            if (!Windows.Foundation.Metadata.ApiInformation.IsMethodPresent("Windows.Devices.Gpio.GpioController", "GetDefault"))
                return false;

            if (Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily != "Windows.IoT")
                return false;
            //Windows.System.Profile.AnalyticsInfo.DeviceForm
            var gpio = GpioController.GetDefault();
            if (gpio == null) {
                pinLED = null;
                return false;
            }
            pinLED = gpio.OpenPin(LED_PIN);
            if (pinLED == null) return false;
            pinLED.SetDriveMode(GpioPinDriveMode.Output);
            pinPIR = gpio.OpenPin(PIR_PIN);
            if (pinPIR == null) return false;
            pinPIR.SetDriveMode(GpioPinDriveMode.Input);
            pinPIR.ValueChanged += PinPIR_ValueChanged;

            setState(false); //Zawsze zmienia stan - zapisuje do pin
            return true;
        }
Example #11
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            //
            // TODO: Insert code to perform background work
            //
            // If you start any asynchronous methods here, prevent the task
            // from closing prematurely by using BackgroundTaskDeferral as
            // described in http://aka.ms/backgroundtaskdeferral
            //
            var gpio = GpioController.GetDefault();

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

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

            while (true)
            {

            }
        }
Example #12
0
        private void InitGPIO()
        {
            _pin = GpioController.GetDefault().OpenPin(_pinNumber);

            _pin.Write(GpioPinValue.High);
            _pin.SetDriveMode(GpioPinDriveMode.Output);
        }
Example #13
0
        private void InitGpio()
        {
            var gpio = GpioController.GetDefault();

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

            redpin = gpio.OpenPin(REDLED_PIN);
            bluepin = gpio.OpenPin(BLUELED_PIN);
            greenpin = gpio.OpenPin(GREENLED_PIN);

            redpin.Write(GpioPinValue.High);
            redpin.SetDriveMode(GpioPinDriveMode.Output);
            bluepin.Write(GpioPinValue.High);
            bluepin.SetDriveMode(GpioPinDriveMode.Output);
            greenpin.Write(GpioPinValue.High);
            greenpin.SetDriveMode(GpioPinDriveMode.Output);

            GpioStatus.Text = "GPIO red/green/blue pin initialized correctly";
        }
        public async Task InitAsync()
        {
            if (!init)
            {
                var gpio = GpioController.GetDefault();

                if (gpio != null)
                {
                    gpioPinTrig = gpio.OpenPin(trigGpioPin);
                    gpioPinEcho = gpio.OpenPin(echoGpioPin);
                    gpioPinTrig.SetDriveMode(GpioPinDriveMode.Output);
                    gpioPinEcho.SetDriveMode(GpioPinDriveMode.Input);
                    gpioPinTrig.Write(GpioPinValue.Low);

                    //first time ensure the pin is low and wait two seconds
                    gpioPinTrig.Write(GpioPinValue.Low);
                    await Task.Delay(2000);
                    init = true;
                }
                else
                {
                    throw new InvalidOperationException("Gpio not present");
                }
            }
        }
        private bool InitGPIO()
        {
            // Initialize the GPIO controller
            GpioController gpio = GpioController.GetDefault();

            // Show an error if there is no GPIO controller
            if (gpio == null)
            {
                _pin1 = null;
                _pin2 = null;
                return false;
            }

            // Initialize the GPIO pin for the first LED
            _pin1 = gpio.OpenPin(LED1_PIN);
            _pin1.Write(GpioPinValue.Low);
            _pin1.SetDriveMode(GpioPinDriveMode.Output);

            // Initialize the GPIO pin for the second LED
            _pin2 = gpio.OpenPin(LED2_PIN);
            _pin2.Write(GpioPinValue.High);
            _pin2.SetDriveMode(GpioPinDriveMode.Output);

            return true;
        }
Example #16
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            deferral = taskInstance.GetDeferral();

            //Motor starts off
            currentPulseWidth = 0;

            //The stopwatch will be used to precisely time calls to pulse the motor.
            stopwatch = Stopwatch.StartNew();

            GpioController controller = GpioController.GetDefault();

            //Buttons are attached to pins 5 and 6 to control which direction the motor should run in
            //Interrupts (ValueChanged) events are used to notify this app when the buttons are pressed
            forwardButton = controller.OpenPin(5);
            forwardButton.DebounceTimeout = new TimeSpan(0, 0, 0, 0, 250);
            forwardButton.SetDriveMode(GpioPinDriveMode.Input);
            forwardButton.ValueChanged += _forwardButton_ValueChanged;

            backwardButton = controller.OpenPin(6);
            backwardButton.SetDriveMode(GpioPinDriveMode.Input);
            forwardButton.DebounceTimeout = new TimeSpan(0, 0, 0, 0, 250);
            backwardButton.ValueChanged += _backgwardButton_ValueChanged;


            servoPin = controller.OpenPin(13);
            servoPin.SetDriveMode(GpioPinDriveMode.Output);

            
           

            //You do not need to await this, as your goal is to have this run for the lifetime of the application
            Windows.System.Threading.ThreadPool.RunAsync(this.MotorThread, Windows.System.Threading.WorkItemPriority.High);
        }
Example #17
0
        private void InitGPIO()
        {
            var gpio = GpioController.GetDefault();

            // error prompt
            if (gpio == null) {
                GpioStatus.Text = "There's no GPIO controller on this device";
                return -1;
            }

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

            // init LED to OFF by HIGH, cuz LED is wired in LOW config
            ledPin.Write(GpioPinValue.High);
            ledPin.SetDriveMode(GpioPinDriveMode.Output);

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

            // setting debounce timeout
            buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);

            // register for ValueChanged event
            // so buttonPin_ValueChanged()
            // is called when button is pressed
            buttonPin.ValueChanged += buttonPin_ValueChanged;

            GpioStatus.Text = "GPIO pins initialized correctly";
        }
        private bool initialize()
        {
            try
            {
                var gpio = GpioController.GetDefault();

                if (gpio != null)
                {
                    _inputPin = gpio.OpenPin(MICRO_INPUT);

                    if (_inputPin != null)
                    {
                        _inputPin.SetDriveMode(GpioPinDriveMode.Input);

                        return true;
                    }
                }
            }
            catch
            {
                lb_Output.Items.Add("Initialization failed!");
            }

            return false;
        }
        private void InitGPIO()
        {
            if (!ApiInformation.IsTypePresent(GpioPresentNS))
            {
                return;
            }

            var gpio = GpioController.GetDefault();
            if (gpio == null)
            {
                Debug.WriteLine("There is no GPIO controller on this device.");
                return;
            }

            var buttonPin = gpio.OpenPin(ButtonPin);
            ledPin = gpio.OpenPin(LedPin);

            // 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(GpioPinValue.High);
            ledPin.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);

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

            buttonPin.ValueChanged += ButtonPin_ValueChanged;
        }
Example #20
0
        public async Task Init()
        {
            var gpio = GpioController.GetDefault();
            // Show an error if there is no GPIO controller
            if (gpio == null)
            {
                logger.WriteLn("There is no GPIO controller on this device.");
                return;
            }

            this.switchX = gpio.OpenPin(5);
            this.switchY = gpio.OpenPin(6);
            switchX.SetDriveMode(GpioPinDriveMode.Input);
            switchY.SetDriveMode(GpioPinDriveMode.Input);
            logger.WriteLn("GPIO initialized", LogType.Success);

            await servoDriver.Init();
            logger.WriteLn("Pen driver initialized", LogType.Success);
            await PenUp();

            await motorDriver.Init();
            motorX.SetSpeed(200);
            motorY.SetSpeed(200);
            logger.WriteLn("Plotter initialized", LogType.Success);
        } 
Example #21
0
        private void InitializeGpio()
        {
            var gpio = GpioController.GetDefault();

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

            buttonPin = gpio.OpenPin(BUTTON_PIN);

            if ( buttonPin == null)
            {
                GpioStatus.Text = "Unable to open button pin.";
                return;
            }

            // Button is in a active high configuration which means it will go to high when pressed
            // Take advantage of the Raspberry Pi's built in pull down resistors
            buttonPin.SetDriveMode(GpioPinDriveMode.InputPullDown);

            // Set a debounce timeout to filter out the ups and downs from a button press
            buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);

            // Register for the ValueChanged event - aka when the button is pushed
            buttonPin.ValueChanged += buttonPin_ValueChanged;

            GpioStatus.Text = "GPIO pins initialized correctly.";
        }
        public InfraRed(byte IR_Pin)
        {
            this.IR_Pin = IR_Pin;

            input = gpio.OpenPin(IR_Pin);
            input.SetDriveMode(GpioPinDriveMode.Input);
        }
        private void InitGPIO()
        {
            // Initialize the GPIO controller
            GpioController gpio = GpioController.GetDefault();

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

            // Initialize the GPIO pin for the first LED
            _pin1 = gpio.OpenPin(LED1_PIN);
            _pin1.Write(GpioPinValue.Low);
            _pin1.SetDriveMode(GpioPinDriveMode.Output);

            // Initialize the LED1 Ellipse to draw Gray
            LED1.Fill = _grayBrush;

            // Initialize the GPIO pin for the second LED
            _pin2 = gpio.OpenPin(LED2_PIN);
            _pin2.Write(GpioPinValue.Low);
            _pin2.SetDriveMode(GpioPinDriveMode.Output);

            // Initialize the LED2 Ellipse to draw Gray
            LED2.Fill = _grayBrush;

            // Show the GPIO is OK message
            GpioStatus.Text = "GPIO pin initialized correctly.";
        }
 public MotionSensor()
 {
     var gpioController = GpioController.GetDefault();
     motionSensorPin = gpioController.OpenPin(App.Controller.XmlSettings.GpioMotionPin);
     motionSensorPin.SetDriveMode(GpioPinDriveMode.Input);
     motionSensorPin.ValueChanged += MotionSensorPin_ValueChanged;
 }
Example #25
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.";
        }
        //
        // Constructor
        //
        public TLC5947ControllerBase(uint latchPin, uint blackoutPin)
        {
            // Create the controller
            m_controller = new LedController(this, ControlerUpdateType.AllSlots);

            // Open the latch pin
            GpioController controller = GpioController.GetDefault();
            m_latchPin = controller.OpenPin((int)latchPin);
            m_latchPin.SetDriveMode(GpioPinDriveMode.Output);

            // Open the black out pin, set it high and low to reset the device.
            m_blackoutPin = controller.OpenPin((int)blackoutPin);
            m_blackoutPin.SetDriveMode(GpioPinDriveMode.Output);
            m_blackoutPin.Write(GpioPinValue.High);
            m_blackoutPin.Write(GpioPinValue.Low);

            // Create a async task to setup SPI
            new Task(async () =>
            {
                // Create the settings
                var settings = new SpiConnectionSettings(SPI_CHIP_SELECT_LINE);
                // Max SPI clock frequency, here it is 30MHz
                settings.ClockFrequency = 30000000;
                settings.Mode = SpiMode.Mode0;
                //  Find the selector string for the SPI bus controller
                string spiAqs = SpiDevice.GetDeviceSelector(SPI_CONTROLLER_NAME);
                // Find the SPI bus controller device with our selector string
                var devicesInfo = await DeviceInformation.FindAllAsync(spiAqs);
                // Create an SpiDevice with our bus controller and SPI settings
                m_spiDevice = await SpiDevice.FromIdAsync(devicesInfo[0].Id, settings);
            }).Start();
        }
        public MainPage()
        {
            this.InitializeComponent();
            try
            {
                if (Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily != "Windows.IoT")
                {
                    m_deviceClient = DeviceClient.CreateFromConnectionString("HostName=pltkw3IoT.azure-devices.net;DeviceId=pltkw87Demo;SharedAccessKey=ABC", TransportType.Http1);
                    m_telemetrySource = new IoTTelemetrySourceGen();
                }
                else
                {
                    m_deviceClient = DeviceClient.CreateFromConnectionString("HostName=pltkw3IoT.azure-devices.net;DeviceId=rpi2C;SharedAccessKey=ABC", TransportType.Http1);
                    m_telemetrySource = new IoTTelemetrySourceDevice();
                    //Inaczej null
                    var gpio = GpioController.GetDefault();
                    pinLED = gpio.OpenPin(LED_PIN);
                    pinLED.SetDriveMode(GpioPinDriveMode.Output);
                    m_lcd = new TK_LCDlcm1602DriverWRC.LCDI2C(0x27, 2, 16);
                    m_lcd.InitAsync();
                }
                //LED
                uxToggleLaser.IsOn = true;
                m_telemetrySource.Init();
                m_timer.Tick += M_timer_Tick;
                startTimer();
                ReceiveDataFromAzure(); //Po prostu "task"
            }
            catch (Exception ex)
            {
                m_tc.TrackException(ex);
            }

        }
        private void InitGPIO()
        {
            // get the GPIO controller
            var gpio = GpioController.GetDefault();

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

            // set up the LED on the defined GPIO pin
            // and set it to High to turn off the LED
            led = gpio.OpenPin(ledPin);
            led.Write(GpioPinValue.High);
            led.SetDriveMode(GpioPinDriveMode.Output);

            // set up the PIR sensor's signal on the defined GPIO pin
            // and set it's initial value to Low
            pir = gpio.OpenPin(pirPin);
            pir.SetDriveMode(GpioPinDriveMode.Input);

            //ID is the Pin number
            sensor1.SensorId = pir.PinNumber.ToString();
            sensor1.SensorType = "PIR";
            sensors[node1.CurrentSensor] = sensor1;

            GpioStatus.Text = "GPIO pins initialized correctly.";
        }
 public ServoDriver(GpioPin servoPin, ServoPulseModel servoPulseModel)
 {
     _servoPin = servoPin;
     _servoPin.SetDriveMode(GpioPinDriveMode.Output);
     _servoPulseModel = servoPulseModel;
     _servoBackgroundTask = Windows.System.Threading.ThreadPool.RunAsync(this.ServoBackgrounTask, Windows.System.Threading.WorkItemPriority.High);
 }
Example #30
0
        public MainPage()
        {
            this.InitializeComponent();
            var gpio = GpioController.GetDefault();

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

            pin5 = gpio.OpenPin(5);
            pin6 = gpio.OpenPin(6);

            // Show an error if the pin5 wasn't initialized properly
            if (pin5 == null)
            {
                //GpioStatus.Text = "There were problems initializing the GPIO pin5.";
                return;
            }
           

            pin6.SetDriveMode(GpioPinDriveMode.Output);
            pin5.SetDriveMode(GpioPinDriveMode.InputPullUp);
            pin5.ValueChanged += Pin5OnValueChanged;
        }