diff --git a/RFM69.cpp b/RFM69.cpp index aac4530..b3bc30d 100644 --- a/RFM69.cpp +++ b/RFM69.cpp @@ -37,8 +37,10 @@ uint8_t RFM69::ACK_REQUESTED; uint8_t RFM69::ACK_RECEIVED; // should be polled immediately after sending a packet with ACK request int16_t RFM69::RSSI; // most accurate RSSI during reception (closest to the reception) volatile bool RFM69::_haveData; +RFM69 *RFM69::_instance = nullptr; RFM69::RFM69(uint8_t slaveSelectPin, uint8_t interruptPin, bool isRFM69HW_HCW, SPIClass *spi) { + _instance = this; _slaveSelectPin = slaveSelectPin; _interruptPin = interruptPin; _mode = RF69_MODE_STANDBY; @@ -227,6 +229,12 @@ void RFM69::setNetwork(uint8_t networkID) writeReg(REG_SYNCVALUE2, networkID); } +//set user's ISR callback +void RFM69::setIsrCallback(void (*callback)()) +{ + _isrCallback = callback; +} + // Control transmitter output power (this is NOT a dBm value!) // the power configurations are explained in the SX1231H datasheet (Table 10 on p21; RegPaLevel p66): http://www.semtech.com/images/datasheet/sx1231h.pdf // valid powerLevel parameter values are 0-31 and result in a directly proportional effect on the output/transmission power @@ -446,7 +454,11 @@ void RFM69::interruptHandler() { } // internal function -ISR_PREFIX void RFM69::isr0() { _haveData = true; } +ISR_PREFIX void RFM69::isr0() { + _haveData = true; + if (_instance->_isrCallback) + _instance->_isrCallback(); +} // internal function void RFM69::receiveBegin() { diff --git a/RFM69.h b/RFM69.h index 491fa7e..c5f029c 100644 --- a/RFM69.h +++ b/RFM69.h @@ -203,6 +203,7 @@ class RFM69 { bool initialize(uint8_t freqBand, uint16_t ID, uint8_t networkID=1); void setAddress(uint16_t addr); void setNetwork(uint8_t networkID); + void setIsrCallback(void (*callback)()); virtual bool canSend(); virtual void send(uint16_t toAddress, const void* buffer, uint8_t bufferSize, bool requestACK=false); virtual bool sendWithRetry(uint16_t toAddress, const void* buffer, uint8_t bufferSize, uint8_t retries=2, uint8_t retryWaitTime=RFM69_ACK_TIMEOUT); @@ -247,6 +248,7 @@ class RFM69 { void interruptHandler(); virtual void interruptHook(uint8_t CTLbyte __attribute__((unused))) {}; static volatile bool _haveData; + static RFM69 *_instance; virtual void sendFrame(uint16_t toAddress, const void* buffer, uint8_t size, bool requestACK=false, bool sendACK=false); // for ListenMode sleep/timer @@ -260,6 +262,7 @@ class RFM69 { uint8_t _powerLevel; bool _isRFM69HW; SPIClass *_spi; + void (*_isrCallback)() = nullptr; #if defined (SPCR) && defined (SPSR) uint8_t _SPCR; uint8_t _SPSR;