Skip to content

Commit

Permalink
DigitalIn args on callback function
Browse files Browse the repository at this point in the history
  • Loading branch information
cotestatnt committed Aug 22, 2023
1 parent f2cc75d commit 9ceed8b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=DigitalSignalsArduino
version=0.0.4
version=0.0.5
author=Tolentino Cotesta <[email protected]>
maintainer=Tolentino Cotesta <[email protected]>
sentence=Arduino Digital Signal library
Expand Down
6 changes: 3 additions & 3 deletions src/DigitalIn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ uint8_t DigitalIn::update() {

if (!m_pressEdge && fn_press != nullptr && m_pressedDuration > m_bounceTime) {
m_pressEdge = true;
fn_press();
fn_press(this);
}
}
else {
m_pressEdge = false;
if (fn_release != nullptr && m_pressedDuration > m_bounceTime) {
fn_release();
fn_release(this);
}

if (m_pressedDuration > m_longClickTime) {
Expand Down Expand Up @@ -99,4 +99,4 @@ bool DigitalIn::longClick(bool waitRelease) {
return m_fsmState == LONG_CLICK;
else
return m_fsmState == PRESSED;
}
}
7 changes: 6 additions & 1 deletion src/DigitalIn.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
typedef int IOPinName;
typedef int IOPinMode;

typedef void(*function_cb)();
typedef void(*function_cb)(void*);


/** A digital input, used for reading the state of a pin
Expand Down Expand Up @@ -92,6 +92,11 @@ class DigitalIn {
update();
return isActive() && m_pressedDuration > m_bounceTime;
}

/** Get assigned GPIO number */
int getPin() {
return m_pin;
}
};


Expand Down
10 changes: 5 additions & 5 deletions src/DigitalOut.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Output {
enum class OutType {SR, TOFF, TON, TON_M, BLINK};
}

typedef void(*function_cb)();
typedef void(*function_out_cb)();

using Output::OutType;

Expand Down Expand Up @@ -43,8 +43,8 @@ class DigitalOut
// Set output state
void write(bool val);

function_cb fn_rise = nullptr;
function_cb fn_fall = nullptr;
function_out_cb fn_rise = nullptr;
function_out_cb fn_fall = nullptr;

public:
DigitalOut(OutType type, uint32_t time = 0);
Expand Down Expand Up @@ -80,11 +80,11 @@ class DigitalOut
write(value);
}

inline void onRising(function_cb fn) {
inline void onRising(function_out_cb fn) {
fn_rise = fn;
}

inline void onFalling(function_cb fn) {
inline void onFalling(function_out_cb fn) {
fn_fall = fn;
}

Expand Down

0 comments on commit 9ceed8b

Please sign in to comment.