Skip to content

Moved "using namespac" + added volumesize function #166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/Datalogger/Datalogger.ino
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <SPI.h>
#include <SD.h>

using namespace SDLib;

const int chipSelect = 10;

void setup() {
Expand Down
2 changes: 2 additions & 0 deletions examples/DumpFile/DumpFile.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions examples/Files/Files.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*/
#include <SD.h>

using namespace SDLib;

const int chipSelect = 10;
File myFile;

Expand Down
2 changes: 2 additions & 0 deletions examples/NonBlockingWrite/NonBlockingWrite.ino
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
*/
#include <SD.h>

using namespace SDLib;

const int chipSelect = 10;

// file name to use for writing
Expand Down
2 changes: 2 additions & 0 deletions examples/ReadWrite/ReadWrite.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
*/
#include <SD.h>

using namespace SDLib;

const int chipSelect = 10;
File myFile;

Expand Down
2 changes: 2 additions & 0 deletions examples/listfiles/listfiles.ino
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
*/
#include <SD.h>

using namespace SDLib;

const int chipSelect = 10;
File root;

Expand Down
4 changes: 3 additions & 1 deletion src/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@

*/

#include <SD.h>
#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));
Expand Down
24 changes: 23 additions & 1 deletion src/SD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

*/

#include "SD.h"
#include <SD.h>

namespace SDLib {

Expand Down Expand Up @@ -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();
Expand Down
6 changes: 4 additions & 2 deletions src/SD.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Loading