diff --git a/examples/nRF24/nRF24_Receive_Interrupt/nRF24_Receive_Interrupt.ino b/examples/nRF24/nRF24_Receive_Interrupt/nRF24_Receive_Interrupt.ino index ccca2798..c41bb2b8 100644 --- a/examples/nRF24/nRF24_Receive_Interrupt/nRF24_Receive_Interrupt.ino +++ b/examples/nRF24/nRF24_Receive_Interrupt/nRF24_Receive_Interrupt.ino @@ -61,7 +61,7 @@ void setup() { // set the function that will be called // when new packet is received - radio.setIrqAction(setFlag); + radio.setPacketReceivedAction(setFlag); // start listening Serial.print(F("[nRF24] Starting to listen ... ")); diff --git a/examples/nRF24/nRF24_Transmit_Interrupt/nRF24_Transmit_Interrupt.ino b/examples/nRF24/nRF24_Transmit_Interrupt/nRF24_Transmit_Interrupt.ino index cdcbf997..05398fc4 100644 --- a/examples/nRF24/nRF24_Transmit_Interrupt/nRF24_Transmit_Interrupt.ino +++ b/examples/nRF24/nRF24_Transmit_Interrupt/nRF24_Transmit_Interrupt.ino @@ -63,7 +63,7 @@ void setup() { // set the function that will be called // when packet transmission is finished - radio.setIrqAction(setFlag); + radio.setPacketSentAction(setFlag); // start transmitting the first packet Serial.print(F("[nRF24] Sending first packet ... ")); diff --git a/src/modules/nRF24/nRF24.cpp b/src/modules/nRF24/nRF24.cpp index 62cb2c2d..3257187b 100644 --- a/src/modules/nRF24/nRF24.cpp +++ b/src/modules/nRF24/nRF24.cpp @@ -159,6 +159,26 @@ void nRF24::setIrqAction(void (*func)(void)) { this->mod->hal->attachInterrupt(this->mod->hal->pinToInterrupt(this->mod->getIrq()), func, this->mod->hal->GpioInterruptFalling); } +void nRF24::clearIrqAction() { + this->mod->hal->detachInterrupt(this->mod->hal->pinToInterrupt(this->mod->getIrq())); +} + +void nRF24::setPacketReceivedAction(void (*func)(void)) { + this->setIrqAction(func); +} + +void nRF24::clearPacketReceivedAction() { + this->clearIrqAction(); +} + +void nRF24::setPacketSentAction(void (*func)(void)) { + this->setIrqAction(func); +} + +void nRF24::clearPacketSentAction() { + this->clearIrqAction(); +} + int16_t nRF24::startTransmit(uint8_t* data, size_t len, uint8_t addr) { // suppress unused variable warning (void)addr; diff --git a/src/modules/nRF24/nRF24.h b/src/modules/nRF24/nRF24.h index e94a7421..22a161ef 100644 --- a/src/modules/nRF24/nRF24.h +++ b/src/modules/nRF24/nRF24.h @@ -272,6 +272,33 @@ class nRF24: public PhysicalLayer { */ void setIrqAction(void (*func)(void)); + /*! + \brief Clears interrupt service routine . + */ + void clearIrqAction(); + + /*! + \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 Interrupt-driven binary transmit method. IRQ will be activated when full packet is transmitted. Overloads for string-based transmissions are implemented in PhysicalLayer.