Permalink
Browse files

fresh start :/

  • Loading branch information...
1 parent 0921399 commit bc9237707efb5d13350f10e2d8c80f58e1fdb157 @ladyada ladyada committed Mar 9, 2011
Showing with 333 additions and 302 deletions.
  1. +20 −106 File.cpp
  2. +296 −159 SD.cpp
  3. +9 −28 SD.h
  4. +3 −2 examples/Datalogger/Datalogger.pde
  5. +1 −1 examples/Files/Files.pde
  6. +3 −2 examples/ReadWrite/ReadWrite.pde
  7. +1 −3 utility/SdFat.h
  8. +0 −1 utility/SdFile.cpp
View
126 File.cpp
@@ -9,143 +9,57 @@
(Because sdfatlib is licensed with this.)
(C) Copyright 2010 SparkFun Electronics
- Multi-file support and some extras added by Limor Fried
*/
#include <SD.h>
-/* for debugging file open/close leaks
- uint8_t nfilecount=0;
-*/
-
-File::File(SdFile f, char *n) {
- // oh man you are kidding me, new() doesnt exist? Ok we do it by hand!
- _file = (SdFile *)malloc(sizeof(SdFile));
- if (_file) {
- memcpy(_file, &f, sizeof(SdFile));
-
- strncpy(_name, n, 12);
- _name[12] = 0;
- _c = -1;
-
- /* for debugging file open/close leaks
- nfilecount++;
- Serial.print("Created \"");
- Serial.print(n);
- Serial.print("\": ");
- Serial.println(nfilecount, DEC);
- */
- }
-}
-
-File::File(void) {
- _c = -1;
- _file = 0;
- _name[0] = 0;
- //Serial.print("Created empty file object");
-}
-
-File::~File(void) {
- // Serial.print("Deleted file object");
-}
-
-char *File::name(void) {
- return _name;
-};
-
-boolean File::isDirectory(void) {
- return (_file && _file->isDir());
-}
-
void File::write(uint8_t val) {
- if (_file)
- _file->write(val);
+ SD.file.write(val);
}
void File::write(const char *str) {
- if (_file)
- _file->write(str);
+ SD.file.write(str);
}
void File::write(const uint8_t *buf, size_t size) {
- if (_file)
- _file->write(buf, size);
+ SD.file.write(buf, size);
}
int File::peek() {
- if (!_file)
- return 0;
-
- if (_c != -1)
- return _c;
- _c = _file->read();
- return _c;
+ int c = SD.file.read();
+ if (c != -1) SD.file.seekCur(-1);
+ return c;
}
-boolean File::seekSet(uint32_t pos) {
- return (_file && _file->seekSet(pos));
+int File::read() {
+ return SD.file.read();
}
-uint32_t File::size(void) {
- if (_file)
- return _file->fileSize();
- return 0;
+int File::available() {
+ return size() - position();
}
-
-int File::read() {
- if (!_file)
- return 0;
-
- if (_c != -1) {
- int tmp = _c;
- _c = -1;
- return tmp;
- }
- return _file->read();
+void File::flush() {
+ SD.file.sync();
}
-int File::read(void *buf, uint16_t nbyte) {
- if (!_file)
- return 0;
-
- if ((_c != -1) && (nbyte > 0)) {
- ((char *)buf)[0] = SD.c;
- _c = -1;
- return _file->read(((char *)buf)+1, nbyte-1);
- }
- return _file->read(buf, nbyte);
+boolean File::seek(uint32_t pos) {
+ return SD.file.seekSet(pos);
}
-int File::available() {
- if (_c != -1)
- return 1;
- if (! _file)
- return 0;
- _c = _file->read();
- return _c != -1;
+uint32_t File::position() {
+ return SD.file.curPosition();
}
-void File::flush() {
- if (_file)
- _file->sync();
+uint32_t File::size() {
+ return SD.file.fileSize();
}
void File::close() {
- if (_file) {
- _file->close();
- free(_file);
- _file = 0;
-
- /* for debugging file open/close leaks
- nfilecount--;
- Serial.print("Deleted ");
- Serial.println(nfilecount, DEC);
- */
- }
+ SD.file.close();
}
File::operator bool() {
- return (_file && _file->isOpen());
+ return SD.file.isOpen();
}
Oops, something went wrong.

0 comments on commit bc92377

Please sign in to comment.