mirror of
https://github.com/sweidac/kidsbox.git
synced 2026-10-27 22:52:57 +01:00
- rc522: add NDEF URL reading via WUPA+cascade anticoll+SELECT+TLV parse
- AudioPlayer: route http:// URIs to esp_player_http_music_play()
- CacheManager: download URLs async to /sdcard/cache/{hash}.{ext}
- TagPlayerControl: NDEF URL → cache-or-stream; fallback to UID local mapping
- RFIDInterface: wire ndef_callback, expose combined uid+url callback
- WebInterface: add /api/info, /api/storage, /api/playback, /api/bluetooth
- BluetoothInterface: stub for A2DP speaker mode
- Networking: WiFi connect with 30s timeout instead of blocking forever
- main.cpp: re-enable WiFi + web server, fix init order, add CacheManager
- www/: full SPA — playback controls, device info, storage, BT pairing
- .gitmodules: switch rc522 submodule URL to HTTPS
https://claude.ai/code/session_01MhAnh68DPNnTjcKqjNYDmk
91 lines
2.3 KiB
C++
91 lines
2.3 KiB
C++
#include "RFIDInterface.hpp"
|
|
|
|
#include <esp_log.h>
|
|
#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[26];
|
|
static std::function<void(char*)> legacyCallback;
|
|
static std::function<void(const char*, const char*)> ndefCallback;
|
|
|
|
static char* getLastTagId() {
|
|
return lastTagId;
|
|
}
|
|
|
|
static void onUidCallback(uint8_t* sn) {
|
|
if(sn == NULL) {
|
|
ESP_LOGI(TAG, "Tag removed");
|
|
lastTagId[0] = '\0';
|
|
if(legacyCallback) legacyCallback(NULL);
|
|
} else {
|
|
snprintf(lastTagId, sizeof(lastTagId),
|
|
"%#x_%#x_%#x_%#x_%#x", sn[0], sn[1], sn[2], sn[3], sn[4]);
|
|
ESP_LOGI(TAG, "Tag UID: %s", lastTagId);
|
|
if(legacyCallback) legacyCallback(lastTagId);
|
|
}
|
|
}
|
|
|
|
static void onNdefCallback(uint8_t* sn, const char* url) {
|
|
if(!ndefCallback) return;
|
|
|
|
if(sn == NULL) {
|
|
ndefCallback(NULL, NULL);
|
|
return;
|
|
}
|
|
|
|
/* Format UID same way as above */
|
|
char uid[26];
|
|
snprintf(uid, sizeof(uid),
|
|
"%#x_%#x_%#x_%#x_%#x", sn[0], sn[1], sn[2], sn[3], sn[4]);
|
|
|
|
if(url) {
|
|
ESP_LOGI(TAG, "NDEF URL on %s: %s", uid, url);
|
|
} else {
|
|
ESP_LOGI(TAG, "No NDEF on %s", uid);
|
|
}
|
|
|
|
ndefCallback(uid, url);
|
|
}
|
|
|
|
RFIDInterface::RFIDInterface() {
|
|
startConfig = (rc522_start_args_t){
|
|
.miso_io = 12,
|
|
.mosi_io = 13,
|
|
.sck_io = 23,
|
|
.sda_io = 18,
|
|
.spi_host_id = (spi_host_device_t)0,
|
|
.callback = onUidCallback,
|
|
.ndef_callback = onNdefCallback,
|
|
};
|
|
}
|
|
|
|
void RFIDInterface::start() {
|
|
rc522_start(startConfig);
|
|
}
|
|
|
|
void RFIDInterface::registerWebResources(WebInterface* interface) {
|
|
httpd_uri_t config = {
|
|
.uri = "/rfid",
|
|
.method = HTTP_GET,
|
|
.handler = [](httpd_req_t* req) {
|
|
httpd_resp_send(req, getLastTagId(), HTTPD_RESP_USE_STRLEN);
|
|
return ESP_OK;
|
|
}
|
|
};
|
|
interface->registerResource(&config);
|
|
}
|
|
|
|
void RFIDInterface::registerTagCallback(std::function<void(const char*, const char*)> cb) {
|
|
ndefCallback = cb;
|
|
}
|
|
|
|
void RFIDInterface::registerTagChangeCallback(std::function<void(char*)> cb) {
|
|
legacyCallback = cb;
|
|
}
|