Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practice to put GPIO logic in UWP

If I create a app in UWP for example with Template 10. I use C#

I want to have the GpioController logic in a class or somewhere that will handle all input and output business like set all pins and events.

Like an example, when a button is pressed it will send a POST request to the server, this must work in any view.

If I go to a view and I want to get the status of a pin to show like "The door is open"

Also if for an example a sensor is triggering a pin to HIGH, if i change view it cant trigger buttonPin_ValueChanged event and or set it to LOW for any reason unless the sensor is LOW.

Even if the pins Power-on Pull is PullDown.

pin = gpio.OpenPin(12);
pin.SetDriveMode(GpioPinDriveMode.InputPullUp);
pin.Write(GpioPinValue.Low);
pin.ValueChanged += buttonPin_ValueChanged;
like image 385
Krister Johansson Avatar asked Sep 11 '16 23:09

Krister Johansson


People also ask

Does it matter which GPIO pin I use?

The power pins pull power directly from the Raspberry Pi. GND are the pins you use to ground your devices. It doesn't matter which pin you use as they are all connected to the same line.

Which module is used to control the GPIO in Python?

Raspberry-gpio-python or RPi. GPIO, is a Python module to control the GPIO interface on the Raspberry Pi. It was developed by Ben Croston and released under an MIT free software license.

What is the start up state for the GPIO pins?

GPIOs up to 8: default state is 1 (HIGH, or close to 3.3V). GPIOs 9 to 27: default state is 0 (LOW, or close to 0V).

What is GPIO protocol?

GPIO or general purpose input/output is a generic pin on an integrated circuit or computer board whose behavior (including whether it is an input or output pin) is controllable by the user at run time. ( From Wikipedia, the free encyclopedia)


1 Answers

You can create a GpioController object in your initial class, and pass it as an object to other classes.

Such as:

class BaseClass {
    GpioController gpio;

    void createGpioController(){
        gpio = new GpioController(/*Constuctor arguments here.*/);
    }

    void moveToNextClass(NextClass next){
        //Instantiate next class with any special constructors.
        next.gpio = this.gpio; 
        //Launch next class with same gpio member values. 
    }
}

class NextClass: BaseClass {
   GpioController gpio; //Will be assigned by last class.
}
like image 143
NonCreature0714 Avatar answered Sep 28 '22 20:09

NonCreature0714