18
18
19
19
#include < FileIO.h>
20
20
21
+
22
+
21
23
File::File (BridgeClass &b) : mode(255 ), bridge(b) {
22
24
// Empty
23
25
}
@@ -27,6 +29,7 @@ File::File(const char *_filename, uint8_t _mode, BridgeClass &b) : mode(_mode),
27
29
char modes[] = {' r' ,' w' ,' a' };
28
30
uint8_t cmd[] = {' F' , modes[mode]};
29
31
uint8_t res[2 ];
32
+ dirPosition = 1 ;
30
33
bridge.transfer (cmd, 2 , (uint8_t *)filename.c_str (), filename.length (), res, 2 );
31
34
if (res[0 ] != 0 ) { // res[0] contains error code
32
35
mode = 255 ; // In case of error keep the file closed
@@ -161,9 +164,42 @@ boolean File::isDirectory() {
161
164
bridge.transfer (cmd, 1 , (uint8_t *)filename.c_str (), filename.length (), res, 1 );
162
165
return res[0 ];
163
166
}
164
- // boolean isDirectory(void)
165
- // File openNextFile(uint8_t mode = O_RDONLY);
166
- // void rewindDirectory(void)
167
+
168
+
169
+ File File::openNextFile (uint8_t mode){
170
+ Process awk;
171
+ char tmp;
172
+ String command;
173
+ String filepath;
174
+ if (dirPosition == 0xFFFF ) return File ();
175
+
176
+ command = " ls " ;
177
+ command += filename;
178
+ command += " | awk 'NR==" ;
179
+ command += dirPosition;
180
+ command += " '" ;
181
+
182
+ awk.runShellCommand (command);
183
+
184
+ while (awk.running ());
185
+
186
+ command = " " ;
187
+
188
+ while (awk.available ()){
189
+ tmp = awk.read ();
190
+ if (tmp!=' \n ' ) command += tmp;
191
+ }
192
+ if (command.length () == 0 )
193
+ return File ();
194
+ dirPosition++;
195
+ filepath = filename + " /" + command;
196
+ return File (filepath.c_str (),mode);
197
+
198
+ }
199
+
200
+ void File::rewindDirectory (void ){
201
+ dirPosition = 1 ;
202
+ }
167
203
168
204
169
205
0 commit comments