Skip to content

Commit 318d460

Browse files
authored
Merge pull request #1 from artemen/onError-callback
onError callback
2 parents 26640bc + 562b505 commit 318d460

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/LoRa.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ LoRaClass::LoRaClass() :
7171
_packetIndex(0),
7272
_implicitHeaderMode(0),
7373
_onReceive(NULL),
74-
_onTxDone(NULL)
74+
_onTxDone(NULL),
75+
_onError(NULL)
7576
{
7677
// overide Stream timeout value
7778
setTimeout(0);
@@ -385,6 +386,23 @@ void LoRaClass::onTxDone(void(*callback)())
385386
}
386387
}
387388

389+
void LoRaClass::onError(void(*callback)()){
390+
_onError = callback;
391+
392+
if (callback) {
393+
pinMode(_dio0, INPUT);
394+
#ifdef SPI_HAS_NOTUSINGINTERRUPT
395+
SPI.usingInterrupt(digitalPinToInterrupt(_dio0));
396+
#endif
397+
attachInterrupt(digitalPinToInterrupt(_dio0), LoRaClass::onDio0Rise, RISING);
398+
} else {
399+
detachInterrupt(digitalPinToInterrupt(_dio0));
400+
#ifdef SPI_HAS_NOTUSINGINTERRUPT
401+
SPI.notUsingInterrupt(digitalPinToInterrupt(_dio0));
402+
#endif
403+
}
404+
}
405+
388406
void LoRaClass::receive(int size)
389407
{
390408

@@ -684,6 +702,10 @@ void LoRaClass::handleDio0Rise()
684702
_onTxDone();
685703
}
686704
}
705+
} else {
706+
if (_onError) {
707+
_onError();
708+
}
687709
}
688710
}
689711

src/LoRa.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class LoRaClass : public Stream {
5858
#ifndef ARDUINO_SAMD_MKRWAN1300
5959
void onReceive(void(*callback)(int));
6060
void onTxDone(void(*callback)());
61+
void onError(void(*callback)());
6162

6263
void receive(int size = 0);
6364
#endif
@@ -119,6 +120,7 @@ class LoRaClass : public Stream {
119120
int _implicitHeaderMode;
120121
void (*_onReceive)(int);
121122
void (*_onTxDone)();
123+
void (*_onError)();
122124
};
123125

124126
extern LoRaClass LoRa;

0 commit comments

Comments
 (0)