Skip to content

Commit

Permalink
Cleanup SD stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
justcallmekoko committed Aug 26, 2020
1 parent c7cf1e0 commit f86b5a4
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 43 deletions.
2 changes: 1 addition & 1 deletion esp32_marauder/Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Display
TFT_eSPI tft = TFT_eSPI();
TFT_eSprite img = TFT_eSprite(&tft);
TFT_eSPI_Button key[BUTTON_ARRAY_LEN];
String version_number = "v0.7.0";
String version_number = "v0.7.1";

bool printing = false;
bool loading = false;
Expand Down
2 changes: 1 addition & 1 deletion esp32_marauder/MenuFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ void MenuFunctions::RunSetup()
WiFi.softAPdisconnect(true);
web_obj.shutdownServer();
});
//addNodes(&updateMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF; changeMenu(updateMenu.parentMenu);});
addNodes(&updateMenu, "Back", TFT_LIGHTGREY, NULL, 0, [this](){wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF; changeMenu(updateMenu.parentMenu);});

// Failed update menu
failedUpdateMenu.parentMenu = &whichUpdateMenu;
Expand Down
40 changes: 37 additions & 3 deletions esp32_marauder/SDInterface.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,41 @@
#include "SDInterface.h"

bool SDInterface::startSD() {
Serial.println("Starting SD card...");
if (SD.begin(SD_CS)) {
buffer_obj = Buffer();
this->sd_running = true;
return true;
}
else {
//delete &buffer_obj;
//buffer_obj = NULL;
this->sd_running = false;
return false;
}
}

bool SDInterface::stopSD() {
Serial.println("Stopping SD card");
//delete &buffer_obj;
//buffer_obj = NULL;
this->sd_running = false;
SD.end();
}

bool SDInterface::initSD() {
String display_string = "";

if (!SD.begin(SD_CS)) {
if (!this->startSD()) {
Serial.println("Failed to mount SD Card");
this->supported = false;
this->stopSD();
return false;
}
// else {
// SD.end(); // Release memory used for SD
// return false;
// }
else {
this->supported = true;
this->cardType = SD.cardType();
Expand Down Expand Up @@ -47,10 +75,13 @@ bool SDInterface::initSD() {
this->card_sz = sz;
}

buffer_obj = Buffer();
//buffer_obj = Buffer();

//if (this->supported)
// buffer_obj.open(&SD);

// Clean up the SD
this->stopSD();

return true;
}
Expand All @@ -69,6 +100,7 @@ void SDInterface::openCapture(String file_name) {
}

void SDInterface::runUpdate() {
this->startSD();
//display_obj.clearScreen();
display_obj.tft.setTextWrap(false);
display_obj.tft.setFreeFont(NULL);
Expand Down Expand Up @@ -104,6 +136,8 @@ void SDInterface::runUpdate() {
}

updateBin.close();

this->stopSD();

// whe finished remove the binary from sd card to indicate end of the process
display_obj.tft.println("rebooting...");
Expand Down Expand Up @@ -160,7 +194,7 @@ void SDInterface::performUpdate(Stream &updateSource, size_t updateSize) {
}

void SDInterface::main() {
if ((this->supported) && (this->do_save)) {
if ((this->supported) && (this->do_save) && (this->sd_running)) {
//Serial.println("Saving packet...");
buffer_obj.forceSave(&SD);
}
Expand Down
3 changes: 3 additions & 0 deletions esp32_marauder/SDInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ extern Display display_obj;
class SDInterface {

private:
bool sd_running = false;

public:
uint8_t cardType;
Expand All @@ -28,6 +29,8 @@ class SDInterface {

bool initSD();

bool stopSD();
bool startSD();
void addPacket(uint8_t* buf, uint32_t len);
void openCapture(String file_name = "");
void runUpdate();
Expand Down

0 comments on commit f86b5a4

Please sign in to comment.