3 SD - a slightly more friendly wrapper for sdfatlib
5 This library aims to expose a subset of SD card functionality
6 in the form of a higher level "wrapper" object.
8 License: GNU General Public License V3
9 (Because sdfatlib is licensed with this.)
11 (C) Copyright 2010 SparkFun Electronics
24 #include <utility/SdFat.h>
25 #include <utility/SdFatUtil.h>
27 #define FILE_READ O_READ
28 #define FILE_WRITE (O_READ | O_WRITE | O_CREAT)
30 class File : public Stream {
32 char _name[13]; // our name
33 SdFile *_file; // underlying file pointer
36 File(SdFile f, char *name); // wraps an underlying SdFile
37 File(void); // 'empty' constructor
38 ~File(void); // destructor
40 virtual size_t write(uint8_t);
41 virtual size_t write(const char *str);
42 virtual size_t write(const uint8_t *buf, size_t size);
44 virtual void write(uint8_t);
45 virtual void write(const char *str);
46 virtual void write(const uint8_t *buf, size_t size);
50 virtual int available();
52 int read(void *buf, uint16_t nbyte);
53 boolean seek(uint32_t pos);
60 boolean isDirectory(void);
61 File openNextFile(uint8_t mode = O_RDONLY);
62 void rewindDirectory(void);
68 // These are required for initialisation and use of sdfatlib
73 // my quick&dirty iterator, should be replaced
74 SdFile getParentDir(char *filepath, int *indx);
76 // This needs to be called to set up the connection to the SD card
77 // before other methods are used.
78 boolean begin(uint8_t csPin = SD_CHIP_SELECT_PIN, int8_t mosi = -1, int8_t miso = -1, int8_t sck = -1);
80 // Open the specified file/directory with the supplied mode (e.g. read or
81 // write, etc). Returns a File object for interacting with the file.
82 // Note that currently only one file can be open at a time.
83 File open(char *filename, uint8_t mode = FILE_READ);
85 // Methods to determine if the requested file path exists.
86 boolean exists(char *filepath);
88 // Create the requested directory heirarchy--if intermediate directories
89 // do not exist they will be created.
90 boolean mkdir(char *filepath);
93 boolean remove(char *filepath);
95 boolean rmdir(char *filepath);
97 void enableCRC(boolean mode);
101 // This is used to determine the mode used to open a file
102 // it's here because it's the easiest place to pass the
103 // information through the directory walking function. But
104 // it's probably not the best place for it.
105 // It shouldn't be set directly--it is set via the parameters to `open`.
109 friend boolean callback_openPath(SdFile&, char *, boolean, void *);