Debian Codegraph @

app/testdata/libraries/SD_1.2.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 | O_APPEND)
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 //call this when a card is removed. It will allow you to insert and initialise a new card.
74 void end();
75
76 // Open the specified file/directory with the supplied mode (e.g. read or
77 // write, etc). Returns a File object for interacting with the file.
78 // Note that currently only one file can be open at a time.
79 File open(const char *filename, uint8_t mode = FILE_READ);
80 File open(const String &filename, uint8_t mode = FILE_READ) { return open( filename.c_str(), mode ); }
81
82 // Methods to determine if the requested file path exists.
83 boolean exists(const char *filepath);
84 boolean exists(const String &filepath) { return exists(filepath.c_str()); }
85
86 // Create the requested directory heirarchy--if intermediate directories
87 // do not exist they will be created.
88 boolean mkdir(const char *filepath);
89 boolean mkdir(const String &filepath) { return mkdir(filepath.c_str()); }
90
91 // Delete the file.
92 boolean remove(const char *filepath);
93 boolean remove(const String &filepath) { return remove(filepath.c_str()); }
94
95 boolean rmdir(const char *filepath);
96 boolean rmdir(const String &filepath) { return rmdir(filepath.c_str()); }
97
98 private:
99
100 // This is used to determine the mode used to open a file
101 // it's here because it's the easiest place to pass the
102 // information through the directory walking function. But
103 // it's probably not the best place for it.
104 // It shouldn't be set directly--it is set via the parameters to `open`.
105 int fileOpenMode;
106
107 friend class File;
108 friend boolean callback_openPath(SdFile&, const char *, boolean, void *);
109 };
110
111 extern SDClass SD;
112
113 };
114
115 // We enclose File and SD classes in namespace SDLib to avoid conflicts
116 // with others legacy libraries that redefines File class.
117
118 // This ensure compatibility with sketches that uses only SD library
119 using namespace SDLib;
120
121 // This allows sketches to use SDLib::File with other libraries (in the
122 // sketch you must use SDFile instead of File to disambiguate)
123 typedef SDLib::File SDFile;
124 typedef SDLib::SDClass SDFileSystemClass;
125 #define SDFileSystem SDLib::SD
126
127 #endif