mirror of
https://github.com/arduino/Arduino.git
synced 2024-11-29 10:24:12 +01:00
File: implemented File.openNextFile() and File.rewindDirectory()
This commit is contained in:
parent
08d9e574c8
commit
de095c0c43
@ -18,6 +18,8 @@
|
||||
|
||||
#include <FileIO.h>
|
||||
|
||||
|
||||
|
||||
File::File(BridgeClass &b) : mode(255), bridge(b) {
|
||||
// Empty
|
||||
}
|
||||
@ -27,6 +29,7 @@ File::File(const char *_filename, uint8_t _mode, BridgeClass &b) : mode(_mode),
|
||||
char modes[] = {'r','w','a'};
|
||||
uint8_t cmd[] = {'F', modes[mode]};
|
||||
uint8_t res[2];
|
||||
dirPosition = 1;
|
||||
bridge.transfer(cmd, 2, (uint8_t*)filename.c_str(), filename.length(), res, 2);
|
||||
if (res[0] != 0) { // res[0] contains error code
|
||||
mode = 255; // In case of error keep the file closed
|
||||
@ -161,9 +164,42 @@ boolean File::isDirectory() {
|
||||
bridge.transfer(cmd, 1, (uint8_t *)filename.c_str(), filename.length(), res, 1);
|
||||
return res[0];
|
||||
}
|
||||
//boolean isDirectory(void)
|
||||
//File openNextFile(uint8_t mode = O_RDONLY);
|
||||
//void rewindDirectory(void)
|
||||
|
||||
|
||||
File File::openNextFile(uint8_t mode){
|
||||
Process awk;
|
||||
char tmp;
|
||||
String command;
|
||||
String filepath;
|
||||
if (dirPosition == 0xFFFF) return File();
|
||||
|
||||
command = "ls ";
|
||||
command += filename;
|
||||
command += " | awk 'NR==";
|
||||
command += dirPosition;
|
||||
command += "'";
|
||||
|
||||
awk.runShellCommand(command);
|
||||
|
||||
while(awk.running());
|
||||
|
||||
command = "";
|
||||
|
||||
while (awk.available()){
|
||||
tmp = awk.read();
|
||||
if (tmp!='\n') command += tmp;
|
||||
}
|
||||
if (command.length() == 0)
|
||||
return File();
|
||||
dirPosition++;
|
||||
filepath = filename + "/" + command;
|
||||
return File(filepath.c_str(),mode);
|
||||
|
||||
}
|
||||
|
||||
void File::rewindDirectory(void){
|
||||
dirPosition = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -55,14 +55,17 @@ private:
|
||||
void doBuffer();
|
||||
uint8_t buffered;
|
||||
uint8_t readPos;
|
||||
uint16_t dirPosition;
|
||||
static const int BUFFER_SIZE = 64;
|
||||
uint8_t buffer[BUFFER_SIZE];
|
||||
|
||||
|
||||
private:
|
||||
BridgeClass &bridge;
|
||||
String filename;
|
||||
uint8_t mode;
|
||||
uint8_t handle;
|
||||
|
||||
};
|
||||
|
||||
class FileSystemClass {
|
||||
|
Loading…
Reference in New Issue
Block a user