diff --git a/device/main/RFIDInterface.cpp b/device/main/RFIDInterface.cpp index 3818345..97d4b83 100644 --- a/device/main/RFIDInterface.cpp +++ b/device/main/RFIDInterface.cpp @@ -4,12 +4,14 @@ #include #include #include +#include #include "WebInterface.hpp" static const char* TAG = "rfid"; static char* lastTagId = (char*)malloc(26 * sizeof(char)); +static std::function callback; static char* getLastTagId() { return lastTagId; @@ -29,6 +31,10 @@ RFIDInterface::RFIDInterface() { sprintf(lastTagId, "%#x_%#x_%#x_%#x_%#x", sn[0], sn[1], sn[2], sn[3], sn[4]); ESP_LOGI(TAG, "sprintf tag id: %s", lastTagId); + + if (callback) { + callback(getLastTagId()); + } } }; } @@ -48,4 +54,8 @@ void RFIDInterface::registerWebResources(WebInterface* interface) { }; interface->registerResource(&config); +} + +void RFIDInterface::registerTagChangeCallback(std::function cb) { + callback = cb; } \ No newline at end of file diff --git a/device/main/RFIDInterface.hpp b/device/main/RFIDInterface.hpp index 4c1bd89..d174967 100644 --- a/device/main/RFIDInterface.hpp +++ b/device/main/RFIDInterface.hpp @@ -2,6 +2,7 @@ #define _RFID_INTERFACE_HPP #include +#include #include "WebInterface.hpp" class RFIDInterface { @@ -11,6 +12,7 @@ class RFIDInterface { RFIDInterface(); void start(); void registerWebResources(WebInterface* interface); + void registerTagChangeCallback(std::function); }; #endif \ No newline at end of file