Skip to content

Commit feea424

Browse files
committed
Make certain DigitalOut methods virtual
1 parent a6207ca commit feea424

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

drivers/DigitalIn.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,20 @@ class DigitalIn {
7575
gpio_init_in_ex(&gpio, pin, mode);
7676
}
7777

78+
/** Class destructor, deinitialize the pin
79+
*/
80+
virtual ~DigitalIn()
81+
{
82+
gpio_free(&gpio);
83+
}
84+
7885
/** Read the input, represented as 0 or 1 (int)
7986
*
8087
* @returns
8188
* An integer representing the state of the input pin,
8289
* 0 for logical 0, 1 for logical 1
8390
*/
84-
int read()
91+
virtual int read()
8592
{
8693
// Thread safe / atomic HAL call
8794
return gpio_read(&gpio);
@@ -91,15 +98,15 @@ class DigitalIn {
9198
*
9299
* @param pull PullUp, PullDown, PullNone, OpenDrain
93100
*/
94-
void mode(PinMode pull);
101+
virtual void mode(PinMode pull);
95102

96103
/** Return the output setting, represented as 0 or 1 (int)
97104
*
98105
* @returns
99106
* Non zero value if pin is connected to uc GPIO
100107
* 0 if gpio object was initialized with NC
101108
*/
102-
int is_connected()
109+
virtual int is_connected()
103110
{
104111
// Thread safe / atomic HAL call
105112
return gpio_is_connected(&gpio);

drivers/DigitalInOut.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,19 @@ class DigitalInOut {
5858
gpio_init_inout(&gpio, pin, direction, mode, value);
5959
}
6060

61+
/** Class destructor, deinitialize the pin
62+
*/
63+
virtual ~DigitalInOut()
64+
{
65+
gpio_free(&gpio);
66+
}
67+
6168
/** Set the output, specified as 0 or 1 (int)
6269
*
6370
* @param value An integer specifying the pin output value,
6471
* 0 for logical 0, 1 (or any other non-zero value) for logical 1
6572
*/
66-
void write(int value)
73+
virtual void write(int value)
6774
{
6875
// Thread safe / atomic HAL call
6976
gpio_write(&gpio, value);
@@ -75,33 +82,33 @@ class DigitalInOut {
7582
* an integer representing the output setting of the pin if it is an output,
7683
* or read the input if set as an input
7784
*/
78-
int read()
85+
virtual int read()
7986
{
8087
// Thread safe / atomic HAL call
8188
return gpio_read(&gpio);
8289
}
8390

8491
/** Set as an output
8592
*/
86-
void output();
93+
virtual void output();
8794

8895
/** Set as an input
8996
*/
90-
void input();
97+
virtual void input();
9198

9299
/** Set the input pin mode
93100
*
94101
* @param pull PullUp, PullDown, PullNone, OpenDrain
95102
*/
96-
void mode(PinMode pull);
103+
virtual void mode(PinMode pull);
97104

98105
/** Return the output setting, represented as 0 or 1 (int)
99106
*
100107
* @returns
101108
* Non zero value if pin is connected to uc GPIO
102109
* 0 if gpio object was initialized with NC
103110
*/
104-
int is_connected()
111+
virtual int is_connected()
105112
{
106113
// Thread safe / atomic HAL call
107114
return gpio_is_connected(&gpio);

drivers/DigitalOut.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,19 @@ class DigitalOut {
7070
gpio_init_out_ex(&gpio, pin, value);
7171
}
7272

73+
/** Class destructor, deinitialize the pin
74+
*/
75+
virtual ~DigitalOut()
76+
{
77+
gpio_free(&gpio);
78+
}
79+
7380
/** Set the output, specified as 0 or 1 (int)
7481
*
7582
* @param value An integer specifying the pin output value,
7683
* 0 for logical 0, 1 (or any other non-zero value) for logical 1
7784
*/
78-
void write(int value)
85+
virtual void write(int value)
7986
{
8087
// Thread safe / atomic HAL call
8188
gpio_write(&gpio, value);
@@ -87,7 +94,7 @@ class DigitalOut {
8794
* an integer representing the output setting of the pin,
8895
* 0 for logical 0, 1 for logical 1
8996
*/
90-
int read()
97+
virtual int read()
9198
{
9299
// Thread safe / atomic HAL call
93100
return gpio_read(&gpio);
@@ -99,7 +106,7 @@ class DigitalOut {
99106
* Non zero value if pin is connected to uc GPIO
100107
* 0 if gpio object was initialized with NC
101108
*/
102-
int is_connected()
109+
virtual int is_connected()
103110
{
104111
// Thread safe / atomic HAL call
105112
return gpio_is_connected(&gpio);

0 commit comments

Comments
 (0)