From b4911b203af268005f82dd1dd3eee19fd01cb35d Mon Sep 17 00:00:00 2001 From: Changwoo Ryu Date: Mon, 27 Feb 2012 00:26:37 +0900 Subject: Correct SD for Arduino 1.0 compatibility With Arduino 1.0 Print class: - write() should return, and - print() with a uint_8 or int_8 character argument does not call print(char) anymore. So character argument should be casted to 'char' explicitly. --- Sprinter/SdFat.h | 4 ++++ Sprinter/SdFatUtil.h | 2 +- Sprinter/SdFile.cpp | 33 +++++++++++++++++++++------------ 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/Sprinter/SdFat.h b/Sprinter/SdFat.h index 048fa71..7a11bba 100644 --- a/Sprinter/SdFat.h +++ b/Sprinter/SdFat.h @@ -283,7 +283,11 @@ class SdFile : public Print { } /** \return SdVolume that contains this file. */ SdVolume* volume(void) const {return vol_;} +#if ARDUINO >= 100 + size_t write(uint8_t b); +#else void write(uint8_t b); +#endif int16_t write(const void* buf, uint16_t nbyte); void write(const char* str); void write_P(PGM_P str); diff --git a/Sprinter/SdFatUtil.h b/Sprinter/SdFatUtil.h index 8bf9048..de3fee3 100644 --- a/Sprinter/SdFatUtil.h +++ b/Sprinter/SdFatUtil.h @@ -55,7 +55,7 @@ static int FreeRam(void) { * \param[in] str Pointer to string stored in flash memory. */ static NOINLINE void SerialPrint_P(PGM_P str) { - for (uint8_t c; (c = pgm_read_byte(str)); str++) Serial.print(c); + for (uint8_t c; (c = pgm_read_byte(str)); str++) Serial.print(char(c)); } //------------------------------------------------------------------------------ /** diff --git a/Sprinter/SdFile.cpp b/Sprinter/SdFile.cpp index 0a27159..13f4c6a 100644 --- a/Sprinter/SdFile.cpp +++ b/Sprinter/SdFile.cpp @@ -213,7 +213,7 @@ void SdFile::ls(uint8_t flags, uint8_t indent) { if (!DIR_IS_FILE_OR_SUBDIR(p)) continue; // print any indent spaces - for (int8_t i = 0; i < indent; i++) Serial.print(' '); + for (int8_t i = 0; i < indent; i++) Serial.print(char(' ')); // print file name with possible blank fill printDirName(*p, flags & (LS_DATE | LS_SIZE) ? 14 : 0); @@ -221,12 +221,12 @@ void SdFile::ls(uint8_t flags, uint8_t indent) { // print modify date/time if requested if (flags & LS_DATE) { printFatDate(p->lastWriteDate); - Serial.print(' '); + Serial.print(char(' ')); printFatTime(p->lastWriteTime); } // print size if requested if (!DIR_IS_SUBDIR(p) && (flags & LS_SIZE)) { - Serial.print(' '); + Serial.print(char(' ')); Serial.print(p->fileSize); } Serial.println(); @@ -587,18 +587,18 @@ void SdFile::printDirName(const dir_t& dir, uint8_t width) { for (uint8_t i = 0; i < 11; i++) { if (dir.name[i] == ' ')continue; if (i == 8) { - Serial.print('.'); + Serial.print(char('.')); w++; } - Serial.print(dir.name[i]); + Serial.print(char(dir.name[i])); w++; } if (DIR_IS_SUBDIR(&dir)) { - Serial.print('/'); + Serial.print(char('/')); w++; } while (w < width) { - Serial.print(' '); + Serial.print(char(' ')); w++; } } @@ -611,9 +611,9 @@ void SdFile::printDirName(const dir_t& dir, uint8_t width) { */ void SdFile::printFatDate(uint16_t fatDate) { Serial.print(FAT_YEAR(fatDate)); - Serial.print('-'); + Serial.print(char('-')); printTwoDigits(FAT_MONTH(fatDate)); - Serial.print('-'); + Serial.print(char('-')); printTwoDigits(FAT_DAY(fatDate)); } //------------------------------------------------------------------------------ @@ -625,9 +625,9 @@ void SdFile::printFatDate(uint16_t fatDate) { */ void SdFile::printFatTime(uint16_t fatTime) { printTwoDigits(FAT_HOUR(fatTime)); - Serial.print(':'); + Serial.print(char(':')); printTwoDigits(FAT_MINUTE(fatTime)); - Serial.print(':'); + Serial.print(char(':')); printTwoDigits(FAT_SECOND(fatTime)); } //------------------------------------------------------------------------------ @@ -1219,8 +1219,17 @@ int16_t SdFile::write(const void* buf, uint16_t nbyte) { * * Use SdFile::writeError to check for errors. */ -void SdFile::write(uint8_t b) { +#if ARDUINO >= 100 +size_t SdFile::write(uint8_t b) +#else +void SdFile::write(uint8_t b) +#endif +{ +#if ARDUINO >= 100 + return (size_t) write(&b, 1); +#else write(&b, 1); +#endif } //------------------------------------------------------------------------------ /** -- cgit v1.2.1