mirror of
https://github.com/arduino/Arduino.git
synced 2024-11-29 10:24:12 +01:00
Revising SD library API.
Open now returns a file object (which has a close() method); exists() no longer accepts a parent directory.
This commit is contained in:
parent
06d3d85143
commit
a5898ae26a
39
libraries/SD/File.cpp
Normal file
39
libraries/SD/File.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
|
||||
SD - a slightly more friendly wrapper for sdfatlib
|
||||
|
||||
This library aims to expose a subset of SD card functionality
|
||||
in the form of a higher level "wrapper" object.
|
||||
|
||||
License: GNU General Public License V3
|
||||
(Because sdfatlib is licensed with this.)
|
||||
|
||||
(C) Copyright 2010 SparkFun Electronics
|
||||
|
||||
*/
|
||||
|
||||
#include <SD.h>
|
||||
|
||||
void File::write(uint8_t val) {
|
||||
SD.file.write(val);
|
||||
}
|
||||
|
||||
void File::write(const char *str) {
|
||||
SD.file.write(str);
|
||||
}
|
||||
|
||||
void File::write(const uint8_t *buf, size_t size) {
|
||||
SD.file.write(buf, size);
|
||||
}
|
||||
|
||||
int File::read() {
|
||||
return SD.file.read();
|
||||
}
|
||||
|
||||
void File::close() {
|
||||
SD.file.close();
|
||||
}
|
||||
|
||||
File::operator bool() {
|
||||
return SD.file.isOpen();
|
||||
}
|
@ -327,7 +327,7 @@ void SDClass::begin(uint8_t csPin) {
|
||||
}
|
||||
|
||||
|
||||
boolean SDClass::open(char *filepath,
|
||||
File SDClass::open(char *filepath,
|
||||
boolean write, boolean append) {
|
||||
/*
|
||||
|
||||
@ -368,19 +368,19 @@ boolean SDClass::open(char *filepath,
|
||||
fileOpenMode = oflag;
|
||||
walkPath(filepath, root, callback_openPath, this);
|
||||
|
||||
// TODO: Actually return something useful.
|
||||
return File();
|
||||
|
||||
}
|
||||
|
||||
|
||||
boolean SDClass::close() {
|
||||
/*
|
||||
|
||||
Closes the file opened by the `open` method.
|
||||
|
||||
*/
|
||||
file.close();
|
||||
}
|
||||
//boolean SDClass::close() {
|
||||
// /*
|
||||
//
|
||||
// Closes the file opened by the `open` method.
|
||||
//
|
||||
// */
|
||||
// file.close();
|
||||
//}
|
||||
|
||||
|
||||
boolean SDClass::exists(char *filepath) {
|
||||
@ -389,19 +389,19 @@ boolean SDClass::exists(char *filepath) {
|
||||
Returns true if the supplied file path exists.
|
||||
|
||||
*/
|
||||
return exists(filepath, root);
|
||||
return walkPath(filepath, root, callback_pathExists);
|
||||
}
|
||||
|
||||
|
||||
boolean SDClass::exists(char *filepath, SdFile& parentDir) {
|
||||
/*
|
||||
|
||||
Returns true if the supplied file path rooted at `parentDir`
|
||||
exists.
|
||||
|
||||
*/
|
||||
return walkPath(filepath, parentDir, callback_pathExists);
|
||||
}
|
||||
//boolean SDClass::exists(char *filepath, SdFile& parentDir) {
|
||||
// /*
|
||||
//
|
||||
// Returns true if the supplied file path rooted at `parentDir`
|
||||
// exists.
|
||||
//
|
||||
// */
|
||||
// return walkPath(filepath, parentDir, callback_pathExists);
|
||||
//}
|
||||
|
||||
|
||||
boolean SDClass::makeDir(char *filepath) {
|
||||
|
@ -23,6 +23,16 @@
|
||||
// Use this to configure the chip select pin of the SD card.
|
||||
#define SD_CARD_CHIP_SELECT_PIN 4 // For use with Arduino Ethernet Shield
|
||||
|
||||
class File : public Print {
|
||||
public:
|
||||
virtual void write(uint8_t);
|
||||
virtual void write(const char *str);
|
||||
virtual void write(const uint8_t *buf, size_t size);
|
||||
int read();
|
||||
void close();
|
||||
operator bool();
|
||||
};
|
||||
|
||||
class SDClass {
|
||||
|
||||
private:
|
||||
@ -40,14 +50,14 @@ class SDClass {
|
||||
// Open the specified file/directory with the supplied mode (e.g. read or
|
||||
// write, etc). Once opened the file can be accessed via the
|
||||
// `MemoryCard.file` field which is a standard `sdfatlib` file object.
|
||||
boolean open(char *filename, boolean write = false, boolean append = true);
|
||||
File open(char *filename, boolean write = false, boolean append = true);
|
||||
|
||||
// Close an opened file object.
|
||||
boolean close();
|
||||
//boolean close();
|
||||
|
||||
// Methods to determine if the requested file path exists.
|
||||
boolean exists(char *filepath);
|
||||
boolean exists(char *filepath, SdFile& parentDir);
|
||||
//boolean exists(char *filepath, SdFile& parentDir);
|
||||
|
||||
// Create the requested directory heirarchy--if intermediate directories
|
||||
// do not exist they will be created.
|
||||
|
Loading…
Reference in New Issue
Block a user