From df126c92f90767ccecd1926c4ef13cd7b67936e5 Mon Sep 17 00:00:00 2001
From: jgromes <jan.gromes@gmail.com>
Date: Wed, 21 Jun 2023 22:15:54 +0200
Subject: [PATCH] [RF69] Implemented generic actions

---
 .../RF69_Receive_Interrupt.ino                |  2 +-
 .../RF69_Transmit_Interrupt.ino               |  2 +-
 src/modules/RF69/RF69.cpp                     | 16 ++++++++++++++
 src/modules/RF69/RF69.h                       | 22 +++++++++++++++++++
 4 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/examples/RF69/RF69_Receive_Interrupt/RF69_Receive_Interrupt.ino b/examples/RF69/RF69_Receive_Interrupt/RF69_Receive_Interrupt.ino
index fc2c5804..0a125883 100644
--- a/examples/RF69/RF69_Receive_Interrupt/RF69_Receive_Interrupt.ino
+++ b/examples/RF69/RF69_Receive_Interrupt/RF69_Receive_Interrupt.ino
@@ -41,7 +41,7 @@ void setup() {
 
   // set the function that will be called
   // when new packet is received
-  radio.setDio0Action(setFlag);
+  radio.setPacketReceivedAction(setFlag);
 
   // start listening for packets
   Serial.print(F("[RF69] Starting to listen ... "));
diff --git a/examples/RF69/RF69_Transmit_Interrupt/RF69_Transmit_Interrupt.ino b/examples/RF69/RF69_Transmit_Interrupt/RF69_Transmit_Interrupt.ino
index de73535d..cd29c59c 100644
--- a/examples/RF69/RF69_Transmit_Interrupt/RF69_Transmit_Interrupt.ino
+++ b/examples/RF69/RF69_Transmit_Interrupt/RF69_Transmit_Interrupt.ino
@@ -47,7 +47,7 @@ void setup() {
 
   // set the function that will be called
   // when packet transmission is finished
-  radio.setDio0Action(setFlag);
+  radio.setPacketSentAction(setFlag);
 
   // NOTE: some RF69 modules use high power output,
   //       those are usually marked RF69H(C/CW).
diff --git a/src/modules/RF69/RF69.cpp b/src/modules/RF69/RF69.cpp
index e06b1077..6af30fae 100644
--- a/src/modules/RF69/RF69.cpp
+++ b/src/modules/RF69/RF69.cpp
@@ -294,6 +294,22 @@ void RF69::clearDio1Action() {
   this->mod->hal->detachInterrupt(this->mod->hal->pinToInterrupt(this->mod->getGpio()));
 }
 
+void RF69::setPacketReceivedAction(void (*func)(void)) {
+  this->setDio0Action(func);
+}
+
+void RF69::clearPacketReceivedAction() {
+  this->clearDio0Action();
+}
+
+void RF69::setPacketSentAction(void (*func)(void)) {
+  this->setDio0Action(func);
+}
+
+void RF69::clearPacketSentAction() {
+  this->clearDio0Action();
+}
+
 void RF69::setFifoEmptyAction(void (*func)(void)) {
   // set DIO1 to the FIFO empty event (the register setting is done in startTransmit)
   if(this->mod->getGpio() == RADIOLIB_NC) {
diff --git a/src/modules/RF69/RF69.h b/src/modules/RF69/RF69.h
index 95b0677a..dfe0308f 100644
--- a/src/modules/RF69/RF69.h
+++ b/src/modules/RF69/RF69.h
@@ -617,6 +617,28 @@ class RF69: 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.