Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fixes #136

Merged
merged 3 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions src/core/sd_functions.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <regex>
#include "globals.h"
#include "sd_functions.h"
#include "mykeyboard.h" // usinf keyboard when calling rename
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()) {
Expand Down
7 changes: 4 additions & 3 deletions src/modules/others/webInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 6 additions & 3 deletions src/modules/rfid/tag_o_matic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -447,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) {
Expand Down
Loading