1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-16 11:21:18 +03:00

Revert "Merge branch 'master' of github.com:arduino/Arduino into diskloader_reboot"

This reverts commit df9835efaf, reversing
changes made to ec45af8bfa.

Conflicts:

	hardware/arduino/variants/mega/pins_arduino.h
	libraries/Ethernet/examples/PachubeClientString/PachubeClientString.ino
This commit is contained in:
Zach Eveland
2011-10-27 11:45:13 -04:00
parent f2bd8a5394
commit a6a59f1783
40 changed files with 1917 additions and 2221 deletions

View File

@ -14,52 +14,137 @@
#include <SD.h>
void File::write(uint8_t val) {
SD.file.write(val);
/* for debugging file open/close leaks
uint8_t nfilecount=0;
*/
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) {
memcpy(_file, &f, sizeof(SdFile));
strncpy(_name, n, 12);
_name[12] = 0;
/* for debugging file open/close leaks
nfilecount++;
Serial.print("Created \"");
Serial.print(n);
Serial.print("\": ");
Serial.println(nfilecount, DEC);
*/
}
}
void File::write(const char *str) {
SD.file.write(str);
File::File(void) {
_file = 0;
_name[0] = 0;
//Serial.print("Created empty file object");
}
void File::write(const uint8_t *buf, size_t size) {
SD.file.write(buf, size);
File::~File(void) {
// Serial.print("Deleted file object");
}
// returns a pointer to the file name
char *File::name(void) {
return _name;
}
// a directory is a special type of file
boolean File::isDirectory(void) {
return (_file && _file->isDir());
}
size_t File::write(uint8_t val) {
return write(&val, 1);
}
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() {
int c = SD.file.read();
if (c != -1) SD.file.seekCur(-1);
if (! _file)
return 0;
int c = _file->read();
if (c != -1) _file->seekCur(-1);
return c;
}
int File::read() {
return SD.file.read();
if (_file)
return _file->read();
return -1;
}
// buffered read for more efficient, high speed reading
int File::read(void *buf, uint16_t nbyte) {
if (_file)
return _file->read(buf, nbyte);
return 0;
}
int File::available() {
return size() - position();
if (! _file) return 0;
uint32_t n = size() - position();
return n > 0X7FFF ? 0X7FFF : n;
}
void File::flush() {
SD.file.sync();
if (_file)
_file->sync();
}
boolean File::seek(uint32_t pos) {
return SD.file.seekSet(pos);
if (! _file) return false;
return _file->seekSet(pos);
}
uint32_t File::position() {
return SD.file.curPosition();
if (! _file) return -1;
return _file->curPosition();
}
uint32_t File::size() {
return SD.file.fileSize();
if (! _file) return 0;
return _file->fileSize();
}
void File::close() {
SD.file.close();
if (_file) {
_file->close();
free(_file);
_file = 0;
/* for debugging file open/close leaks
nfilecount--;
Serial.print("Deleted ");
Serial.println(nfilecount, DEC);
*/
}
}
File::operator bool() {
return SD.file.isOpen();
if (_file)
return _file->isOpen();
return false;
}