Skip to content

onError callback #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2020
Merged
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
24 changes: 23 additions & 1 deletion src/LoRa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ LoRaClass::LoRaClass() :
_packetIndex(0),
_implicitHeaderMode(0),
_onReceive(NULL),
_onTxDone(NULL)
_onTxDone(NULL),
_onError(NULL)
{
// overide Stream timeout value
setTimeout(0);
Expand Down Expand Up @@ -385,6 +386,23 @@ void LoRaClass::onTxDone(void(*callback)())
}
}

void LoRaClass::onError(void(*callback)()){
_onError = callback;

if (callback) {
pinMode(_dio0, INPUT);
#ifdef SPI_HAS_NOTUSINGINTERRUPT
SPI.usingInterrupt(digitalPinToInterrupt(_dio0));
#endif
attachInterrupt(digitalPinToInterrupt(_dio0), LoRaClass::onDio0Rise, RISING);
} else {
detachInterrupt(digitalPinToInterrupt(_dio0));
#ifdef SPI_HAS_NOTUSINGINTERRUPT
SPI.notUsingInterrupt(digitalPinToInterrupt(_dio0));
#endif
}
}

void LoRaClass::receive(int size)
{

Expand Down Expand Up @@ -684,6 +702,10 @@ void LoRaClass::handleDio0Rise()
_onTxDone();
}
}
} else {
if (_onError) {
_onError();
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/LoRa.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class LoRaClass : public Stream {
#ifndef ARDUINO_SAMD_MKRWAN1300
void onReceive(void(*callback)(int));
void onTxDone(void(*callback)());
void onError(void(*callback)());

void receive(int size = 0);
#endif
Expand Down Expand Up @@ -119,6 +120,7 @@ class LoRaClass : public Stream {
int _implicitHeaderMode;
void (*_onReceive)(int);
void (*_onTxDone)();
void (*_onError)();
};

extern LoRaClass LoRa;
Expand Down