feat: enhance RFID tag detection with NDEF support and improved error handling
This commit is contained in:
1 parent
775700f90f
commit
9d3a3411fb
1 file changed
+42
-10
+42
-10
@@ -2183,16 +2183,48 @@ void scanRfidTask(void * parameter) {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// UID length != 7, might be a Mifare Classic (Bambu tags)
|
// UID length != 7 — could be Mifare Classic (BambuLab) or non-standard NTAG.
|
||||||
Serial.println("Not a standard NTAG (UID length != 7), trying Bambu Lab tag...");
|
// Try NTAG-style NDEF read first to check for openspool/filaman protocol.
|
||||||
if (!detectBambuTag(uid, uidLength)) {
|
Serial.println("UID length != 7, checking for openspool/filaman protocol first...");
|
||||||
//TBD: Show error here?!
|
activeTagUuid = uidString;
|
||||||
oledShowProgressBar(1, 1, tr(STR_FAILURE), tr(STR_UNKNOWN_TAG_TYPE));
|
|
||||||
oledSetPriority(DISPLAY_PRIORITY_WARNING, 2000);
|
bool handledAsNdef = false;
|
||||||
Serial.println("This doesn't seem to be an NTAG2xx tag (UUID length != 7 bytes)!");
|
uint16_t tagSize = readTagSize();
|
||||||
// Reset activeSpoolId when tag type is unknown to prevent autoSet
|
if (tagSize > 0)
|
||||||
activeSpoolId = "";
|
{
|
||||||
Serial.println("Unknown tag type - activeSpoolId reset to prevent autoSet");
|
uint8_t* data = (uint8_t*)malloc(tagSize);
|
||||||
|
memset(data, 0, tagSize);
|
||||||
|
uint8_t numPages = tagSize / 4;
|
||||||
|
for (uint8_t i = 4; i < 4 + numPages; i++) {
|
||||||
|
if (!robustPageRead(i, data + (i - 4) * 4)) {
|
||||||
|
Serial.printf("Page %d read failed, stopping\n", i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (data[(i - 4) * 4] == 0xFE) {
|
||||||
|
Serial.println("Found NDEF end marker");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
yield();
|
||||||
|
esp_task_wdt_reset();
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(2));
|
||||||
|
}
|
||||||
|
if (decodeNdefAndReturnJson(data, uidString)) {
|
||||||
|
handledAsNdef = true;
|
||||||
|
nfcReaderState = NFC_READ_SUCCESS;
|
||||||
|
}
|
||||||
|
free(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!handledAsNdef)
|
||||||
|
{
|
||||||
|
Serial.println("No NDEF/openspool protocol found, trying Bambu Lab tag...");
|
||||||
|
if (!detectBambuTag(uid, uidLength)) {
|
||||||
|
oledShowProgressBar(1, 1, tr(STR_FAILURE), tr(STR_UNKNOWN_TAG_TYPE));
|
||||||
|
oledSetPriority(DISPLAY_PRIORITY_WARNING, 2000);
|
||||||
|
Serial.println("This doesn't seem to be an NTAG2xx tag (UUID length != 7 bytes)!");
|
||||||
|
activeSpoolId = "";
|
||||||
|
Serial.println("Unknown tag type - activeSpoolId reset to prevent autoSet");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user