2010-11-13 19:42:17 +01:00
|
|
|
/*
|
|
|
|
|
2010-11-14 17:48:21 +01:00
|
|
|
SD - a slightly more friendly wrapper for sdfatlib
|
2010-11-13 19:42:17 +01:00
|
|
|
|
|
|
|
This library aims to expose a subset of SD card functionality
|
|
|
|
in the form of a higher level "wrapper" object.
|
|
|
|
|
|
|
|
License: GNU General Public License V3
|
|
|
|
(Because sdfatlib is licensed with this.)
|
|
|
|
|
|
|
|
(C) Copyright 2010 SparkFun Electronics
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2010-11-20 17:01:38 +01:00
|
|
|
#ifndef __SD_H__
|
|
|
|
#define __SD_H__
|
2010-11-13 19:42:17 +01:00
|
|
|
|
|
|
|
#include <WProgram.h>
|
|
|
|
|
2010-11-13 20:01:37 +01:00
|
|
|
#include <utility/SdFat.h>
|
2010-11-13 20:34:49 +01:00
|
|
|
#include <utility/SdFatUtil.h>
|
2010-11-13 19:42:17 +01:00
|
|
|
|
2010-11-14 17:48:21 +01:00
|
|
|
// Use this to configure the chip select pin of the SD card.
|
|
|
|
#define SD_CARD_CHIP_SELECT_PIN 4 // For use with Arduino Ethernet Shield
|
|
|
|
|
2010-11-20 04:30:40 +01:00
|
|
|
class File : public Print {
|
|
|
|
public:
|
|
|
|
virtual void write(uint8_t);
|
|
|
|
virtual void write(const char *str);
|
|
|
|
virtual void write(const uint8_t *buf, size_t size);
|
|
|
|
int read();
|
|
|
|
void close();
|
|
|
|
operator bool();
|
|
|
|
};
|
|
|
|
|
2010-11-13 20:01:37 +01:00
|
|
|
class SDClass {
|
2010-11-13 19:42:17 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
// These are required for initialisation and use of sdfatlib
|
|
|
|
Sd2Card card;
|
|
|
|
SdVolume volume;
|
|
|
|
SdFile root;
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
2010-11-20 17:01:38 +01:00
|
|
|
// This needs to be called to set up the connection to the SD card
|
2010-11-13 19:42:17 +01:00
|
|
|
// before other methods are used.
|
2010-11-14 17:48:21 +01:00
|
|
|
void begin(uint8_t csPin = SD_CARD_CHIP_SELECT_PIN);
|
2010-11-13 19:42:17 +01:00
|
|
|
|
|
|
|
// Open the specified file/directory with the supplied mode (e.g. read or
|
2010-11-20 17:01:38 +01:00
|
|
|
// write, etc). Returns a File object for interacting with the file.
|
|
|
|
// Note that currently only one file can be open at a time.
|
2010-11-20 04:30:40 +01:00
|
|
|
File open(char *filename, boolean write = false, boolean append = true);
|
2010-11-13 19:42:17 +01:00
|
|
|
|
|
|
|
// Methods to determine if the requested file path exists.
|
|
|
|
boolean exists(char *filepath);
|
|
|
|
|
|
|
|
// Create the requested directory heirarchy--if intermediate directories
|
|
|
|
// do not exist they will be created.
|
|
|
|
boolean makeDir(char *filepath);
|
|
|
|
|
2010-11-20 17:01:38 +01:00
|
|
|
private:
|
|
|
|
SdFile file;
|
2010-11-13 19:42:17 +01:00
|
|
|
|
|
|
|
// This is used to determine the mode used to open a file
|
|
|
|
// it's here because it's the easiest place to pass the
|
|
|
|
// information through the directory walking function. But
|
|
|
|
// it's probably not the best place for it.
|
|
|
|
// It shouldn't be set directly--it is set via the parameters to `open`.
|
2010-11-20 17:01:38 +01:00
|
|
|
int fileOpenMode;
|
|
|
|
|
|
|
|
friend class File;
|
|
|
|
friend boolean callback_openPath(SdFile&, char *, boolean, void *);
|
2010-11-13 19:42:17 +01:00
|
|
|
};
|
|
|
|
|
2010-11-13 20:01:37 +01:00
|
|
|
extern SDClass SD;
|
|
|
|
|
2010-11-13 19:42:17 +01:00
|
|
|
#endif
|