mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-16 11:21:18 +03:00
Replacing boolean parameters to SD.open() with SD_MODE constants.
This commit is contained in:
@ -15,11 +15,25 @@ void setup()
|
|||||||
ATS_PrintTestStatus("SD.begin()", b = SD.begin(4));
|
ATS_PrintTestStatus("SD.begin()", b = SD.begin(4));
|
||||||
if (!b) goto done;
|
if (!b) goto done;
|
||||||
|
|
||||||
f = SD.open("test.txt", true, false);
|
f = SD.open("test.txt", SD_TRUNCATE);
|
||||||
ATS_PrintTestStatus("SD.open()", f);
|
ATS_PrintTestStatus("SD.open()", f);
|
||||||
if (!f) goto done;
|
if (!f) goto done;
|
||||||
|
|
||||||
f.print("abcdefgh");
|
f.print("1234");
|
||||||
|
f.close();
|
||||||
|
|
||||||
|
f = SD.open("test.txt", SD_TRUNCATE);
|
||||||
|
ATS_PrintTestStatus("SD.open()", f);
|
||||||
|
if (!f) goto done;
|
||||||
|
|
||||||
|
f.print("abcde");
|
||||||
|
f.close();
|
||||||
|
|
||||||
|
f = SD.open("test.txt", SD_APPEND);
|
||||||
|
ATS_PrintTestStatus("SD.open()", f);
|
||||||
|
if (!f) goto done;
|
||||||
|
|
||||||
|
f.print("fgh");
|
||||||
f.close();
|
f.close();
|
||||||
|
|
||||||
f = SD.open("test.txt");
|
f = SD.open("test.txt");
|
||||||
@ -57,7 +71,7 @@ void setup()
|
|||||||
|
|
||||||
f.close();
|
f.close();
|
||||||
|
|
||||||
f = SD.open("test2.txt", true, false);
|
f = SD.open("test2.txt", SD_TRUNCATE);
|
||||||
ATS_PrintTestStatus("SD.open()", f);
|
ATS_PrintTestStatus("SD.open()", f);
|
||||||
if (!f) goto done;
|
if (!f) goto done;
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ void setup()
|
|||||||
if (!b) goto done;
|
if (!b) goto done;
|
||||||
|
|
||||||
ATS_PrintTestStatus("!SD.exists()", !SD.exists("asdf.txt"));
|
ATS_PrintTestStatus("!SD.exists()", !SD.exists("asdf.txt"));
|
||||||
ATS_PrintTestStatus("SD.open()", f = SD.open("asdf.txt", true)); f.close();
|
ATS_PrintTestStatus("SD.open()", f = SD.open("asdf.txt", SD_TRUNCATE)); f.close();
|
||||||
ATS_PrintTestStatus("SD.exists()", SD.exists("asdf.txt"));
|
ATS_PrintTestStatus("SD.exists()", SD.exists("asdf.txt"));
|
||||||
ATS_PrintTestStatus("SD.exists()", SD.exists("/asdf.txt"));
|
ATS_PrintTestStatus("SD.exists()", SD.exists("/asdf.txt"));
|
||||||
ATS_PrintTestStatus("SD.remove()", SD.remove("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"));
|
||||||
ATS_PrintTestStatus("!SD.exists()", !SD.exists("x/y/z"));
|
ATS_PrintTestStatus("!SD.exists()", !SD.exists("x/y/z"));
|
||||||
|
|
||||||
ATS_PrintTestStatus("!SD.open()", !(f = SD.open("asdf/asdf.txt", true))); f.close();
|
ATS_PrintTestStatus("!SD.open()", !(f = SD.open("asdf/asdf.txt", SD_TRUNCATE))); f.close();
|
||||||
ATS_PrintTestStatus("!SD.exists()", !SD.exists("asdf"));
|
ATS_PrintTestStatus("!SD.exists()", !SD.exists("asdf"));
|
||||||
ATS_PrintTestStatus("!SD.exists()", !SD.exists("asdf.txt"));
|
ATS_PrintTestStatus("!SD.exists()", !SD.exists("asdf.txt"));
|
||||||
ATS_PrintTestStatus("!SD.exists()", !SD.exists("asdf/asdf.txt"));
|
ATS_PrintTestStatus("!SD.exists()", !SD.exists("asdf/asdf.txt"));
|
||||||
ATS_PrintTestStatus("SD.mkdir()", SD.mkdir("asdf"));
|
ATS_PrintTestStatus("SD.mkdir()", SD.mkdir("asdf"));
|
||||||
ATS_PrintTestStatus("SD.exists()", SD.exists("asdf"));
|
ATS_PrintTestStatus("SD.exists()", SD.exists("asdf"));
|
||||||
ATS_PrintTestStatus("SD.open()", f = SD.open("asdf/asdf.txt", true)); f.close();
|
ATS_PrintTestStatus("SD.open()", f = SD.open("asdf/asdf.txt", SD_TRUNCATE)); f.close();
|
||||||
ATS_PrintTestStatus("SD.exists()", SD.exists("asdf/asdf.txt"));
|
ATS_PrintTestStatus("SD.exists()", SD.exists("asdf/asdf.txt"));
|
||||||
ATS_PrintTestStatus("!SD.rmdir()", !SD.rmdir("asdf"));
|
ATS_PrintTestStatus("!SD.rmdir()", !SD.rmdir("asdf"));
|
||||||
ATS_PrintTestStatus("SD.exists()", SD.exists("asdf"));
|
ATS_PrintTestStatus("SD.exists()", SD.exists("asdf"));
|
||||||
|
@ -343,7 +343,7 @@ boolean SDClass::begin(uint8_t csPin) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
File SDClass::open(char *filepath, boolean write, boolean append) {
|
File SDClass::open(char *filepath, uint8_t mode) {
|
||||||
/*
|
/*
|
||||||
|
|
||||||
Open the supplied file path for reading or writing.
|
Open the supplied file path for reading or writing.
|
||||||
@ -369,18 +369,7 @@ File SDClass::open(char *filepath, boolean write, boolean append) {
|
|||||||
|
|
||||||
// TODO: Allow for read&write? (Possibly not, as it requires seek.)
|
// TODO: Allow for read&write? (Possibly not, as it requires seek.)
|
||||||
|
|
||||||
uint8_t oflag = O_RDONLY;
|
fileOpenMode = mode;
|
||||||
|
|
||||||
if (write) {
|
|
||||||
oflag = O_CREAT | O_WRITE;
|
|
||||||
if (append) {
|
|
||||||
oflag |= O_APPEND;
|
|
||||||
} else {
|
|
||||||
oflag |= O_TRUNC;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fileOpenMode = oflag;
|
|
||||||
walkPath(filepath, root, callback_openPath, this);
|
walkPath(filepath, root, callback_openPath, this);
|
||||||
|
|
||||||
return File();
|
return File();
|
||||||
|
@ -20,6 +20,10 @@
|
|||||||
#include <utility/SdFat.h>
|
#include <utility/SdFat.h>
|
||||||
#include <utility/SdFatUtil.h>
|
#include <utility/SdFatUtil.h>
|
||||||
|
|
||||||
|
#define SD_READ O_READ
|
||||||
|
#define SD_TRUNCATE (O_WRITE | O_CREAT | O_TRUNC)
|
||||||
|
#define SD_APPEND (O_WRITE | O_CREAT | O_APPEND)
|
||||||
|
|
||||||
class File : public Stream {
|
class File : public Stream {
|
||||||
public:
|
public:
|
||||||
virtual void write(uint8_t);
|
virtual void write(uint8_t);
|
||||||
@ -49,7 +53,7 @@ public:
|
|||||||
// Open the specified file/directory with the supplied mode (e.g. read or
|
// Open the specified file/directory with the supplied mode (e.g. read or
|
||||||
// write, etc). Returns a File object for interacting with the file.
|
// write, etc). Returns a File object for interacting with the file.
|
||||||
// Note that currently only one file can be open at a time.
|
// Note that currently only one file can be open at a time.
|
||||||
File open(char *filename, boolean write = false, boolean append = true);
|
File open(char *filename, uint8_t mode = SD_READ);
|
||||||
|
|
||||||
// Methods to determine if the requested file path exists.
|
// Methods to determine if the requested file path exists.
|
||||||
boolean exists(char *filepath);
|
boolean exists(char *filepath);
|
||||||
|
Reference in New Issue
Block a user