mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-19 13:54:23 +01:00
Redoing peek() implementation (SD file class).
Now simply seeking backwards by a character in peek() rather than trying to keep track of the extra character read.
This commit is contained in:
parent
a7a8f3fa10
commit
575bb1dafb
@ -13,7 +13,7 @@ void setup()
|
||||
if (!b) goto done;
|
||||
|
||||
ATS_PrintTestStatus("!SD.exists()", !SD.exists("asdf.txt"));
|
||||
ATS_PrintTestStatus("SD.open()", f = SD.open("asdf.txt", FILE_TRUNCATE)); f.close();
|
||||
ATS_PrintTestStatus("SD.open()", f = SD.open("asdf.txt", FILE_WRITE)); f.close();
|
||||
ATS_PrintTestStatus("SD.exists()", SD.exists("asdf.txt"));
|
||||
ATS_PrintTestStatus("SD.exists()", SD.exists("/asdf.txt"));
|
||||
ATS_PrintTestStatus("SD.remove()", SD.remove("asdf.txt"));
|
||||
@ -48,13 +48,13 @@ void setup()
|
||||
ATS_PrintTestStatus("!SD.exists()", !SD.exists("x/y"));
|
||||
ATS_PrintTestStatus("!SD.exists()", !SD.exists("x/y/z"));
|
||||
|
||||
ATS_PrintTestStatus("!SD.open()", !(f = SD.open("asdf/asdf.txt", FILE_TRUNCATE))); f.close();
|
||||
ATS_PrintTestStatus("!SD.open()", !(f = SD.open("asdf/asdf.txt", FILE_WRITE))); f.close();
|
||||
ATS_PrintTestStatus("!SD.exists()", !SD.exists("asdf"));
|
||||
ATS_PrintTestStatus("!SD.exists()", !SD.exists("asdf.txt"));
|
||||
ATS_PrintTestStatus("!SD.exists()", !SD.exists("asdf/asdf.txt"));
|
||||
ATS_PrintTestStatus("SD.mkdir()", SD.mkdir("asdf"));
|
||||
ATS_PrintTestStatus("SD.exists()", SD.exists("asdf"));
|
||||
ATS_PrintTestStatus("SD.open()", f = SD.open("asdf/asdf.txt", FILE_TRUNCATE)); f.close();
|
||||
ATS_PrintTestStatus("SD.open()", f = SD.open("asdf/asdf.txt", FILE_WRITE)); f.close();
|
||||
ATS_PrintTestStatus("SD.exists()", SD.exists("asdf/asdf.txt"));
|
||||
ATS_PrintTestStatus("!SD.rmdir()", !SD.rmdir("asdf"));
|
||||
ATS_PrintTestStatus("SD.exists()", SD.exists("asdf"));
|
||||
|
@ -15,39 +15,29 @@
|
||||
#include <SD.h>
|
||||
|
||||
void File::write(uint8_t val) {
|
||||
SD.c = -1;
|
||||
SD.file.write(val);
|
||||
}
|
||||
|
||||
void File::write(const char *str) {
|
||||
SD.c = -1;
|
||||
SD.file.write(str);
|
||||
}
|
||||
|
||||
void File::write(const uint8_t *buf, size_t size) {
|
||||
SD.c = -1;
|
||||
SD.file.write(buf, size);
|
||||
}
|
||||
|
||||
int File::peek() {
|
||||
if (SD.c != -1) return SD.c;
|
||||
SD.c = SD.file.read();
|
||||
return SD.c;
|
||||
char c = SD.file.read();
|
||||
if (c != -1) SD.file.seekCur(-1);
|
||||
return c;
|
||||
}
|
||||
|
||||
int File::read() {
|
||||
if (SD.c != -1) {
|
||||
int tmp = SD.c;
|
||||
SD.c = -1;
|
||||
return tmp;
|
||||
}
|
||||
return SD.file.read();
|
||||
}
|
||||
|
||||
int File::available() {
|
||||
if (SD.c != -1) return 1;
|
||||
SD.c = SD.file.read();
|
||||
return SD.c != -1;
|
||||
return size() - position();
|
||||
}
|
||||
|
||||
void File::flush() {
|
||||
@ -55,12 +45,10 @@ void File::flush() {
|
||||
}
|
||||
|
||||
boolean File::seek(uint32_t pos) {
|
||||
SD.c = -1;
|
||||
return SD.file.seekSet(pos);
|
||||
}
|
||||
|
||||
uint32_t File::position() {
|
||||
if (SD.c != -1) return SD.file.curPosition() - 1;
|
||||
return SD.file.curPosition();
|
||||
}
|
||||
|
||||
|
@ -300,7 +300,6 @@ boolean callback_openPath(SdFile& parentDir, char *filePathComponent,
|
||||
if (p_SD->fileOpenMode == FILE_WRITE) {
|
||||
p_SD->file.seekSet(p_SD->file.fileSize());
|
||||
}
|
||||
p_SD->c = -1;
|
||||
// TODO: Return file open result?
|
||||
return false;
|
||||
}
|
||||
|
@ -79,8 +79,6 @@ private:
|
||||
// It shouldn't be set directly--it is set via the parameters to `open`.
|
||||
int fileOpenMode;
|
||||
|
||||
int c;
|
||||
|
||||
friend class File;
|
||||
friend boolean callback_openPath(SdFile&, char *, boolean, void *);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user