From a70377be5b93d70fa1d626aaebb60627ddfe210f Mon Sep 17 00:00:00 2001 From: Rennan Cockles Date: Tue, 6 Aug 2024 21:06:49 -0300 Subject: [PATCH 1/3] format mifare ultralight with ndef standard --- src/modules/rfid/tag_o_matic.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/modules/rfid/tag_o_matic.cpp b/src/modules/rfid/tag_o_matic.cpp index 11eae8f1..e844679a 100644 --- a/src/modules/rfid/tag_o_matic.cpp +++ b/src/modules/rfid/tag_o_matic.cpp @@ -242,8 +242,11 @@ bool TagOMatic::erase_data_blocks() { break; case MFRC522::PICC_TYPE_MIFARE_UL: - // if (!read_data_blocks()) return false; - for (byte i = 4; i < 130; i++) { + // NDEF stardard + blockWriteSuccess = write_mifare_ultralight_data_block(4, "03 00 FE 00"); + if (!blockWriteSuccess) return false; + + for (byte i = 5; i < 130; i++) { blockWriteSuccess = write_mifare_ultralight_data_block(i, "00 00 00 00"); if (!blockWriteSuccess) return false; } From f67e71767ef988d41bfb42ddbf58f53220ca8818 Mon Sep 17 00:00:00 2001 From: Rennan Cockles Date: Tue, 6 Aug 2024 23:36:38 -0300 Subject: [PATCH 2/3] fix webui printing on top of previous screen --- src/modules/others/webInterface.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/modules/others/webInterface.cpp b/src/modules/others/webInterface.cpp index 42ad3ec7..d81e697a 100644 --- a/src/modules/others/webInterface.cpp +++ b/src/modules/others/webInterface.cpp @@ -301,21 +301,21 @@ void configureWebServer() { } }); - + // Route to send an generic command (Tasmota compatible API) https://tasmota.github.io/docs/Commands/#with-web-requests server->on("/cm", HTTP_POST, []() { if (server->hasArg("cmnd")) { String cmnd = server->arg("cmnd"); if( processSerialCommand( cmnd ) ) { setup_gpio(); // temp fix for menu inf. loop - server->send(200, "text/plain", "command " + cmnd + " success"); + server->send(200, "text/plain", "command " + cmnd + " success"); } else { server->send(400, "text/plain", "command failed, check the serial log for details"); } } server->send(400, "text/plain", "http request missing required arg: cmnd"); }); - + // Reinicia o ESP server->on("/reboot", HTTP_GET, []() { if (checkUserWebAuth()) { @@ -472,6 +472,7 @@ void startWebUi(bool mode_ap) { configureWebServer(); + tft.fillScreen(BGCOLOR); tft.fillScreen(BGCOLOR); tft.drawSmoothRoundRect(5,5,5,5,WIDTH-10,HEIGHT-10,ALCOLOR,BGCOLOR); setTftDisplay(0,0,ALCOLOR,FM); From ac212369a1068a91146e14458a24caa1e5849ac2 Mon Sep 17 00:00:00 2001 From: Rennan Cockles Date: Tue, 6 Aug 2024 23:37:36 -0300 Subject: [PATCH 3/3] change readFs to accept multiple extension filters --- src/core/sd_functions.cpp | 40 ++++++++++++++++++++------------ src/modules/rfid/tag_o_matic.cpp | 2 +- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/core/sd_functions.cpp b/src/core/sd_functions.cpp index c0451b25..a45ce332 100644 --- a/src/core/sd_functions.cpp +++ b/src/core/sd_functions.cpp @@ -1,3 +1,4 @@ +#include #include "globals.h" #include "sd_functions.h" #include "mykeyboard.h" // usinf keyboard when calling rename @@ -30,10 +31,10 @@ bool setupSdCard() { sdcardMounted = false; return false; } - + // avoid unnecessary remounting - if(sdcardMounted) return true; - + if(sdcardMounted) return true; + #if TFT_MOSI == SDCARD_MOSI if (!SD.begin(SDCARD_CS)) #else @@ -330,6 +331,15 @@ void sortList(String fileList[][3], int fileListCount) { } while (swapped); } +bool checkExt(String ext, String pattern) { + if (ext == pattern) return true; + + char charArray[pattern.length() + 1]; + pattern.toCharArray(charArray, pattern.length() + 1); + std::regex ext_regex(charArray); + return std::regex_search(ext.c_str(), ext_regex); +} + /*************************************************************************************** ** Function name: sortList ** Description: sort files for name @@ -357,13 +367,13 @@ void readFs(FS fs, String folder, String result[][3], String allowed_ext) { if (!file2.isDirectory()) { String ext = fileName.substring(fileName.lastIndexOf(".") + 1); ext.toUpperCase(); - if (ext.equals("BIN")) { - result[allFilesCount][0] = fileName.substring(fileName.lastIndexOf("/") + 1); - result[allFilesCount][1] = file2.path(); - result[allFilesCount][2] = "file"; - allFilesCount++; - } - else if(allowed_ext=="*" || ext==allowed_ext) { + if (ext.equals("BIN")) { + result[allFilesCount][0] = fileName.substring(fileName.lastIndexOf("/") + 1); + result[allFilesCount][1] = file2.path(); + result[allFilesCount][2] = "file"; + allFilesCount++; + } + else if(allowed_ext=="*" || checkExt(ext, allowed_ext)) { result[allFilesCount][0] = fileName.substring(fileName.lastIndexOf("/") + 1); result[allFilesCount][1] = file2.path(); result[allFilesCount][2] = "file"; @@ -507,23 +517,23 @@ String loopSD(FS &fs, bool filePicker, String allowed_ext) { if(&fs == &LittleFS && sdcardMounted) options.push_back({"Copy->SD", [=]() { copyToFs(LittleFS, SD, fileList[index][1]); }}); // custom file formats commands added in front - if(fileList[index][1].endsWith(".ir")) options.insert(options.begin(), {"IR Tx SpamAll", [&]() { + if(fileList[index][1].endsWith(".ir")) options.insert(options.begin(), {"IR Tx SpamAll", [&]() { delay(200); txIrFile(&fs, fileList[index][1]); }}); - if(fileList[index][1].endsWith(".sub")) options.insert(options.begin(), {"Subghz Tx", [&]() { + if(fileList[index][1].endsWith(".sub")) options.insert(options.begin(), {"Subghz Tx", [&]() { delay(200); txSubFile(&fs, fileList[index][1]); }}); #if defined(USB_as_HID) - if(fileList[index][1].endsWith(".txt")) options.insert(options.begin(), {"BadUSB Run", [&]() { + if(fileList[index][1].endsWith(".txt")) options.insert(options.begin(), {"BadUSB Run", [&]() { Kb.begin(); USB.begin(); key_input(fs, fileList[index][1]); }}); #endif #if defined(HAS_NS4168_SPKR) - if(isAudioFile(fileList[index][1])) options.insert(options.begin(), {"Play Audio", [&]() { + if(isAudioFile(fileList[index][1])) options.insert(options.begin(), {"Play Audio", [&]() { delay(200); playAudioFile(&fs, fileList[index][1]); setup_gpio(); //TODO: remove after fix select loop @@ -618,7 +628,7 @@ void viewFile(FS fs, String filepath) { file = fs.open(filepath, FILE_READ); if (!file) return; - + // TODO: detect binary file, switch to hex view while (file.available()) { diff --git a/src/modules/rfid/tag_o_matic.cpp b/src/modules/rfid/tag_o_matic.cpp index e844679a..9220dff5 100644 --- a/src/modules/rfid/tag_o_matic.cpp +++ b/src/modules/rfid/tag_o_matic.cpp @@ -450,7 +450,7 @@ bool TagOMatic::load_from_file() { if(setupSdCard()) fs=&SD; else fs=&LittleFS; - filepath = loopSD(*fs, true, "RFID"); + filepath = loopSD(*fs, true, "RFID|NFC"); file = fs->open(filepath, FILE_READ); if (!file) {