Skip to content

Commit f9f4c5d

Browse files
committed
Add fileSize to FileSdFatMMC
1 parent 7ded2f3 commit f9f4c5d

File tree

1 file changed

+38
-28
lines changed

1 file changed

+38
-28
lines changed

Firmware/RTK_Surveyor/FileSdFatMMC.h

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#ifdef COMPILE_SD_MMC
44

5-
//#include "FS.h"
5+
// #include "FS.h"
66
#include "SD_MMC.h" // Also includes FS.h
77

88
class FileSdFatMMC : public SdFile, public File
@@ -15,7 +15,6 @@ class FileSdFatMMC : public SdFile
1515

1616
{
1717
public:
18-
1918
FileSdFatMMC()
2019
{
2120
if (USE_SPI_MICROSD)
@@ -25,21 +24,21 @@ class FileSdFatMMC : public SdFile
2524
_file = new File;
2625
#endif
2726
};
28-
27+
2928
~FileSdFatMMC()
3029
{
3130
if (USE_SPI_MICROSD)
3231
{
3332
;
34-
//if (_sdFile) // operator bool
35-
// delete _sdFile;
33+
// if (_sdFile) // operator bool
34+
// delete _sdFile;
3635
}
3736
#ifdef COMPILE_SD_MMC
3837
else
3938
{
4039
;
41-
//if (_file) // operator bool
42-
// delete _file;
40+
// if (_file) // operator bool
41+
// delete _file;
4342
}
4443
#endif
4544
};
@@ -87,7 +86,7 @@ class FileSdFatMMC : public SdFile
8786
return true;
8887
return false;
8988
}
90-
#endif
89+
#endif
9190
return false; // Keep the compiler happy
9291
};
9392

@@ -97,8 +96,19 @@ class FileSdFatMMC : public SdFile
9796
return _sdFile->size();
9897
#ifdef COMPILE_SD_MMC
9998
else
100-
return _file->size();
101-
#endif
99+
return (uint32_t)_file->size();
100+
#endif
101+
return 0; // Keep the compiler happy
102+
};
103+
104+
uint32_t fileSize()
105+
{
106+
if (USE_SPI_MICROSD)
107+
return _sdFile->fileSize();
108+
#ifdef COMPILE_SD_MMC
109+
else
110+
return (uint32_t)_file->size();
111+
#endif
102112
return 0; // Keep the compiler happy
103113
};
104114

@@ -108,8 +118,8 @@ class FileSdFatMMC : public SdFile
108118
return _sdFile->position();
109119
#ifdef COMPILE_SD_MMC
110120
else
111-
return _file->position();
112-
#endif
121+
return (uint32_t)_file->position();
122+
#endif
113123
return 0; // Keep the compiler happy
114124
};
115125

@@ -120,20 +130,20 @@ class FileSdFatMMC : public SdFile
120130
#ifdef COMPILE_SD_MMC
121131
else
122132
return _file->available();
123-
#endif
133+
#endif
124134
return 0; // Keep the compiler happy
125-
};
135+
};
126136

127137
int read(uint8_t *buf, uint16_t nbyte)
128138
{
129139
if (USE_SPI_MICROSD)
130140
return _sdFile->read(buf, nbyte);
131141
#ifdef COMPILE_SD_MMC
132142
else
133-
return _file->read(buf, nbyte);
134-
#endif
143+
return (int)_file->read(buf, nbyte);
144+
#endif
135145
return 0; // Keep the compiler happy
136-
};
146+
};
137147

138148
size_t write(const uint8_t *buf, size_t size)
139149
{
@@ -142,7 +152,7 @@ class FileSdFatMMC : public SdFile
142152
#ifdef COMPILE_SD_MMC
143153
else
144154
return _file->write(buf, size);
145-
#endif
155+
#endif
146156
return 0; // Keep the compiler happy
147157
};
148158

@@ -153,7 +163,7 @@ class FileSdFatMMC : public SdFile
153163
#ifdef COMPILE_SD_MMC
154164
else
155165
_file->close();
156-
#endif
166+
#endif
157167
};
158168

159169
void updateFileAccessTimestamp()
@@ -162,7 +172,7 @@ class FileSdFatMMC : public SdFile
162172
{
163173
if (online.rtc == true)
164174
{
165-
//ESP32Time returns month:0-11
175+
// ESP32Time returns month:0-11
166176
_sdFile->timestamp(T_ACCESS, rtc.getYear(), rtc.getMonth() + 1, rtc.getDay(), rtc.getHour(true), rtc.getMinute(), rtc.getSecond());
167177
_sdFile->timestamp(T_WRITE, rtc.getYear(), rtc.getMonth() + 1, rtc.getDay(), rtc.getHour(true), rtc.getMinute(), rtc.getSecond());
168178
}
@@ -175,7 +185,7 @@ class FileSdFatMMC : public SdFile
175185
{
176186
if (online.rtc == true)
177187
{
178-
_sdFile->timestamp(T_CREATE, rtc.getYear(), rtc.getMonth() + 1, rtc.getDay(), rtc.getHour(true), rtc.getMinute(), rtc.getSecond()); //ESP32Time returns month:0-11
188+
_sdFile->timestamp(T_CREATE, rtc.getYear(), rtc.getMonth() + 1, rtc.getDay(), rtc.getHour(true), rtc.getMinute(), rtc.getSecond()); // ESP32Time returns month:0-11
179189
}
180190
}
181191
};
@@ -187,27 +197,27 @@ class FileSdFatMMC : public SdFile
187197
};
188198

189199
protected:
190-
SdFile * _sdFile;
200+
SdFile *_sdFile;
191201
#ifdef COMPILE_SD_MMC
192-
File * _file;
202+
File *_file;
193203
#endif
194204
};
195205

196-
//Update the file access and write time with date and time obtained from GNSS
197-
// These are SdFile-specific. SD_MMC does this automatically
206+
// Update the file access and write time with date and time obtained from GNSS
207+
// These are SdFile-specific. SD_MMC does this automatically
198208
void updateDataFileAccess(SdFile *dataFile)
199209
{
200210
if (online.rtc == true)
201211
{
202-
//ESP32Time returns month:0-11
212+
// ESP32Time returns month:0-11
203213
dataFile->timestamp(T_ACCESS, rtc.getYear(), rtc.getMonth() + 1, rtc.getDay(), rtc.getHour(true), rtc.getMinute(), rtc.getSecond());
204214
dataFile->timestamp(T_WRITE, rtc.getYear(), rtc.getMonth() + 1, rtc.getDay(), rtc.getHour(true), rtc.getMinute(), rtc.getSecond());
205215
}
206216
}
207217

208-
//Update the file create time with date and time obtained from GNSS
218+
// Update the file create time with date and time obtained from GNSS
209219
void updateDataFileCreate(SdFile *dataFile)
210220
{
211221
if (online.rtc == true)
212-
dataFile->timestamp(T_CREATE, rtc.getYear(), rtc.getMonth() + 1, rtc.getDay(), rtc.getHour(true), rtc.getMinute(), rtc.getSecond()); //ESP32Time returns month:0-11
222+
dataFile->timestamp(T_CREATE, rtc.getYear(), rtc.getMonth() + 1, rtc.getDay(), rtc.getHour(true), rtc.getMinute(), rtc.getSecond()); // ESP32Time returns month:0-11
213223
}

0 commit comments

Comments
 (0)