@@ -14,202 +14,184 @@ class FileSdFatMMC : public SdFile
1414#endif
1515
1616{
17- public:
18- FileSdFatMMC ()
19- {
20- if (USE_SPI_MICROSD)
21- _sdFile = new SdFile;
22- #ifdef COMPILE_SD_MMC
23- else
24- _file = new File;
25- #endif
26- };
17+ public:
2718
28- ~FileSdFatMMC ()
29- {
30- if (USE_SPI_MICROSD)
31- {
32- ;
33- // if (_sdFile) // operator bool
34- // delete _sdFile;
35- }
36- #ifdef COMPILE_SD_MMC
37- else
19+ FileSdFatMMC ()
3820 {
39- ;
40- // if (_file) // operator bool
41- // delete _file;
42- }
43- #endif
44- };
45-
46- operator bool ()
47- {
48- if (USE_SPI_MICROSD)
49- return _sdFile;
21+ if (USE_SPI_MICROSD)
22+ _sdFile = new SdFile;
5023#ifdef COMPILE_SD_MMC
51- else
52- return _file;
24+ else
25+ _file = new File ;
5326#endif
54- return false ; // Keep the compiler happy
55- };
27+ };
5628
57- size_t println (const char printMe[])
58- {
59- if (USE_SPI_MICROSD)
60- return _sdFile->println (printMe);
29+ ~FileSdFatMMC ()
30+ {
31+ if (USE_SPI_MICROSD)
32+ {
33+ ;
34+ // if (_sdFile) // operator bool
35+ // delete _sdFile;
36+ }
6137#ifdef COMPILE_SD_MMC
62- else
63- return _file->println (printMe);
38+ else
39+ {
40+ ;
41+ // if (_file) // operator bool
42+ // delete _file;
43+ }
6444#endif
65- return 0 ; // Keep the compiler happy
66- };
45+ };
6746
68- bool open (const char *filepath, oflag_t mode)
69- {
70- if (USE_SPI_MICROSD)
47+ operator bool ()
7148 {
72- if (_sdFile->open (filepath, mode) == true )
73- return true ;
74- return false ;
75- }
49+ if (USE_SPI_MICROSD)
50+ return _sdFile;
7651#ifdef COMPILE_SD_MMC
77- else
78- {
79- if (mode & O_APPEND)
80- *_file = SD_MMC.open (filepath, FILE_APPEND);
81- else if (mode & O_WRITE)
82- *_file = SD_MMC.open (filepath, FILE_WRITE);
83- else // if (mode & O_READ)
84- *_file = SD_MMC.open (filepath, FILE_READ);
85- if (_file) // operator bool
86- return true ;
87- return false ;
88- }
52+ else
53+ return _file;
8954#endif
90- return false ; // Keep the compiler happy
91- };
55+ };
9256
93- uint32_t size ( )
94- {
95- if (USE_SPI_MICROSD)
96- return _sdFile->size ( );
57+ size_t println ( const char printMe[] )
58+ {
59+ if (USE_SPI_MICROSD)
60+ return _sdFile->println (printMe );
9761#ifdef COMPILE_SD_MMC
98- else
99- return ( uint32_t ) _file->size ( );
62+ else
63+ return _file->println (printMe );
10064#endif
101- return 0 ; // Keep the compiler happy
102- };
65+ };
10366
104- uint32_t fileSize ()
105- {
106- if (USE_SPI_MICROSD)
107- return _sdFile->fileSize ();
67+ bool open (const char *filepath, oflag_t mode)
68+ {
69+ if (USE_SPI_MICROSD)
70+ {
71+ if (_sdFile->open (filepath, mode) == true )
72+ return true ;
73+ return false ;
74+ }
10875#ifdef COMPILE_SD_MMC
109- else
110- return (uint32_t )_file->size ();
76+ else
77+ {
78+ if (mode & O_APPEND)
79+ *_file = SD_MMC.open (filepath, FILE_APPEND);
80+ else if (mode & O_WRITE)
81+ *_file = SD_MMC.open (filepath, FILE_WRITE);
82+ else // if (mode & O_READ)
83+ *_file = SD_MMC.open (filepath, FILE_READ);
84+ if (_file) // operator bool
85+ return true ;
86+ return false ;
87+ }
11188#endif
112- return 0 ; // Keep the compiler happy
113- };
89+ };
11490
115- uint32_t position ()
116- {
117- if (USE_SPI_MICROSD)
118- return _sdFile->position ();
91+ uint32_t size ()
92+ {
93+ if (USE_SPI_MICROSD)
94+ return _sdFile->size ();
11995#ifdef COMPILE_SD_MMC
120- else
121- return ( uint32_t ) _file->position ();
96+ else
97+ return _file->size ();
12298#endif
123- return 0 ; // Keep the compiler happy
124- };
99+ };
125100
126- int available ()
127- {
128- if (USE_SPI_MICROSD)
129- return _sdFile->available ();
101+ uint32_t position ()
102+ {
103+ if (USE_SPI_MICROSD)
104+ return _sdFile->position ();
130105#ifdef COMPILE_SD_MMC
131- else
132- return _file->available ();
106+ else
107+ return _file->position ();
133108#endif
134- return 0 ; // Keep the compiler happy
135- };
109+ };
136110
137- int read ( uint8_t *buf, uint16_t nbyte )
138- {
139- if (USE_SPI_MICROSD)
140- return _sdFile->read (buf, nbyte );
111+ int available ( )
112+ {
113+ if (USE_SPI_MICROSD)
114+ return _sdFile->available ( );
141115#ifdef COMPILE_SD_MMC
142- else
143- return ( int ) _file->read (buf, nbyte );
116+ else
117+ return _file->available ( );
144118#endif
145- return 0 ; // Keep the compiler happy
146- };
119+ };
147120
148- size_t write ( const uint8_t *buf, size_t size )
149- {
150- if (USE_SPI_MICROSD)
151- return _sdFile->write (buf, size );
121+ int read ( uint8_t *buf, uint16_t nbyte )
122+ {
123+ if (USE_SPI_MICROSD)
124+ return _sdFile->read (buf, nbyte );
152125#ifdef COMPILE_SD_MMC
153- else
154- return _file->write (buf, size );
126+ else
127+ return _file->read (buf, nbyte );
155128#endif
156- return 0 ; // Keep the compiler happy
157- };
129+ };
158130
159- void close ( )
160- {
161- if (USE_SPI_MICROSD)
162- _sdFile->close ( );
131+ size_t write ( const uint8_t *buf, size_t size )
132+ {
133+ if (USE_SPI_MICROSD)
134+ return _sdFile->write (buf, size );
163135#ifdef COMPILE_SD_MMC
164- else
165- _file->close ( );
136+ else
137+ return _file->write (buf, size );
166138#endif
167- };
139+ };
168140
169- void flush ()
170- {
171- if (USE_SPI_MICROSD)
172- _sdFile->flush ();
141+ void close ()
142+ {
143+ if (USE_SPI_MICROSD)
144+ _sdFile->close ();
173145#ifdef COMPILE_SD_MMC
174- else
175- _file->flush ();
146+ else
147+ _file->close ();
176148#endif
177- };
149+ };
178150
179- void updateFileAccessTimestamp ()
180- {
181- if (USE_SPI_MICROSD)
151+ void updateFileAccessTimestamp ()
182152 {
183- if (online. rtc == true )
153+ if (USE_SPI_MICROSD )
184154 {
185- // ESP32Time returns month:0-11
186- _sdFile->timestamp (T_ACCESS, rtc.getYear (), rtc.getMonth () + 1 , rtc.getDay (), rtc.getHour (true ), rtc.getMinute (), rtc.getSecond ());
187- _sdFile->timestamp (T_WRITE, rtc.getYear (), rtc.getMonth () + 1 , rtc.getDay (), rtc.getHour (true ), rtc.getMinute (), rtc.getSecond ());
155+ if (online.rtc == true )
156+ {
157+ // ESP32Time returns month:0-11
158+ _sdFile->timestamp (T_ACCESS, rtc.getYear (), rtc.getMonth () + 1 , rtc.getDay (), rtc.getHour (true ), rtc.getMinute (), rtc.getSecond ());
159+ _sdFile->timestamp (T_WRITE, rtc.getYear (), rtc.getMonth () + 1 , rtc.getDay (), rtc.getHour (true ), rtc.getMinute (), rtc.getSecond ());
160+ }
188161 }
189- }
190- };
162+ };
191163
192- void updateFileCreateTimestamp ()
193- {
194- if (USE_SPI_MICROSD)
164+ void updateFileCreateTimestamp ()
195165 {
196- if (online. rtc == true )
166+ if (USE_SPI_MICROSD )
197167 {
198- _sdFile->timestamp (T_CREATE, rtc.getYear (), rtc.getMonth () + 1 , rtc.getDay (), rtc.getHour (true ), rtc.getMinute (), rtc.getSecond ()); // ESP32Time returns month:0-11
168+ if (online.rtc == true )
169+ {
170+ _sdFile->timestamp (T_CREATE, rtc.getYear (), rtc.getMonth () + 1 , rtc.getDay (), rtc.getHour (true ), rtc.getMinute (), rtc.getSecond ()); // ESP32Time returns month:0-11
171+ }
199172 }
200- }
201- };
173+ };
202174
203- void sync ()
204- {
205- if (USE_SPI_MICROSD)
206- _sdFile->sync ();
207- };
175+ void sync ()
176+ {
177+ if (USE_SPI_MICROSD)
178+ _sdFile->sync ();
179+ };
180+
181+ int fileSize ()
182+ {
183+ if (USE_SPI_MICROSD)
184+ return _sdFile->fileSize ();
185+ #ifdef COMPILE_SD_MMC
186+ else
187+ return _file->size ();
188+ #endif
189+ };
208190
209- protected:
210- SdFile *_sdFile;
191+ protected:
192+ SdFile * _sdFile;
211193#ifdef COMPILE_SD_MMC
212- File *_file;
194+ File * _file;
213195#endif
214196};
215197
0 commit comments