diff --git a/examples/Datalogger/Datalogger.ino b/examples/Datalogger/Datalogger.ino index c5a509c..592ac68 100644 --- a/examples/Datalogger/Datalogger.ino +++ b/examples/Datalogger/Datalogger.ino @@ -26,6 +26,8 @@ #include #include +using namespace SDLib; + const int chipSelect = 10; void setup() { diff --git a/examples/DumpFile/DumpFile.ino b/examples/DumpFile/DumpFile.ino index b6e9944..b6d1305 100644 --- a/examples/DumpFile/DumpFile.ino +++ b/examples/DumpFile/DumpFile.ino @@ -25,6 +25,8 @@ const int chipSelect = 10; +using namespace SDLib; + void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); diff --git a/examples/Files/Files.ino b/examples/Files/Files.ino index 2df0269..64f8b0a 100644 --- a/examples/Files/Files.ino +++ b/examples/Files/Files.ino @@ -21,6 +21,8 @@ */ #include +using namespace SDLib; + const int chipSelect = 10; File myFile; diff --git a/examples/NonBlockingWrite/NonBlockingWrite.ino b/examples/NonBlockingWrite/NonBlockingWrite.ino index 101bfd0..8a21244 100644 --- a/examples/NonBlockingWrite/NonBlockingWrite.ino +++ b/examples/NonBlockingWrite/NonBlockingWrite.ino @@ -33,6 +33,8 @@ */ #include +using namespace SDLib; + const int chipSelect = 10; // file name to use for writing diff --git a/examples/ReadWrite/ReadWrite.ino b/examples/ReadWrite/ReadWrite.ino index b505a27..aecbb35 100644 --- a/examples/ReadWrite/ReadWrite.ino +++ b/examples/ReadWrite/ReadWrite.ino @@ -20,6 +20,8 @@ */ #include +using namespace SDLib; + const int chipSelect = 10; File myFile; diff --git a/examples/listfiles/listfiles.ino b/examples/listfiles/listfiles.ino index ded9b13..1a7be4f 100644 --- a/examples/listfiles/listfiles.ino +++ b/examples/listfiles/listfiles.ino @@ -28,6 +28,8 @@ */ #include +using namespace SDLib; + const int chipSelect = 10; File root; diff --git a/src/File.cpp b/src/File.cpp index 3e27fb4..bf83f91 100644 --- a/src/File.cpp +++ b/src/File.cpp @@ -12,12 +12,14 @@ */ -#include +#include "SD.h" /* for debugging file open/close leaks uint8_t nfilecount=0; */ +using namespace SDLib; + File::File(SdFile f, const char *n) { // oh man you are kidding me, new() doesn't exist? Ok we do it by hand! _file = (SdFile *)malloc(sizeof(SdFile)); diff --git a/src/SD.cpp b/src/SD.cpp index 423db45..5692c14 100644 --- a/src/SD.cpp +++ b/src/SD.cpp @@ -50,7 +50,7 @@ */ -#include "SD.h" +#include namespace SDLib { @@ -366,6 +366,28 @@ namespace SDLib { root.openRoot(volume); } + /** + Get information about the volume size + + @return Returns the volume size in kB of the first volume/partition + */ + uint32_t SDClass::getVolumeSize() + { + uint32_t volumesize = volume.blocksPerCluster(); // clusters are collections of blocks + volumesize *= volume.clusterCount(); // we'll have a lot of clusters + volumesize /= 2; + return (volumesize); //2 blocks make 1kB + } + + /** + Get card type + @return 0:none, 1:SDv1, 2:SDv2, 3:SDHC + */ + uint8_t SDClass::getCardType() + { + return card.type(); + } + //call this when a card is removed. It will allow you to insert and initialise a new card. void SDClass::end() { root.close(); diff --git a/src/SD.h b/src/SD.h index c81a7d3..ea73ad8 100644 --- a/src/SD.h +++ b/src/SD.h @@ -106,6 +106,10 @@ namespace SDLib { return rmdir(filepath.c_str()); } + uint32_t getVolumeSize(); + + uint8_t getCardType(); + private: // This is used to determine the mode used to open a file @@ -126,8 +130,6 @@ namespace SDLib { // We enclose File and SD classes in namespace SDLib to avoid conflicts // with others legacy libraries that redefines File class. -// This ensure compatibility with sketches that uses only SD library -using namespace SDLib; // This allows sketches to use SDLib::File with other libraries (in the // sketch you must use SDFile instead of File to disambiguate)