#include </opt/build/repo/nap/modules/nappipins/src/gpiopin.h>
Public Member Functions | |
GpioPin (GpioService &service) | |
bool | init (utility::ErrorState &errorState) override |
void | onDestroy () override |
void | setPinMode (EPinMode mode) |
void | setPullUpDnControl (EPUDMode pud) |
void | setPwmValue (int value) |
EDigitalPinValue | getDigitalRead () |
int | getAnalogRead () |
void | setDigitalWrite (EDigitalPinValue value) |
void | setAnalogWrite (int value) |
![]() | |
Resource () | |
![]() | |
Object () | |
virtual | ~Object () |
Object (Object &)=delete | |
Object & | operator= (const Object &)=delete |
Object (Object &&)=delete | |
Object & | operator= (Object &&)=delete |
Public Attributes | |
int | mPin = 0 |
Property: 'Pin' the Pin number. More... | |
EPinMode | mMode = EPinMode::OUTPUT |
Property: 'Mode' Pin mode. More... | |
![]() | |
std::string | mID |
Property: 'mID' unique name of the object. Used as an identifier by the system. More... | |
Additional Inherited Members | |
![]() | |
static bool | isIDProperty (rtti::Instance &object, const rtti::Property &property) |
GpioPin can be used to read or write to a GPIO pin on the Raspberry PI. You can set the pin number by setting the "Pin" property and set its mode by setting the "Mode" property. The GpioService uses "wiringPiSetupGpio()" which means the service uses the Broadcom GPIO pin numbers directly with no re-mapping. Write calls will always be asynchronous and not block the calling thread. Read calls are synchronous and perform a mutex lock to ensure thread-safety. See https://pinout.xyz/ to help with mapping. The PiGPIOPin wraps the core functionality of wiringPi, see : http://wiringpi.com/reference/
GpioPin | ( | GpioService & | service | ) |
Constructor
service | reference to GpioService |
int getAnalogRead | ( | ) |
This returns the value read on the supplied analog input pin. The analog input and output are 8-bit devices, so have a range of 0 to 255 when we read/write them.
EDigitalPinValue getDigitalRead | ( | ) |
This function returns the value read at the given pin. It will be HIGH or LOW (1 or 0) depending on the logic level at the pin.
|
overridevirtual |
Override this method to initialize the object after de-serialization. When called it is safe to assume that all dependencies have been resolved up to this point.
errorState | should contain the error message when initialization fails. |
Reimplemented from Object.
|
overridevirtual |
Called upon destruction before destructor
Reimplemented from Object.
void setAnalogWrite | ( | int | value | ) |
This writes the given value to the supplied analog pin. The analog input and output are 8-bit devices, so have a range of 0 to 255 when we read/write them.
value | the value between 0-255 |
void setDigitalWrite | ( | EDigitalPinValue | value | ) |
Writes the value HIGH or LOW (1 or 0) to the given pin which must have been previously set as an output.
value | the value HIGH or LOW (1 or 0) depending on the logic level at the pin. |
void setPinMode | ( | EPinMode | mode | ) |
This sets the mode of a pin to either INPUT, OUTPUT, PWM_OUTPUT or GPIO_CLOCK. Note that only wiringPi pin 1 (BCM_GPIO 18) supports PWM output and only wiringPi pin 7 (BCM_GPIO 4) supports CLOCK output modes.
mode | the mode |
void setPullUpDnControl | ( | EPUDMode | pud | ) |
This sets the pull-up or pull-down resistor mode on the given pin, which should be set as an input. Unlike the Arduino, the BCM2835 has both pull-up an down internal resistors. The parameter pud should be; PUD_OFF, (no pull up/down), PUD_DOWN (pull to ground) or PUD_UP (pull to 3.3v) The internal pull up/down resistors have a value of approximately 50KΩ on the Raspberry Pi.
pud | PUD_OFF, (no pull up/down), PUD_DOWN (pull to ground) or PUD_UP (pull to 3.3v) |
void setPwmValue | ( | int | value | ) |
Writes the value to the PWM register for the given pin. The Raspberry Pi has one on-board PWM pin, pin 1 (BMC_GPIO 18, Phys 12) and the range is 0-1024. Other PWM devices may have other PWM ranges.
value | the value between 0-1024 |
EPinMode mMode = EPinMode::OUTPUT |
Property: 'Mode' Pin mode.
int mPin = 0 |
Property: 'Pin' the Pin number.