aboutsummaryrefslogtreecommitdiff
path: root/libraries/SD
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/SD')
-rw-r--r--libraries/SD/File.cpp33
-rw-r--r--libraries/SD/SD.cpp6
-rw-r--r--libraries/SD/SD.h13
-rw-r--r--libraries/SD/examples/CardInfo/CardInfo.ino (renamed from libraries/SD/examples/CardInfo/CardInfo.pde)2
-rw-r--r--libraries/SD/examples/Datalogger/Datalogger.ino (renamed from libraries/SD/examples/Datalogger/Datalogger.pde)0
-rw-r--r--libraries/SD/examples/DumpFile/DumpFile.ino (renamed from libraries/SD/examples/DumpFile/DumpFile.pde)0
-rw-r--r--libraries/SD/examples/Files/Files.ino (renamed from libraries/SD/examples/Files/Files.pde)0
-rw-r--r--libraries/SD/examples/ReadWrite/ReadWrite.ino (renamed from libraries/SD/examples/ReadWrite/ReadWrite.pde)0
-rw-r--r--libraries/SD/examples/listfiles/listfiles.ino (renamed from libraries/SD/examples/listfiles/listfiles.pde)0
-rw-r--r--libraries/SD/utility/SdFat.h8
-rw-r--r--libraries/SD/utility/SdFatUtil.h5
-rw-r--r--libraries/SD/utility/SdFile.cpp17
12 files changed, 47 insertions, 37 deletions
diff --git a/libraries/SD/File.cpp b/libraries/SD/File.cpp
index 9ef8196..88d9e9a 100644
--- a/libraries/SD/File.cpp
+++ b/libraries/SD/File.cpp
@@ -18,7 +18,7 @@
uint8_t nfilecount=0;
*/
-File::File(SdFile f, char *n) {
+File::File(SdFile f, const char *n) {
// oh man you are kidding me, new() doesnt exist? Ok we do it by hand!
_file = (SdFile *)malloc(sizeof(SdFile));
if (_file) {
@@ -58,19 +58,23 @@ boolean File::isDirectory(void) {
}
-void File::write(uint8_t val) {
- if (_file)
- _file->write(val);
-}
-
-void File::write(const char *str) {
- if (_file)
- _file->write(str);
+size_t File::write(uint8_t val) {
+ return write(&val, 1);
}
-void File::write(const uint8_t *buf, size_t size) {
- if (_file)
- _file->write(buf, size);
+size_t File::write(const uint8_t *buf, size_t size) {
+ size_t t;
+ if (!_file) {
+ setWriteError();
+ return 0;
+ }
+ _file->clearWriteError();
+ t = _file->write(buf, size);
+ if (_file->getWriteError()) {
+ setWriteError();
+ return 0;
+ }
+ return t;
}
int File::peek() {
@@ -97,7 +101,10 @@ int File::read(void *buf, uint16_t nbyte) {
int File::available() {
if (! _file) return 0;
- return size() - position();
+
+ uint32_t n = size() - position();
+
+ return n > 0X7FFF ? 0X7FFF : n;
}
void File::flush() {
diff --git a/libraries/SD/SD.cpp b/libraries/SD/SD.cpp
index 64dc40b..c746809 100644
--- a/libraries/SD/SD.cpp
+++ b/libraries/SD/SD.cpp
@@ -348,7 +348,7 @@ boolean SDClass::begin(uint8_t csPin) {
// this little helper is used to traverse paths
-SdFile SDClass::getParentDir(char *filepath, int *index) {
+SdFile SDClass::getParentDir(const char *filepath, int *index) {
// get parent directory
SdFile d1 = root; // start with the mostparent, root!
SdFile d2;
@@ -357,7 +357,7 @@ SdFile SDClass::getParentDir(char *filepath, int *index) {
SdFile *parent = &d1;
SdFile *subdir = &d2;
- char *origpath = filepath;
+ const char *origpath = filepath;
while (strchr(filepath, '/')) {
@@ -404,7 +404,7 @@ SdFile SDClass::getParentDir(char *filepath, int *index) {
}
-File SDClass::open(char *filepath, uint8_t mode) {
+File SDClass::open(const char *filepath, uint8_t mode) {
/*
Open the supplied file path for reading or writing.
diff --git a/libraries/SD/SD.h b/libraries/SD/SD.h
index 584e2ae..f21ec0f 100644
--- a/libraries/SD/SD.h
+++ b/libraries/SD/SD.h
@@ -29,12 +29,11 @@ class File : public Stream {
SdFile *_file; // underlying file pointer
public:
- File(SdFile f, char *name); // wraps an underlying SdFile
+ File(SdFile f, const char *name); // wraps an underlying SdFile
File(void); // 'empty' constructor
~File(void); // destructor
- virtual void write(uint8_t);
- virtual void write(const char *str);
- virtual void write(const uint8_t *buf, size_t size);
+ virtual size_t write(uint8_t);
+ virtual size_t write(const uint8_t *buf, size_t size);
virtual int read();
virtual int peek();
virtual int available();
@@ -50,6 +49,8 @@ public:
boolean isDirectory(void);
File openNextFile(uint8_t mode = O_RDONLY);
void rewindDirectory(void);
+
+ using Print::write;
};
class SDClass {
@@ -61,7 +62,7 @@ private:
SdFile root;
// my quick&dirty iterator, should be replaced
- SdFile getParentDir(char *filepath, int *indx);
+ SdFile getParentDir(const char *filepath, int *indx);
public:
// This needs to be called to set up the connection to the SD card
// before other methods are used.
@@ -70,7 +71,7 @@ public:
// Open the specified file/directory with the supplied mode (e.g. read or
// write, etc). Returns a File object for interacting with the file.
// Note that currently only one file can be open at a time.
- File open(char *filename, uint8_t mode = FILE_READ);
+ File open(const char *filename, uint8_t mode = FILE_READ);
// Methods to determine if the requested file path exists.
boolean exists(char *filepath);
diff --git a/libraries/SD/examples/CardInfo/CardInfo.pde b/libraries/SD/examples/CardInfo/CardInfo.ino
index 7abfd33..fb2f6c3 100644
--- a/libraries/SD/examples/CardInfo/CardInfo.pde
+++ b/libraries/SD/examples/CardInfo/CardInfo.ino
@@ -80,7 +80,7 @@ void setup()
// print the type and size of the first FAT-type volume
- long volumesize;
+ uint32_t volumesize;
Serial.print("\nVolume type is FAT");
Serial.println(volume.fatType(), DEC);
Serial.println();
diff --git a/libraries/SD/examples/Datalogger/Datalogger.pde b/libraries/SD/examples/Datalogger/Datalogger.ino
index 73d81af..73d81af 100644
--- a/libraries/SD/examples/Datalogger/Datalogger.pde
+++ b/libraries/SD/examples/Datalogger/Datalogger.ino
diff --git a/libraries/SD/examples/DumpFile/DumpFile.pde b/libraries/SD/examples/DumpFile/DumpFile.ino
index 961717f..961717f 100644
--- a/libraries/SD/examples/DumpFile/DumpFile.pde
+++ b/libraries/SD/examples/DumpFile/DumpFile.ino
diff --git a/libraries/SD/examples/Files/Files.pde b/libraries/SD/examples/Files/Files.ino
index 5ed9fea..5ed9fea 100644
--- a/libraries/SD/examples/Files/Files.pde
+++ b/libraries/SD/examples/Files/Files.ino
diff --git a/libraries/SD/examples/ReadWrite/ReadWrite.pde b/libraries/SD/examples/ReadWrite/ReadWrite.ino
index 9957218..9957218 100644
--- a/libraries/SD/examples/ReadWrite/ReadWrite.pde
+++ b/libraries/SD/examples/ReadWrite/ReadWrite.ino
diff --git a/libraries/SD/examples/listfiles/listfiles.pde b/libraries/SD/examples/listfiles/listfiles.ino
index b2435a2..b2435a2 100644
--- a/libraries/SD/examples/listfiles/listfiles.pde
+++ b/libraries/SD/examples/listfiles/listfiles.ino
diff --git a/libraries/SD/utility/SdFat.h b/libraries/SD/utility/SdFat.h
index 048fa71..344326f 100644
--- a/libraries/SD/utility/SdFat.h
+++ b/libraries/SD/utility/SdFat.h
@@ -141,7 +141,7 @@ class SdFile : public Print {
* Set writeError to false before calling print() and/or write() and check
* for true after calls to print() and/or write().
*/
- bool writeError;
+ //bool writeError;
/**
* Cancel unbuffered reads for this file.
* See setUnbufferedRead()
@@ -283,9 +283,9 @@ class SdFile : public Print {
}
/** \return SdVolume that contains this file. */
SdVolume* volume(void) const {return vol_;}
- void write(uint8_t b);
- int16_t write(const void* buf, uint16_t nbyte);
- void write(const char* str);
+ size_t write(uint8_t b);
+ size_t write(const void* buf, uint16_t nbyte);
+ size_t write(const char* str);
void write_P(PGM_P str);
void writeln_P(PGM_P str);
//------------------------------------------------------------------------------
diff --git a/libraries/SD/utility/SdFatUtil.h b/libraries/SD/utility/SdFatUtil.h
index c626bfe..283fcb2 100644
--- a/libraries/SD/utility/SdFatUtil.h
+++ b/libraries/SD/utility/SdFatUtil.h
@@ -30,10 +30,11 @@
/** Store and print a string in flash memory followed by a CR/LF.*/
#define PgmPrintln(x) SerialPrintln_P(PSTR(x))
/** Defined so doxygen works for function definitions. */
-#define NOINLINE __attribute__((noinline))
+#define NOINLINE __attribute__((noinline,unused))
+#define UNUSEDOK __attribute__((unused))
//------------------------------------------------------------------------------
/** Return the number of bytes currently free in RAM. */
-static int FreeRam(void) {
+static UNUSEDOK int FreeRam(void) {
extern int __bss_end;
extern int* __brkval;
int free_memory;
diff --git a/libraries/SD/utility/SdFile.cpp b/libraries/SD/utility/SdFile.cpp
index 40444a7..e786f56 100644
--- a/libraries/SD/utility/SdFile.cpp
+++ b/libraries/SD/utility/SdFile.cpp
@@ -590,7 +590,7 @@ void SdFile::printDirName(const dir_t& dir, uint8_t width) {
Serial.print('.');
w++;
}
- Serial.print(dir.name[i]);
+ Serial.write(dir.name[i]);
w++;
}
if (DIR_IS_SUBDIR(&dir)) {
@@ -1121,7 +1121,7 @@ uint8_t SdFile::truncate(uint32_t length) {
* for a read-only file, device is full, a corrupt file system or an I/O error.
*
*/
-int16_t SdFile::write(const void* buf, uint16_t nbyte) {
+size_t SdFile::write(const void* buf, uint16_t nbyte) {
// convert void* to uint8_t* - must be before goto statements
const uint8_t* src = reinterpret_cast<const uint8_t*>(buf);
@@ -1210,8 +1210,9 @@ int16_t SdFile::write(const void* buf, uint16_t nbyte) {
writeErrorReturn:
// return for write error
- writeError = true;
- return -1;
+ //writeError = true;
+ setWriteError();
+ return 0;
}
//------------------------------------------------------------------------------
/**
@@ -1219,8 +1220,8 @@ int16_t SdFile::write(const void* buf, uint16_t nbyte) {
*
* Use SdFile::writeError to check for errors.
*/
-void SdFile::write(uint8_t b) {
- write(&b, 1);
+size_t SdFile::write(uint8_t b) {
+ return write(&b, 1);
}
//------------------------------------------------------------------------------
/**
@@ -1228,8 +1229,8 @@ void SdFile::write(uint8_t b) {
*
* Use SdFile::writeError to check for errors.
*/
-void SdFile::write(const char* str) {
- write(str, strlen(str));
+size_t SdFile::write(const char* str) {
+ return write(str, strlen(str));
}
//------------------------------------------------------------------------------
/**