mirror of
https://github.com/sweidac/kidsbox.git
synced 2026-10-28 06:52:57 +01:00
Implement full NFC-URL streaming architecture
- 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
This commit is contained in:
19 files changed
+1172
-318
No files matched your search
@@ -10,55 +10,81 @@
|
||||
|
||||
static const char* TAG = "rfid";
|
||||
|
||||
static char* lastTagId = (char*)malloc(26 * sizeof(char));
|
||||
static std::function<void(char*)> callback;
|
||||
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){
|
||||
startConfig = (rc522_start_args_t){
|
||||
.miso_io = 12,
|
||||
.mosi_io = 13,
|
||||
.sck_io = 23,
|
||||
.sda_io = 18,
|
||||
.callback = [](uint8_t* sn) {
|
||||
if (sn == NULL) {
|
||||
ESP_LOGI(TAG, "Tag removed");
|
||||
|
||||
if (callback) {
|
||||
callback(NULL);
|
||||
}
|
||||
} else { // serial number is always 5 bytes long
|
||||
sprintf(lastTagId, "%#x_%#x_%#x_%#x_%#x", sn[0], sn[1], sn[2], sn[3], sn[4]);
|
||||
ESP_LOGI(TAG, "tag id: %s", lastTagId);
|
||||
|
||||
if (callback) {
|
||||
callback(getLastTagId());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
.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);
|
||||
rc522_start(startConfig);
|
||||
}
|
||||
|
||||
void RFIDInterface::registerWebResources(WebInterface* interface) {
|
||||
httpd_uri_t config = {
|
||||
.uri = "/rfid",
|
||||
.method = HTTP_GET,
|
||||
.handler = [](httpd_req_t *req) {
|
||||
.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) {
|
||||
callback = cb;
|
||||
}
|
||||
legacyCallback = cb;
|
||||
}
|
||||
Reference in new issue
Block a user