Debian Codegraph @

app/testdata/libraries/SD_1.1.1/SD/src/SD.h

raw symbols SCIP
1 /*
2
3 SD - a slightly more friendly wrapper for sdfatlib
4
5 This library aims to expose a subset of SD card functionality
6 in the form of a higher level "wrapper" object.
7
8 License: GNU General Public License V3
9 (Because sdfatlib is licensed with this.)
10
11 (C) Copyright 2010 SparkFun Electronics
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]; // our name
31 SdFile *_file; // underlying file pointer
32
33 public:
34 File(SdFile f, const char *name); // wraps an underlying SdFile
35 File(void); // 'empty' constructor
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 // These are required for initialisation and use of sdfatlib
61 Sd2Card card;
62 SdVolume volume;
63 SdFile root;
64
65 // my quick&dirty iterator, should be replaced
66 SdFile getParentDir(const char *filepath, int *indx);
67 public:
68 // This needs to be called to set up the connection to the SD card
69 // before other methods are used.
70 boolean begin(uint8_t csPin = SD_CHIP_SELECT_PIN);
71 boolean begin(uint32_t clock, uint8_t csPin);
72
73 // Open the specified file/directory with the supplied mode (e.g. read or
74 // write, etc). Returns a File object for interacting with the file.
75 // Note that currently only one file can be open at a time.
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 // Methods to determine if the requested file path exists.
80 boolean exists(const char *filepath);
81 boolean exists(const String &filepath) { return exists(filepath.c_str()); }
82
83 // Create the requested directory heirarchy--if intermediate directories
84 // do not exist they will be created.
85 boolean mkdir(const char *filepath);
86 boolean mkdir(const String &filepath) { return mkdir(filepath.c_str()); }
87
88 // Delete the file.
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 // This is used to determine the mode used to open a file
98 // it's here because it's the easiest place to pass the
99 // information through the directory walking function. But
100 // it's probably not the best place for it.
101 // It shouldn't be set directly--it is set via the parameters to `open`.
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 // We enclose File and SD classes in namespace SDLib to avoid conflicts
113 // with others legacy libraries that redefines File class.
114
115 // This ensure compatibility with sketches that uses only SD library
116 using namespace SDLib;
117
118 // This allows sketches to use SDLib::File with other libraries (in the
119 // sketch you must use SDFile instead of File to disambiguate)
120 typedef SDLib::File SDFile;
121 typedef SDLib::SDClass SDFileSystemClass;
122 #define SDFileSystem SDLib::SD
123
124 #endif