diff --git a/Bruce3_Cardputer.bin b/Bruce3_Cardputer.bin deleted file mode 100644 index b4358806..00000000 Binary files a/Bruce3_Cardputer.bin and /dev/null differ diff --git a/Bruce3_cplus1_1.bin b/Bruce3_cplus1_1.bin deleted file mode 100644 index 41ab08ed..00000000 Binary files a/Bruce3_cplus1_1.bin and /dev/null differ diff --git a/Bruce3_cplus2.bin b/Bruce3_cplus2.bin deleted file mode 100644 index 819ad9db..00000000 Binary files a/Bruce3_cplus2.bin and /dev/null differ diff --git a/src/TV-B-Gone.cpp b/src/TV-B-Gone.cpp index 21563873..d79e04b7 100644 --- a/src/TV-B-Gone.cpp +++ b/src/TV-B-Gone.cpp @@ -192,14 +192,14 @@ void otherIRcodes() { int total_codes = 0; int codes_sent = 0; FS *fs; - if(SD.begin()) { + if(setupSdCard()) { bool teste=false; options = { {"SD Card", [&]() { fs=&SD; }}, {"Spiffs", [&]() { fs=&SPIFFS; }}, }; delay(200); - loopOptions(options,false,true,"Radio Frequency"); + loopOptions(options); } else fs=&SPIFFS; diff --git a/src/bad_usb.cpp b/src/bad_usb.cpp index 2900dcc9..9025a10c 100644 --- a/src/bad_usb.cpp +++ b/src/bad_usb.cpp @@ -225,14 +225,14 @@ void usb_setup() { bad_script = "/badpayload.txt"; FS *fs; - if(SD.begin()) { + if(setupSdCard()) { bool teste=false; options = { {"SD Card", [&]() { fs=&SD; }}, {"Spiffs", [&]() { fs=&SPIFFS; }}, }; delay(200); - loopOptions(options,false,true,"Radio Frequency"); + loopOptions(options); } else fs=&SPIFFS; bad_script = loopSD(*fs,true); diff --git a/src/display.cpp b/src/display.cpp index e63c1518..9266e656 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -162,6 +162,7 @@ void drawOptions(int index,const std::vector=MAX_MENU_SIZE) init=index-MAX_MENU_SIZE+1; for(i=0;iMAX_MENU_SIZE) goto Exit; } - + Exit: if(options.size()>MAX_MENU_SIZE) menuSize = MAX_MENU_SIZE; tft.drawRoundRect(WIDTH*0.15,HEIGHT/2-menuSize*(FM*8+4)/2 -5,WIDTH*0.7,(FM*8+4)*menuSize+10,5,fgcolor); } diff --git a/src/display.h b/src/display.h index ef6598ff..3c526ab9 100644 --- a/src/display.h +++ b/src/display.h @@ -10,9 +10,6 @@ void initDisplay(int i = 0); // Início da função e mostra bootscreen void resetTftDisplay(int x = 0, int y = 0, uint16_t fc = FGCOLOR, int size = FM, uint16_t bg = BGCOLOR, uint16_t screen = BGCOLOR); void setTftDisplay(int x = 0, int y = 0, uint16_t fc = tft.textcolor, int size = tft.textsize, uint16_t bg = tft.textbgcolor); -void resetSpriteDisplay(int x = 0, int y = 0, uint16_t fc = FGCOLOR, int size = FM, uint16_t bg = BGCOLOR, uint16_t screen = BGCOLOR); -void setSpriteDisplay(int x = 0, int y = 0, uint16_t fc = sprite.textcolor, int size = sprite.textsize, uint16_t bg = sprite.textbgcolor); - void displayRedStripe(String text, uint16_t fgcolor = TFT_WHITE, uint16_t bgcolor = TFT_RED); void displayError(String txt); // Faixa vermelha diff --git a/src/evil_portal.cpp b/src/evil_portal.cpp index e589559d..94e29d6a 100644 --- a/src/evil_portal.cpp +++ b/src/evil_portal.cpp @@ -31,7 +31,7 @@ void handleCreds() { saveToCSV("/Bruce_creds.csv", csvLine); capturedCredentialsHtml = html_temp + capturedCredentialsHtml; totalCapturedCredentials++; - ep->send(200, "text/html", getHtmlContents("Por favor, aguarde alguns minutos. Em breve você poderá acessar a internet.")); + ep->send(200, "text/html", getHtmlContents("Please, Wait a few minutes. Soon you'll be able to access internet.")); } void startEvilPortal(String tssid, uint8_t channel, bool deauth) { @@ -183,7 +183,10 @@ void startEvilPortal(String tssid, uint8_t channel, bool deauth) { // Função para salvar dados no arquivo CSV void saveToCSV(const String &filename, const String &csvLine) { - File file = SD.open(filename, FILE_APPEND); + FS *fs; + if(setupSdCard()) fs=&SD; + else fs=&SPIFFS; + File file = (*fs).open(filename, FILE_APPEND); if (!file) { log_i("Error to open file"); return; @@ -256,14 +259,13 @@ void chooseHtml(bool def) { ep_logo = ""; if(def) { FS *fs; - if(SD.begin()) { - bool teste=false; + if(setupSdCard()) { options = { {"SD Card", [&]() { fs=&SD; }}, {"Spiffs", [&]() { fs=&SPIFFS; }}, }; delay(200); - loopOptions(options,false,true,"Radio Frequency"); + loopOptions(options); } else fs=&SPIFFS; html_file = loopSD(*fs,true); @@ -271,6 +273,7 @@ void chooseHtml(bool def) { ep_logo = ""; File html = (*fs).open(html_file, FILE_READ); html_file = html.readString(); + html.close(); } else { html_file = index_GET(); } diff --git a/src/main.cpp b/src/main.cpp index b1b2958e..3a77466c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -95,6 +95,7 @@ void setup() { digitalWrite(4,HIGH); // Keeps the Stick alive after take off the USB cable #else Keyboard.begin(); + pinMode(0, INPUT); pinMode(10, INPUT); // Pin that reads the #endif @@ -151,7 +152,6 @@ void loop() { int index = 0; int opt = 6; // there are 3 options> 1 list SD files, 2 OTA and 3 Config tft.fillRect(0,0,WIDTH,HEIGHT,BGCOLOR); - if(!setupSdCard()) index=1; //if SD card is not present, paint SD square grey and auto select OTA while(1){ if(returnToMenu) { returnToMenu = false; diff --git a/src/mykeyboard.cpp b/src/mykeyboard.cpp index 29d76dab..a1eb0180 100644 --- a/src/mykeyboard.cpp +++ b/src/mykeyboard.cpp @@ -34,7 +34,7 @@ bool checkPrevPress() { bool checkSelPress(){ #if defined (CARDPUTER) Keyboard.update(); - if(Keyboard.isKeyPressed(KEY_ENTER)) + if(Keyboard.isKeyPressed(KEY_ENTER) || digitalRead(0)==LOW) #else if(digitalRead(SEL_BTN)==LOW) #endif @@ -224,6 +224,7 @@ String keyboard(String mytext, int maxSize, String msg) { delay(150); redraw = true; } + if(checkSelPress()) break; #else if(checkSelPress()) { diff --git a/src/sd_functions.cpp b/src/sd_functions.cpp index f6d0f25c..85218b97 100644 --- a/src/sd_functions.cpp +++ b/src/sd_functions.cpp @@ -97,6 +97,54 @@ bool renameFile(FS fs, String path, String filename) { return false; } } +/*************************************************************************************** +** Function name: copyToFs +** Description: copy file from SD or SPIFFS to SPIFFS or SD +***************************************************************************************/ +bool copyToFs(FS from, FS to, String path) { + // Tamanho do buffer para leitura/escrita + const size_t bufferSize = 2048*2; // Ajuste conforme necessário para otimizar a performance + uint8_t buffer[bufferSize]; + bool result; + + if (!SD.begin()) { result = false; displayError("Error 1"); } + if(!SPIFFS.begin()) { result = false; displayError("Error 2"); } + + File source = from.open(path, FILE_READ); + if (!source) { + displayError("Error 3"); + result = false; + } + path = path.substring(path.lastIndexOf('/')); + if(!path.startsWith("/")) path = "/" + path; + File dest = to.open(path, FILE_WRITE); + if (!dest) { + displayError("Error 4"); + result = false; + } + size_t bytesRead; + int tot=source.size(); + int prog=0; + //tft.drawRect(5,HEIGHT-12, (WIDTH-10), 9, FGCOLOR); + while ((bytesRead = source.read(buffer, bufferSize)) > 0) { + if (dest.write(buffer, bytesRead) != bytesRead) { + //Serial.println("Falha ao escrever no arquivo de destino"); + source.close(); + dest.close(); + result = false; + displayError("Error 5"); + } else { + prog+=bytesRead; + float rad = 360*prog/tot; + tft.drawArc(WIDTH/2,HEIGHT/2,HEIGHT/4,HEIGHT/5,0,int(rad),ALCOLOR,BGCOLOR,true); + } + } + if(prog==tot) result = true; + else { result = false; displayError("Error 6"); } + + if(!result) delay(5000); + return result; +} /*************************************************************************************** ** Function name: copyFile @@ -320,7 +368,7 @@ void readFs(FS fs, String folder, String result[][3]) { ** Function: loopSD ** Where you choose what to do with your SD Files **********************************************************************/ -String loopSD(FS fs, bool filePicker) { +String loopSD(FS &fs, bool filePicker) { String result = ""; bool reload=false; bool redraw = true; @@ -330,6 +378,8 @@ String loopSD(FS fs, bool filePicker) { String PreFolder = "/"; tft.fillScreen(BGCOLOR); tft.drawRoundRect(5,5,WIDTH-10,HEIGHT-10,5,FGCOLOR); + closeSdCard(); + setupSdCard(); readFs(fs, Folder, fileList); @@ -415,6 +465,9 @@ String loopSD(FS fs, bool filePicker) { }; if(fileToCopy!="") options.push_back({"Paste", [=]() { pasteFile(fs, Folder); }}); options.push_back({"Delete", [=]() { deleteFromSd(fs, fileList[index][1]); }}); + if(&fs == &SD) options.push_back({"Copy->SPIFFS", [=]() { copyToFs(SD,SPIFFS, fileList[index][1]); }}); + if(&fs == &SPIFFS && sdcardMounted) options.push_back({"Copy->SD", [=]() { copyToFs(SPIFFS, SD, fileList[index][1]); }}); + options.push_back({"Main Menu", [=]() { backToMenu(); }}); delay(200); if(!filePicker) loopOptions(options); diff --git a/src/sd_functions.h b/src/sd_functions.h index 4114fb4b..019ec6fe 100644 --- a/src/sd_functions.h +++ b/src/sd_functions.h @@ -18,6 +18,8 @@ bool renameFile(FS fs, String path, String filename); bool copyFile(FS fs, String path); +bool copyToFs(FS from, FS to, String path); + bool pasteFile(FS fs, String path); bool createFolder(FS fs, String path); @@ -28,4 +30,4 @@ void readFs(FS fs, String folder, String result[][3]); void sortList(String fileList[][3], int fileListCount); -String loopSD(FS fs, bool filePicker = false); \ No newline at end of file +String loopSD(FS &fs, bool filePicker = false); \ No newline at end of file diff --git a/src/webInterface.cpp b/src/webInterface.cpp index 4b7b5d13..34ba0517 100644 --- a/src/webInterface.cpp +++ b/src/webInterface.cpp @@ -192,11 +192,11 @@ void handleFileUpload(FS fs) { if (upload.status == UPLOAD_FILE_START) { if (!filename.startsWith("/")) filename = "/" + filename; if (uploadFolder != "/") filename = uploadFolder + filename; + fs.remove(filename); uploadFile = fs.open(filename, "w"); Serial.println("Upload Start: " + filename); } else if (upload.status == UPLOAD_FILE_WRITE) { - if (uploadFile) - uploadFile.write(upload.buf, sizeof(upload.buf)); + if (uploadFile) uploadFile.write(upload.buf, upload.currentSize); } else if (upload.status == UPLOAD_FILE_END) { if (uploadFile) { uploadFile.close();