NAP
Public Member Functions | Public Attributes | List of all members
GpioPin Class Reference

#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)
 
- Public Member Functions inherited from Resource
 Resource ()
 
- Public Member Functions inherited from Object
 Object ()
 
virtual ~Object ()
 
 Object (Object &)=delete
 
Objectoperator= (const Object &)=delete
 
 Object (Object &&)=delete
 
Objectoperator= (Object &&)=delete
 

Public Attributes

int mPin = 0
 Property: 'Pin' the Pin number. More...
 
EPinMode mMode = EPinMode::OUTPUT
 Property: 'Mode' Pin mode. More...
 
- Public Attributes inherited from Object
std::string mID
 Property: 'mID' unique name of the object. Used as an identifier by the system. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from Object
static bool isIDProperty (rtti::Instance &object, const rtti::Property &property)
 

Description

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/

Inheritance diagram for GpioPin:
[legend]
Collaboration diagram for GpioPin:
[legend]

Constructor & Destructor Documentation

◆ GpioPin()

GpioPin ( GpioService service)

Constructor

Parameters
servicereference to GpioService

Member Function Documentation

◆ getAnalogRead()

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.

Returns
the value of the analog pin between 0-255

◆ getDigitalRead()

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.

Returns
will be HIGH or LOW (1 or 0) depending on the logic level at the pin.

◆ init()

bool init ( utility::ErrorState errorState)
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.

Parameters
errorStateshould contain the error message when initialization fails.
Returns
if initialization succeeded or failed.

Reimplemented from Object.

◆ onDestroy()

void onDestroy ( )
overridevirtual

Called upon destruction before destructor

Reimplemented from Object.

◆ setAnalogWrite()

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.

Parameters
valuethe value between 0-255

◆ setDigitalWrite()

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.

Parameters
valuethe value HIGH or LOW (1 or 0) depending on the logic level at the pin.

◆ setPinMode()

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.

Parameters
modethe mode

◆ setPullUpDnControl()

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.

Parameters
pudPUD_OFF, (no pull up/down), PUD_DOWN (pull to ground) or PUD_UP (pull to 3.3v)

◆ setPwmValue()

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.

Parameters
valuethe value between 0-1024

Member Data Documentation

◆ mMode

EPinMode mMode = EPinMode::OUTPUT

Property: 'Mode' Pin mode.

◆ mPin

int mPin = 0

Property: 'Pin' the Pin number.