Skip to content

Commit

Permalink
Make certain DigitalIn/Out/InOut methods virtual
Browse files Browse the repository at this point in the history
  • Loading branch information
AGlass0fMilk committed Jun 30, 2020
1 parent a6207ca commit a332084
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
13 changes: 10 additions & 3 deletions drivers/DigitalIn.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,20 @@ class DigitalIn {
gpio_init_in_ex(&gpio, pin, mode);
}

/** Class destructor, deinitialize the pin
*/
virtual ~DigitalIn()
{
gpio_free(&gpio);
}

/** Read the input, represented as 0 or 1 (int)
*
* @returns
* An integer representing the state of the input pin,
* 0 for logical 0, 1 for logical 1
*/
int read()
virtual int read()
{
// Thread safe / atomic HAL call
return gpio_read(&gpio);
Expand All @@ -91,15 +98,15 @@ class DigitalIn {
*
* @param pull PullUp, PullDown, PullNone, OpenDrain
*/
void mode(PinMode pull);
virtual void mode(PinMode pull);

/** Return the output setting, represented as 0 or 1 (int)
*
* @returns
* Non zero value if pin is connected to uc GPIO
* 0 if gpio object was initialized with NC
*/
int is_connected()
virtual int is_connected()
{
// Thread safe / atomic HAL call
return gpio_is_connected(&gpio);
Expand Down
19 changes: 13 additions & 6 deletions drivers/DigitalInOut.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,19 @@ class DigitalInOut {
gpio_init_inout(&gpio, pin, direction, mode, value);
}

/** Class destructor, deinitialize the pin
*/
virtual ~DigitalInOut()
{
gpio_free(&gpio);
}

/** Set the output, specified as 0 or 1 (int)
*
* @param value An integer specifying the pin output value,
* 0 for logical 0, 1 (or any other non-zero value) for logical 1
*/
void write(int value)
virtual void write(int value)
{
// Thread safe / atomic HAL call
gpio_write(&gpio, value);
Expand All @@ -75,33 +82,33 @@ class DigitalInOut {
* an integer representing the output setting of the pin if it is an output,
* or read the input if set as an input
*/
int read()
virtual int read()
{
// Thread safe / atomic HAL call
return gpio_read(&gpio);
}

/** Set as an output
*/
void output();
virtual void output();

/** Set as an input
*/
void input();
virtual void input();

/** Set the input pin mode
*
* @param pull PullUp, PullDown, PullNone, OpenDrain
*/
void mode(PinMode pull);
virtual void mode(PinMode pull);

/** Return the output setting, represented as 0 or 1 (int)
*
* @returns
* Non zero value if pin is connected to uc GPIO
* 0 if gpio object was initialized with NC
*/
int is_connected()
virtual int is_connected()
{
// Thread safe / atomic HAL call
return gpio_is_connected(&gpio);
Expand Down
13 changes: 10 additions & 3 deletions drivers/DigitalOut.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,19 @@ class DigitalOut {
gpio_init_out_ex(&gpio, pin, value);
}

/** Class destructor, deinitialize the pin
*/
virtual ~DigitalOut()
{
gpio_free(&gpio);
}

/** Set the output, specified as 0 or 1 (int)
*
* @param value An integer specifying the pin output value,
* 0 for logical 0, 1 (or any other non-zero value) for logical 1
*/
void write(int value)
virtual void write(int value)
{
// Thread safe / atomic HAL call
gpio_write(&gpio, value);
Expand All @@ -87,7 +94,7 @@ class DigitalOut {
* an integer representing the output setting of the pin,
* 0 for logical 0, 1 for logical 1
*/
int read()
virtual int read()
{
// Thread safe / atomic HAL call
return gpio_read(&gpio);
Expand All @@ -99,7 +106,7 @@ class DigitalOut {
* Non zero value if pin is connected to uc GPIO
* 0 if gpio object was initialized with NC
*/
int is_connected()
virtual int is_connected()
{
// Thread safe / atomic HAL call
return gpio_is_connected(&gpio);
Expand Down

0 comments on commit a332084

Please sign in to comment.