This commit is contained in:
Simon Weidacher
2021-12-26 14:00:30 +01:00
parent 13bd2051ad
commit 93cced767f
2 changed files with 12 additions and 0 deletions

View File

@@ -4,12 +4,14 @@
#include <esp_err.h>
#include <esp_http_server.h>
#include <stdio.h>
#include <functional>
#include "WebInterface.hpp"
static const char* TAG = "rfid";
static char* lastTagId = (char*)malloc(26 * sizeof(char));
static std::function<void(char*)> 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<void(char*)> cb) {
callback = cb;
}

View File

@@ -2,6 +2,7 @@
#define _RFID_INTERFACE_HPP
#include <rc522.h>
#include <functional>
#include "WebInterface.hpp"
class RFIDInterface {
@@ -11,6 +12,7 @@ class RFIDInterface {
RFIDInterface();
void start();
void registerWebResources(WebInterface* interface);
void registerTagChangeCallback(std::function<void(char*)>);
};
#endif