Voffcon Esp32 device server
 All Classes Functions
GPin Class Reference

Class for handling GPIO pins Use it to read from or write to a pin More...

Public Member Functions

 GPin (const char *strPinName, PINTYPE pinType, int pinNumber, int pinValue)
 Constructor for the GPin object You will need to porovide name, type, number and a starting value of the pin More...
 
 ~GPin ()
 Deconstructor for the pin More...
 
void setName (const char *strPinName)
 Assigns a name to a specific pin More...
 
String getName ()
 Gets a pin name More...
 
void setValue (int value)
 Sets a new value to a pin If the pin is of the type PINTYPE_OUTPUT_ANALOG or PINTYPE_OUTPUT_DIGITAL Then the GPIO pin of the device will be changed to this value. More...
 
int getValue (bool readValueFromHardware=true)
 Read a pin value. If input type is PINTYPE_INPUT_DIGITAL or PINTYPE_INPUT_ANALOG and readValueFromHardware is true then a read will be maid directly to the hardwarepin. otherwise the old member value will be returned. More...
 
int getNumber ()
 Get the number of a pin. More...
 
int getType ()
 Gets the type of the pin More...
 
String toJson ()
 Converts the pin -name, -number, -type and -value to a valid json object string More...
 
String toJsonKeyValue ()
 Returns pin number and value as a Key value pair with no surrounding curly brackets More...
 

Detailed Description

Class for handling GPIO pins Use it to read from or write to a pin

Constructor & Destructor Documentation

GPin::GPin ( const char *  strPinName,
PINTYPE  pinType,
int  pinNumber,
int  pinValue 
)

Constructor for the GPin object You will need to porovide name, type, number and a starting value of the pin

Parameters
strPinNameName of the pin
pinTypeType of the pin

Possible pin types are:

PINTYPE_INPUT_ANALOG : "Read method analogRead shall be used"

PINTYPE_INPUT_DIGITAL : "Read method digitalRead shall be used"

PINTYPE_OUTPUT_ANALOG : "Write method analogWrite shall be used"

PINTYPE_OUTPUT_DIGITAL : "Write method digitalWrite shall be used"

PINTYPE_OUTPUT_VIRTUAL : "A pin not connected to hardware, but can store values"

Parameters
pinNumberNumber of the pin. That is the GPIO number
pinValueThe value to set the pin to
GPin::~GPin ( )

Deconstructor for the pin

Member Function Documentation

String GPin::getName ( )

Gets a pin name

Returns
A String containing the pin name
int GPin::getNumber ( )

Get the number of a pin.

You can then use this number to search for the index of the pin in the GPins object

Returns
The number of the pin. ps. this is not the Index of a pin.
int GPin::getType ( )

Gets the type of the pin

Possible pin types are:

PINTYPE_INPUT_ANALOG : "Read method analogRead shall be used"

PINTYPE_INPUT_DIGITAL : "Read method digitalRead shall be used"

PINTYPE_OUTPUT_ANALOG : "Write method analogWrite shall be used"

PINTYPE_OUTPUT_DIGITAL : "Write method digitalWrite shall be used"

PINTYPE_OUTPUT_VIRTUAL : "A pin not connected to hardware, but can store values"

Returns
The type of the pin
int GPin::getValue ( bool  readValueFromHardware = true)

Read a pin value. If input type is PINTYPE_INPUT_DIGITAL or PINTYPE_INPUT_ANALOG and readValueFromHardware is true then a read will be maid directly to the hardwarepin. otherwise the old member value will be returned.

Parameters
readValueFromHardware
Returns
The value as an int
void GPin::setName ( const char *  strPinName)

Assigns a name to a specific pin

Parameters
strPinNameName of the pin
void GPin::setValue ( int  value)

Sets a new value to a pin If the pin is of the type PINTYPE_OUTPUT_ANALOG or PINTYPE_OUTPUT_DIGITAL Then the GPIO pin of the device will be changed to this value.

Parameters
valueThe new value to set
String GPin::toJson ( )

Converts the pin -name, -number, -type and -value to a valid json object string

Returns
A json object string with information about pin members
String GPin::toJsonKeyValue ( )

Returns pin number and value as a Key value pair with no surrounding curly brackets

Returns
A key value string which can be added to a Json object string

The documentation for this class was generated from the following file: