diff --git a/include/RFPowerView.h b/include/RFPowerView.h index 5c655e8..63f1b9c 100644 --- a/include/RFPowerView.h +++ b/include/RFPowerView.h @@ -23,7 +23,10 @@ public: bool begin(); void loop(); - void setPacketCallback(std::function callback); + void setPacketReceivedCallback(std::function callback); + void setValidBufferReceivedCallback(std::function callback); + void setInvalidBufferReceivedCallback(std::function callback); + bool sendPacket(const Packet* packet); private: @@ -34,7 +37,9 @@ private: uint8_t irqPin; uint8_t rfID[2]; - std::function packetCallback; + std::function packetReceivedCallback; + std::function validBufferReceivedCallback; + std::function invalidBufferReceivedCallback; uint8_t sendBuffer[32]; diff --git a/src/RFPowerView.cpp b/src/RFPowerView.cpp index 1828214..fb33ea8 100644 --- a/src/RFPowerView.cpp +++ b/src/RFPowerView.cpp @@ -7,7 +7,9 @@ RFPowerView::RFPowerView(uint8_t cePin, uint8_t csPin, uint8_t irqPin, uint16_t bufferFiller(0x05), irqPin(irqPin), rfID{static_cast(rfID & 0xFF), static_cast(rfID >> 8)}, - packetCallback(nullptr) {} + packetReceivedCallback(nullptr), + validBufferReceivedCallback(nullptr), + invalidBufferReceivedCallback(nullptr) {} bool RFPowerView::begin() { if (!radio.begin()) { @@ -60,21 +62,35 @@ void RFPowerView::interruptHandler() { } void RFPowerView::processBuffer(const uint8_t *buffer) { + if (validBufferReceivedCallback != nullptr) { + validBufferReceivedCallback(buffer); + } + Packet packet; bool result = packetParser.parsePacket(buffer, packet); if (result) { - if (packetCallback != nullptr) { - packetCallback(&packet); + if (packetReceivedCallback != nullptr) { + packetReceivedCallback(&packet); } } } void RFPowerView::processInvalidBuffer(const uint8_t *buffer) { - + if (invalidBufferReceivedCallback != nullptr) { + invalidBufferReceivedCallback(buffer); + } } -void RFPowerView::setPacketCallback(std::function callback) { - packetCallback = callback; +void RFPowerView::setPacketReceivedCallback(std::function callback) { + packetReceivedCallback = callback; +} + +void RFPowerView::setValidBufferReceivedCallback(std::function callback) { + validBufferReceivedCallback = callback; +} + +void RFPowerView::setInvalidBufferReceivedCallback(std::function callback) { + invalidBufferReceivedCallback = callback; } bool RFPowerView::sendPacket(const Packet* packet) {