Skip to content

Commit

Permalink
Merge pull request #20 from bmorcelli/main
Browse files Browse the repository at this point in the history
Fixes and SPIFFS handling
  • Loading branch information
pr3y authored May 19, 2024
2 parents 47afdf3 + 5d629c7 commit b3d874c
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 19 deletions.
Binary file removed Bruce3_Cardputer.bin
Binary file not shown.
Binary file removed Bruce3_cplus1_1.bin
Binary file not shown.
Binary file removed Bruce3_cplus2.bin
Binary file not shown.
4 changes: 2 additions & 2 deletions src/TV-B-Gone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down
4 changes: 2 additions & 2 deletions src/bad_usb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ void drawOptions(int index,const std::vector<std::pair<std::string, std::functio

int i=0;
int init = 0;
int cont = 1;
menuSize = options.size();
if(index>=MAX_MENU_SIZE) init=index-MAX_MENU_SIZE+1;
for(i=0;i<menuSize;i++) {
Expand All @@ -172,9 +173,11 @@ void drawOptions(int index,const std::vector<std::pair<std::string, std::functio
text += String(options[i].first.c_str());
tft.setCursor(WIDTH*0.15+5,tft.getCursorY()+4);
tft.println(text.substring(0,13));
cont++;
}
if(cont>MAX_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);
}
Expand Down
3 changes: 0 additions & 3 deletions src/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions src/evil_portal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -256,21 +259,21 @@ void chooseHtml(bool def) {
ep_logo = "<div class='containerlogo'><svg viewBox='0 0 75 24' width='75' height='24' xmlns='http://www.w3.org/2000/svg' aria-hidden='true' class='BFr46e xduoyf'><g id='qaEJec'><path fill='#ea4335' d='M67.954 16.303c-1.33 0-2.278-.608-2.886-1.804l7.967-3.3-.27-.68c-.495-1.33-2.008-3.79-5.102-3.79-3.068 0-5.622 2.41-5.622 5.96 0 3.34 2.53 5.96 5.92 5.96 2.73 0 4.31-1.67 4.97-2.64l-2.03-1.35c-.673.98-1.6 1.64-2.93 1.64zm-.203-7.27c1.04 0 1.92.52 2.21 1.264l-5.32 2.21c-.06-2.3 1.79-3.474 3.12-3.474z'></path></g><g id='YGlOvc'><path fill='#34a853' d='M58.193.67h2.564v17.44h-2.564z'></path></g><g id='BWfIk'><path fill='#4285f4' d='M54.152 8.066h-.088c-.588-.697-1.716-1.33-3.136-1.33-2.98 0-5.71 2.614-5.71 5.98 0 3.338 2.73 5.933 5.71 5.933 1.42 0 2.548-.64 3.136-1.36h.088v.86c0 2.28-1.217 3.5-3.183 3.5-1.61 0-2.6-1.15-3-2.12l-2.28.94c.65 1.58 2.39 3.52 5.28 3.52 3.06 0 5.66-1.807 5.66-6.206V7.21h-2.48v.858zm-3.006 8.237c-1.804 0-3.318-1.513-3.318-3.588 0-2.1 1.514-3.635 3.318-3.635 1.784 0 3.183 1.534 3.183 3.635 0 2.075-1.4 3.588-3.19 3.588z'></path></g><g id='e6m3fd'><path fill='#fbbc05' d='M38.17 6.735c-3.28 0-5.953 2.506-5.953 5.96 0 3.432 2.673 5.96 5.954 5.96 3.29 0 5.96-2.528 5.96-5.96 0-3.46-2.67-5.96-5.95-5.96zm0 9.568c-1.798 0-3.348-1.487-3.348-3.61 0-2.14 1.55-3.608 3.35-3.608s3.348 1.467 3.348 3.61c0 2.116-1.55 3.608-3.35 3.608z'></path></g><g id='vbkDmc'><path fill='#ea4335' d='M25.17 6.71c-3.28 0-5.954 2.505-5.954 5.958 0 3.433 2.673 5.96 5.954 5.96 3.282 0 5.955-2.527 5.955-5.96 0-3.453-2.673-5.96-5.955-5.96zm0 9.567c-1.8 0-3.35-1.487-3.35-3.61 0-2.14 1.55-3.608 3.35-3.608s3.35 1.46 3.35 3.6c0 2.12-1.55 3.61-3.35 3.61z'></path></g><g id='idEJde'><path fill='#4285f4' d='M14.11 14.182c.722-.723 1.205-1.78 1.387-3.334H9.423V8.373h8.518c.09.452.16 1.07.16 1.664 0 1.903-.52 4.26-2.19 5.934-1.63 1.7-3.71 2.61-6.48 2.61-5.12 0-9.42-4.17-9.42-9.29C0 4.17 4.31 0 9.43 0c2.83 0 4.843 1.108 6.362 2.56L14 4.347c-1.087-1.02-2.56-1.81-4.577-1.81-3.74 0-6.662 3.01-6.662 6.75s2.93 6.75 6.67 6.75c2.43 0 3.81-.972 4.69-1.856z'></path></g></svg></div>";
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);
if(html_file.endsWith(".html")) {
ep_logo = "";
File html = (*fs).open(html_file, FILE_READ);
html_file = html.readString();
html.close();
} else {
html_file = index_GET();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/mykeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -224,6 +224,7 @@ String keyboard(String mytext, int maxSize, String msg) {
delay(150);
redraw = true;
}
if(checkSelPress()) break;

#else
if(checkSelPress()) {
Expand Down
55 changes: 54 additions & 1 deletion src/sd_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/sd_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
String loopSD(FS &fs, bool filePicker = false);
4 changes: 2 additions & 2 deletions src/webInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit b3d874c

Please sign in to comment.