| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#ifndef __SD_H__ |
| 16 |
#define __SD_H__ |
| 17 |
|
| 18 |
#include <Arduino.h> |
| 19 |
|
| 20 |
#include <utility/SdFat.h> |
| 21 |
#include <utility/SdFatUtil.h> |
| 22 |
|
| 23 |
#define FILE_READ O_READ |
| 24 |
#define FILE_WRITE (O_READ | O_WRITE | O_CREAT) |
| 25 |
|
| 26 |
namespace SDLib { |
| 27 |
|
| 28 |
class File : public Stream { |
| 29 |
private: |
| 30 |
char _name[13]; |
| 31 |
SdFile *_file; |
| 32 |
|
| 33 |
public: |
| 34 |
File(SdFile f, const char *name); |
| 35 |
File(void); |
| 36 |
virtual size_t write(uint8_t); |
| 37 |
virtual size_t write(const uint8_t *buf, size_t size); |
| 38 |
virtual int read(); |
| 39 |
virtual int peek(); |
| 40 |
virtual int available(); |
| 41 |
virtual void flush(); |
| 42 |
int read(void *buf, uint16_t nbyte); |
| 43 |
boolean seek(uint32_t pos); |
| 44 |
uint32_t position(); |
| 45 |
uint32_t size(); |
| 46 |
void close(); |
| 47 |
operator bool(); |
| 48 |
char * name(); |
| 49 |
|
| 50 |
boolean isDirectory(void); |
| 51 |
File openNextFile(uint8_t mode = O_RDONLY); |
| 52 |
void rewindDirectory(void); |
| 53 |
|
| 54 |
using Print::write; |
| 55 |
}; |
| 56 |
|
| 57 |
class SDClass { |
| 58 |
|
| 59 |
private: |
| 60 |
|
| 61 |
Sd2Card card; |
| 62 |
SdVolume volume; |
| 63 |
SdFile root; |
| 64 |
|
| 65 |
|
| 66 |
SdFile getParentDir(const char *filepath, int *indx); |
| 67 |
public: |
| 68 |
|
| 69 |
|
| 70 |
boolean begin(uint8_t csPin = SD_CHIP_SELECT_PIN); |
| 71 |
boolean begin(uint32_t clock, uint8_t csPin); |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
File open(const char *filename, uint8_t mode = FILE_READ); |
| 77 |
File open(const String &filename, uint8_t mode = FILE_READ) { return open( filename.c_str(), mode ); } |
| 78 |
|
| 79 |
|
| 80 |
boolean exists(const char *filepath); |
| 81 |
boolean exists(const String &filepath) { return exists(filepath.c_str()); } |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
boolean mkdir(const char *filepath); |
| 86 |
boolean mkdir(const String &filepath) { return mkdir(filepath.c_str()); } |
| 87 |
|
| 88 |
|
| 89 |
boolean remove(const char *filepath); |
| 90 |
boolean remove(const String &filepath) { return remove(filepath.c_str()); } |
| 91 |
|
| 92 |
boolean rmdir(const char *filepath); |
| 93 |
boolean rmdir(const String &filepath) { return rmdir(filepath.c_str()); } |
| 94 |
|
| 95 |
private: |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
int fileOpenMode; |
| 103 |
|
| 104 |
friend class File; |
| 105 |
friend boolean callback_openPath(SdFile&, const char *, boolean, void *); |
| 106 |
}; |
| 107 |
|
| 108 |
extern SDClass SD; |
| 109 |
|
| 110 |
}; |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
using namespace SDLib; |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
typedef SDLib::File SDFile; |
| 121 |
typedef SDLib::SDClass SDFileSystemClass; |
| 122 |
#define SDFileSystem SDLib::SD |
| 123 |
|
| 124 |
#endif |