[nRF24] Implemented generic actions

This commit is contained in:
jgromes 2023-06-21 22:11:36 +02:00
parent 8567c77641
commit 291251ea72
4 changed files with 49 additions and 2 deletions

View file

@ -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 ... "));

View file

@ -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 ... "));

View file

@ -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;

View file

@ -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.