Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions RCSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ const unsigned int RCSwitch::nSeparationLimit = 4300;
// according to discussion on issue #14 it might be more suitable to set the separation
// limit to the same time as the 'low' part of the sync signal for the current protocol.
unsigned int RCSwitch::timings[RCSWITCH_MAX_CHANGES];
pFunc cb = NULL; // callback function pointer storage
#endif

RCSwitch::RCSwitch() {
Expand Down Expand Up @@ -590,6 +591,10 @@ unsigned int* RCSwitch::getReceivedRawdata() {
return RCSwitch::timings;
}

static void RCSwitch::setCallback(pFunc __callback) { // setter function for callback function storage
cb = __callback;
}

/* helper function for the receiveProtocol method */
static inline unsigned int diff(int A, int B) {
return abs(A - B);
Expand Down Expand Up @@ -680,6 +685,8 @@ void RECEIVE_ATTR RCSwitch::handleInterrupt() {
for(unsigned int i = 1; i <= numProto; i++) {
if (receiveProtocol(i, changeCount)) {
// receive succeeded for protocol i
if (cb != NULL) // finally call the callback function
cb();
break;
}
}
Expand Down
5 changes: 5 additions & 0 deletions RCSwitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
// We can handle up to (unsigned long) => 32 bit * 2 H/L changes per bit + 2 for sync
#define RCSWITCH_MAX_CHANGES 67

typedef void (*pFunc)(); // function Pointer for functions like --> void foo() {...}, no return value, no arguments

class RCSwitch {

public:
Expand Down Expand Up @@ -92,6 +94,9 @@ class RCSwitch {
unsigned int getReceivedDelay();
unsigned int getReceivedProtocol();
unsigned int* getReceivedRawdata();

static void setCallback(pFunc __callback); // member function declaration for setting the callback function

#endif

void enableTransmit(int nTransmitterPin);
Expand Down