Skip to content

Commit

Permalink
SD end() method
Browse files Browse the repository at this point in the history
We need call SdFile::close() only if Sd2Card has no errors because SdFile::sync() is called.
  • Loading branch information
sirzeta committed Feb 28, 2018
1 parent 29789b1 commit 748f25b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions libraries/SD/src/SD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions libraries/SD/src/SD.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 748f25b

Please sign in to comment.