aboutsummaryrefslogtreecommitdiff
path: root/libraries/Bridge/FileIO.cpp
diff options
context:
space:
mode:
authorFederico Fissore <f.fissore@arduino.cc>2013-07-11 18:14:49 +0200
committerFederico Fissore <f.fissore@arduino.cc>2013-07-11 18:14:49 +0200
commitbd1e2ab33250588b33038ab0e9a57437ed1d6e98 (patch)
tree1c6a9c53011c85d9efdd04f6e14329366beb2fb8 /libraries/Bridge/FileIO.cpp
parent61ccf77a7aa7d5d1385b772df86563a8595399c8 (diff)
File: implemented File.openNextFile() and File.rewindDirectory()
Diffstat (limited to 'libraries/Bridge/FileIO.cpp')
-rw-r--r--libraries/Bridge/FileIO.cpp42
1 files changed, 39 insertions, 3 deletions
diff --git a/libraries/Bridge/FileIO.cpp b/libraries/Bridge/FileIO.cpp
index 4339c8e..83c889e 100644
--- a/libraries/Bridge/FileIO.cpp
+++ b/libraries/Bridge/FileIO.cpp
@@ -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;
+}