Skip to content

Commit 748f25b

Browse files
committed
SD end() method
We need call SdFile::close() only if Sd2Card has no errors because SdFile::sync() is called.
1 parent 29789b1 commit 748f25b

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

Diff for: libraries/SD/src/SD.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,17 @@ boolean SDClass::begin(uint8_t csPin, uint32_t speed) {
350350
root.openRoot(volume);
351351
}
352352

353+
// Ends SD card connection
354+
void SDClass::end() {
355+
if(card.errorCode() == 0 && root.isOpen()) {
356+
root.close();
357+
}
358+
359+
root = SdFile();
360+
volume = SdVolume();
361+
card = Sd2Card();
362+
}
363+
353364
// this little helper is used to traverse paths
354365
SdFile SDClass::getParentDir(const char *filepath, int *index) {
355366
// get parent directory

Diff for: libraries/SD/src/SD.h

+3
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ class SDClass {
8989
// before other methods are used.
9090
boolean begin(uint8_t csPin = SD_CHIP_SELECT_PIN, uint32_t speed = SPI_HALF_SPEED);
9191

92+
// Ends SD card connection
93+
void end();
94+
9295
// Open the specified file/directory with the supplied mode (e.g. read or
9396
// write, etc). Returns a File object for interacting with the file.
9497
// Note that currently only one file can be open at a time.

0 commit comments

Comments
 (0)