Skip to content

Commit 8118764

Browse files
committed
DigitalOut run() refactor
1 parent 9ceed8b commit 8118764

File tree

6 files changed

+234
-222
lines changed

6 files changed

+234
-222
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,18 @@ if (button1.longClick(true)) {
4949
```
5050
Use the callback function for edge transition
5151
```C++
52-
void buttonPressed() {
52+
void buttonPressed(void* arg) {
53+
DigitalIn* btn = (DigitalIn*) arg;
54+
Serial.print("GPIO ");
55+
Serial.print(btn->getPin());
5356
Serial.println("Button pressed");
5457
}
5558

56-
void buttonReleased() {
57-
Serial.println("Button released");
59+
void buttonReleased(void* arg) {
60+
DigitalIn* btn = (DigitalIn*) arg;
61+
Serial.print("GPIO ");
62+
Serial.print(btn->getPin());
63+
Serial.println(" - Button released");
5864
}
5965

6066
void setup() {

library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
name=DigitalSignalsArduino
2-
version=0.0.5
1+
name=DigitalSignals Arduino
2+
version=0.1.0
33
author=Tolentino Cotesta <cotestatnt@yahoo.com>
44
maintainer=Tolentino Cotesta <cotestatnt@yahoo.com>
55
sentence=Arduino Digital Signal library

src/DigitalIn.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ DigitalIn::DigitalIn(IOPinName _pin, IOPinMode _mode, uint32_t _time) {
88
m_shortPressCnt = LONG_CLICK;
99

1010
m_bounceTime = _time;
11-
m_deadTime = 2*m_bounceTime;
11+
m_deadTime = 2 * m_bounceTime;
1212
m_pin = _pin;
1313
m_mode = _mode;
1414
pinMode(m_pin, _mode);
@@ -27,7 +27,7 @@ void DigitalIn::mode(IOPinMode pull) {
2727
pinMode(m_pin, pull);
2828
}
2929

30-
void DigitalIn::setLongClickTime(uint32_t newTime){
30+
void DigitalIn::setLongClickTime(uint32_t newTime) {
3131
m_longClickTime = newTime;
3232
}
3333

src/DigitalIn.h

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ typedef int IOPinMode;
88

99
typedef void(*function_cb)(void*);
1010

11-
12-
/** A digital input, used for reading the state of a pin
11+
/*
12+
A digital input, used for reading the state of a pin
1313
*/
1414
class DigitalIn {
1515

@@ -38,28 +38,32 @@ class DigitalIn {
3838

3939
DigitalIn(IOPinName _pin, IOPinMode _mode = INPUT_PULLUP, uint32_t _time = 70);
4040

41-
void pressCallback(function_cb fn) {onPressed(fn);}
42-
void releaseCallback(function_cb fn) {onReleased(fn);}
41+
void pressCallback(function_cb fn) {
42+
onPressed(fn);
43+
}
44+
void releaseCallback(function_cb fn) {
45+
onReleased(fn);
46+
}
4347

4448
void onPressed(function_cb fn);
4549
void onReleased(function_cb fn);
4650

4751
/** Set the input pin mode
48-
*
49-
* @param pull INPUT, INPUT_PULLUP, OUTPUT
50-
*/
52+
53+
@param pull INPUT, INPUT_PULLUP, OUTPUT
54+
*/
5155
void mode(IOPinMode pull);
5256

5357
/** Set the long click time different from default
54-
*
55-
* @param newTime
56-
*/
58+
59+
@param newTime
60+
*/
5761
void setLongClickTime(uint32_t newTime);
5862

5963
/** Set the double click time different from default
60-
*
61-
* @param newTime
62-
*/
64+
65+
@param newTime
66+
*/
6367
void setDoubleClickTime(uint32_t newTime);
6468

6569
/** Get current status of output */
@@ -75,24 +79,29 @@ class DigitalIn {
7579
bool doubleClick();
7680

7781
/** Check for long click (return true on release confgurable)
78-
*
79-
* @param waitRelease true, false
80-
*/
82+
83+
@param waitRelease true, false
84+
*/
8185
bool longClick(bool waitRelease = false);
8286

8387
/** An operator shorthand for read status
84-
* \sa DigitalIn::read()
85-
* @code
86-
* DigitalIn button(BUTTON1);
87-
* DigitalOut led(LED1);
88-
* led = button; // Equivalent to led.write(button.read())
89-
* @endcode
90-
*/
88+
\sa DigitalIn::read()
89+
@code
90+
DigitalIn button(BUTTON1);
91+
DigitalOut led(LED1);
92+
led = button; // Equivalent to led.write(button.read())
93+
@endcode
94+
*/
9195
operator bool() {
9296
update();
9397
return isActive() && m_pressedDuration > m_bounceTime;
9498
}
9599

100+
operator int() {
101+
update();
102+
return isActive() && m_pressedDuration > m_bounceTime;
103+
}
104+
96105
/** Get assigned GPIO number */
97106
int getPin() {
98107
return m_pin;

0 commit comments

Comments
 (0)