From 3b2b7c84675500f8ed11cb32677645dfa3528c60 Mon Sep 17 00:00:00 2001 From: Kees Bakker Date: Sat, 30 Sep 2017 21:20:22 +0200 Subject: [PATCH] Add SDClass::end function Call end function to fully de-initialize SD object. Allows you to call SD.begin again to init a new card. This change was taken from Adafruit's SD library. Author: driverblock --- src/SD.cpp | 6 ++++++ src/SD.h | 3 +++ 2 files changed, 9 insertions(+) diff --git a/src/SD.cpp b/src/SD.cpp index 5f4e465..85581c2 100644 --- a/src/SD.cpp +++ b/src/SD.cpp @@ -354,6 +354,12 @@ boolean SDClass::begin(uint32_t clock, uint8_t csPin) { root.openRoot(volume); } +//call this when a card is removed. It will allow you to insert and initialise a new card. +void SDClass::end() +{ + root.close(); +} + // this little helper is used to traverse paths SdFile SDClass::getParentDir(const char *filepath, int *index) { // get parent directory diff --git a/src/SD.h b/src/SD.h index 7f41033..1d36020 100644 --- a/src/SD.h +++ b/src/SD.h @@ -70,6 +70,9 @@ class SDClass { boolean begin(uint8_t csPin = SD_CHIP_SELECT_PIN); boolean begin(uint32_t clock, uint8_t csPin); + //call this when a card is removed. It will allow you to insert and initialise a new card. + void end(); + // Open the specified file/directory with the supplied mode (e.g. read or // write, etc). Returns a File object for interacting with the file. // Note that currently only one file can be open at a time.