diff --git a/examples/SX127x/SX127x_Receive_Interrupt/SX127x_Receive_Interrupt.ino b/examples/SX127x/SX127x_Receive_Interrupt/SX127x_Receive_Interrupt.ino index 02cb5b09..76c641d3 100644 --- a/examples/SX127x/SX127x_Receive_Interrupt/SX127x_Receive_Interrupt.ino +++ b/examples/SX127x/SX127x_Receive_Interrupt/SX127x_Receive_Interrupt.ino @@ -51,7 +51,7 @@ void setup() { // set the function that will be called // when new packet is received - radio.setDio0Action(setFlag, RISING); + radio.setPacketReceivedAction(setFlag); // start listening for LoRa packets Serial.print(F("[SX1278] Starting to listen ... ")); diff --git a/examples/SX127x/SX127x_Transmit_Interrupt/SX127x_Transmit_Interrupt.ino b/examples/SX127x/SX127x_Transmit_Interrupt/SX127x_Transmit_Interrupt.ino index 6d60cd72..b0551083 100644 --- a/examples/SX127x/SX127x_Transmit_Interrupt/SX127x_Transmit_Interrupt.ino +++ b/examples/SX127x/SX127x_Transmit_Interrupt/SX127x_Transmit_Interrupt.ino @@ -50,7 +50,7 @@ void setup() { // set the function that will be called // when packet transmission is finished - radio.setDio0Action(setFlag, RISING); + radio.setPacketSentAction(setFlag); // start transmitting the first packet Serial.print(F("[SX1278] Sending first packet ... ")); diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index 9b8202be..679681f4 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -452,6 +452,22 @@ void SX127x::clearDio1Action() { this->mod->hal->detachInterrupt(this->mod->hal->pinToInterrupt(this->mod->getGpio())); } +void SX127x::setPacketReceivedAction(void (*func)(void)) { + this->setDio0Action(func, RISING); +} + +void SX127x::clearPacketReceivedAction() { + this->clearDio0Action(); +} + +void SX127x::setPacketSentAction(void (*func)(void)) { + this->setDio0Action(func, RISING); +} + +void SX127x::clearPacketSentAction() { + this->clearDio0Action(); +} + void SX127x::setFifoEmptyAction(void (*func)(void)) { // set DIO1 to the FIFO empty event (the register setting is done in startTransmit) setDio1Action(func, this->mod->hal->GpioInterruptRising); diff --git a/src/modules/SX127x/SX127x.h b/src/modules/SX127x/SX127x.h index e738f844..951ee31b 100644 --- a/src/modules/SX127x/SX127x.h +++ b/src/modules/SX127x/SX127x.h @@ -716,6 +716,28 @@ class SX127x: public PhysicalLayer { */ void clearDio1Action(); + /*! + \brief Sets interrupt service routine to call when a packet is received. + \param func ISR to call. + */ + void setPacketReceivedAction(void (*func)(void)); + + /*! + \brief Clears interrupt service routine to call when a packet is received. + */ + void clearPacketReceivedAction(); + + /*! + \brief Sets interrupt service routine to call when a packet is sent. + \param func ISR to call. + */ + void setPacketSentAction(void (*func)(void)); + + /*! + \brief Clears interrupt service routine to call when a packet is sent. + */ + void clearPacketSentAction(); + /*! \brief Set interrupt service routine function to call when FIFO is empty. \param func Pointer to interrupt service routine.