Enhanced remount process of SD card
This commit is contained in:
+9
-8
@@ -26,12 +26,13 @@ const int SPI_SCK = 18; // BOARD SPECIFIC
|
||||
const int I2S_DOUT = 25; // can be changed on need
|
||||
const int I2S_BLCK = 27; // can be changed on need
|
||||
const int I2S_LRC = 26; // can be changed on need
|
||||
const int sdCardEjectPin = 13; // pin which is used to tell the program to eject the sd card (so that the file system doesn't brake)
|
||||
const int waitOnSDCardEject = 5000; // defines how long to wait (in ms) after the button for SD card eject was pressed (on pin 'sdCardEjectPin'!)
|
||||
const int retrySDMountTreshold = 1000; // defines how long to wait (in ms) to the next try of mounting the sd card
|
||||
const int readyPin = 32; // for an LED that shows if everything started up correctly (SD card mounted, wifi connected, ...)
|
||||
|
||||
// create all needed variables
|
||||
int currentVolume; // variable where current volume (0...21) is stored
|
||||
int sdCardEjectPin = 13; // pin which is used to tell the program to eject the sd card (so that the file system doesn't brake)
|
||||
int restartTresholdOnSDCardEject = 5000; // defines how long to wait (in ms) after the button for SD card eject was pressed (on pin 'sdCardEjectPin'!)
|
||||
int readyPin = 32; // for an LED that shows if everything started up correctly (SD card mounted, wifi connected, ...)
|
||||
Audio audio; // Audio object (for playing audio, decoding mp3, ...)
|
||||
|
||||
void setup() {
|
||||
@@ -43,7 +44,7 @@ void setup() {
|
||||
|
||||
// connect to sd card reader
|
||||
Serial.println("[DEBUG] Connecting to SD-Card reader");
|
||||
while(!setupSD(SD_CS, SPI_MISO, SPI_MOSI, SPI_SCK)) { Serial.println("[DEBUG] Can't connect to SD card reader! Waiting for 1 second..."); delay(1000); }
|
||||
while(!setupSD(SD_CS, SPI_MISO, SPI_MOSI, SPI_SCK)) { Serial.printf("[DEBUG] Can't connect to SD card reader! Waiting for %d milliseconds...\n", retrySDMountTreshold); delay(retrySDMountTreshold); }
|
||||
Serial.println("[DEBUG] Connected to SD-Card reader");
|
||||
|
||||
digitalWrite(readyPin, HIGH); // show that startup is done and everything works fine
|
||||
@@ -54,9 +55,9 @@ void loop() {
|
||||
if(analogRead(sdCardEjectPin) > 4000) { // bigger than 4000: so that it's not affected by a little touch of fingers (4095 is maximum; 0 minimum)
|
||||
SD.end(); // delete SD object and sync its cache to flash
|
||||
digitalWrite(readyPin, LOW); // indicate that SD card can get removed (the ready-LED will go off)
|
||||
Serial.printf("[DEBUG] Unmounting SD-Card and Restarting in %d seconds... ", restartTresholdOnSDCardEject/1000);
|
||||
delay(restartTresholdOnSDCardEject); // wait for a specific amount of time
|
||||
Serial.println("RESTARTING!");
|
||||
ESP.restart();
|
||||
Serial.printf("[DEBUG] Unmounting SD-Card, waiting for %dms and trying to remount (every %d milliseconds)...\n", waitOnSDCardEject, retrySDMountTreshold);
|
||||
delay(waitOnSDCardEject); // wait some time (so that the sd card can be removed!)
|
||||
while(!setupSD(SD_CS, SPI_MISO, SPI_MOSI, SPI_SCK)) delay(retrySDMountTreshold); // remount sd card
|
||||
digitalWrite(readyPin, HIGH); // indicate that everything is ready again
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user