Skip to content
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

onError callback #329

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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)());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking this should be renamed to something more specific, for example: onCrcError or onReceiveCrcError.

Thoughts?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please name it in accordance with the rest of the repo. No objections.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @artemen if you can address these minor changes I'll merge this PR and include in the next release, which I'd like to get to this week.

Thanks for this contribution, it will add some important insight to error conditions.


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