Skip to content
This repository has been archived by the owner on Jul 25, 2019. It is now read-only.

Commit

Permalink
a real mess, totally in progress. does not work!
Browse files Browse the repository at this point in the history
  • Loading branch information
ladyada committed Feb 23, 2011
1 parent b707f7a commit dc336d1
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 330 deletions.
63 changes: 41 additions & 22 deletions File.cpp
Expand Up @@ -14,65 +14,84 @@

#include <SD.h>

File::File(SdFile f, char *n) {
_file = f;
strncpy(_name, n, 12);
_name[12] = 0;
_c = -1;
}

File::File(void) {
_c = -1;
}

char *File::name(void) {
return _name;
};

boolean File::isDirectory(void) {
return _file.isDir();
}

void File::write(uint8_t val) {
SD.file.write(val);
_file.write(val);
}

void File::write(const char *str) {
SD.file.write(str);
_file.write(str);
}

void File::write(const uint8_t *buf, size_t size) {
SD.file.write(buf, size);
_file.write(buf, size);
}

int File::peek() {
if (SD.c != -1) return SD.c;
SD.c = SD.file.read();
return SD.c;
if (_c != -1) return _c;
_c = _file.read();
return _c;
}

boolean File::seekSet(uint32_t pos) {
return SD.file.seekSet(pos);
return _file.seekSet(pos);
}

uint32_t File::size(void) {
return SD.file.fileSize();
return _file.fileSize();
}


int File::read() {
if (SD.c != -1) {
int tmp = SD.c;
SD.c = -1;
if (_c != -1) {
int tmp = _c;
_c = -1;
return tmp;
}
return SD.file.read();
return _file.read();
}

int File::read(void *buf, uint16_t nbyte) {
if ((SD.c != -1) && (nbyte > 0)) {
if ((_c != -1) && (nbyte > 0)) {
((char *)buf)[0] = SD.c;
SD.c = -1;
return SD.file.read(((char *)buf)+1, nbyte-1);
_c = -1;
return _file.read(((char *)buf)+1, nbyte-1);
}
return SD.file.read(buf, nbyte);
return _file.read(buf, nbyte);
}

int File::available() {
if (SD.c != -1) return 1;
SD.c = SD.file.read();
return SD.c != -1;
if (_c != -1) return 1;
_c = _file.read();
return _c != -1;
}

void File::flush() {
SD.file.sync();
_file.sync();
}

void File::close() {
SD.file.close();
_file.close();
}

File::operator bool() {
return SD.file.isOpen();
return _file.isOpen();
}

0 comments on commit dc336d1

Please sign in to comment.