From 748f25b25190be746539a2ed4e2f5ae408537463 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Jos=C3=A9=20Plaza=20de=20los=20Reyes=20Quiroz?= Date: Tue, 27 Feb 2018 18:12:32 -0300 Subject: [PATCH] SD end() method We need call SdFile::close() only if Sd2Card has no errors because SdFile::sync() is called. --- libraries/SD/src/SD.cpp | 11 +++++++++++ libraries/SD/src/SD.h | 3 +++ 2 files changed, 14 insertions(+) diff --git a/libraries/SD/src/SD.cpp b/libraries/SD/src/SD.cpp index ce575128b7..8065da26ee 100644 --- a/libraries/SD/src/SD.cpp +++ b/libraries/SD/src/SD.cpp @@ -350,6 +350,17 @@ boolean SDClass::begin(uint8_t csPin, uint32_t speed) { root.openRoot(volume); } +// Ends SD card connection +void SDClass::end() { + if(card.errorCode() == 0 && root.isOpen()) { + root.close(); + } + + root = SdFile(); + volume = SdVolume(); + card = Sd2Card(); +} + // this little helper is used to traverse paths SdFile SDClass::getParentDir(const char *filepath, int *index) { // get parent directory diff --git a/libraries/SD/src/SD.h b/libraries/SD/src/SD.h index 38ad793598..9864539025 100644 --- a/libraries/SD/src/SD.h +++ b/libraries/SD/src/SD.h @@ -89,6 +89,9 @@ class SDClass { // before other methods are used. boolean begin(uint8_t csPin = SD_CHIP_SELECT_PIN, uint32_t speed = SPI_HALF_SPEED); + // Ends SD card connection + 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.