Permalink
Browse files

Arduino 1.0 compliant

  • Loading branch information...
1 parent 562defe commit 587d4ec2121667f2a9f85a2419d397eea072db51 @PaintYourDragon PaintYourDragon committed Dec 3, 2011
Showing with 76 additions and 5 deletions.
  1. +27 −0 File.cpp
  2. +11 −1 SD.h
  3. +5 −1 utility/Sd2Card.cpp
  4. +6 −0 utility/SdFat.h
  5. +6 −2 utility/SdFatUtil.h
  6. +21 −1 utility/SdFile.cpp
View
@@ -58,6 +58,31 @@ boolean File::isDirectory(void) {
}
+#if ARDUINO >= 100
+
+size_t File::write(uint8_t val) {
+ if (_file)
+ return _file->write(val);
+ else
+ return 0;
+}
+
+size_t File::write(const char *str) {
+ if (_file)
+ return _file->write(str);
+ else
+ return 0;
+}
+
+size_t File::write(const uint8_t *buf, size_t size) {
+ if (_file)
+ return _file->write(buf, size);
+ else
+ return 0;
+}
+
+#else
+
void File::write(uint8_t val) {
if (_file)
_file->write(val);
@@ -73,6 +98,8 @@ void File::write(const uint8_t *buf, size_t size) {
_file->write(buf, size);
}
+#endif // ARDUINO
+
int File::peek() {
if (! _file)
return 0;
View
12 SD.h
@@ -15,7 +15,11 @@
#ifndef __SD_H__
#define __SD_H__
-#include <WProgram.h>
+#if ARDUINO >= 100
+ #include "Arduino.h"
+#else
+ #include "WProgram.h"
+#endif
#include <utility/SdFat.h>
#include <utility/SdFatUtil.h>
@@ -32,9 +36,15 @@ class File : public Stream {
File(SdFile f, char *name); // wraps an underlying SdFile
File(void); // 'empty' constructor
~File(void); // destructor
+#if ARDUINO >= 100
+ virtual size_t write(uint8_t);
+ virtual size_t write(const char *str);
+ virtual size_t write(const uint8_t *buf, size_t size);
+#else
virtual void write(uint8_t);
virtual void write(const char *str);
virtual void write(const uint8_t *buf, size_t size);
+#endif
virtual int read();
virtual int peek();
virtual int available();
View
@@ -17,7 +17,11 @@
* along with the Arduino Sd2Card Library. If not, see
* <http://www.gnu.org/licenses/>.
*/
-#include <WProgram.h>
+#if ARDUINO >= 100
+ #include "Arduino.h"
+#else
+ #include "WProgram.h"
+#endif
#include "Sd2Card.h"
//------------------------------------------------------------------------------
#ifndef SOFTWARE_SPI
View
@@ -283,9 +283,15 @@ 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);
+ size_t write(const void* buf, uint16_t nbyte);
+ size_t write(const char* str);
+#else
void write(uint8_t b);
int16_t write(const void* buf, uint16_t nbyte);
void write(const char* str);
+#endif
void write_P(PGM_P str);
void writeln_P(PGM_P str);
//------------------------------------------------------------------------------
View
@@ -23,8 +23,12 @@
* \file
* Useful utility functions.
*/
-#include <WProgram.h>
-#include <avr/pgmspace.h>
+#if ARDUINO >= 100
+ #include "Arduino.h"
+#else
+ #include "WProgram.h"
+ #include <avr/pgmspace.h>
+#endif
/** Store and print a string in flash memory.*/
#define PgmPrint(x) SerialPrint_P(PSTR(x))
/** Store and print a string in flash memory followed by a CR/LF.*/
View
@@ -19,7 +19,11 @@
*/
#include <SdFat.h>
#include <avr/pgmspace.h>
-#include <WProgram.h>
+#if ARDUINO >= 100
+ #include "Arduino.h"
+#else
+ #include "WProgram.h"
+#endif
//------------------------------------------------------------------------------
// callback function for date/time
void (*SdFile::dateTime_)(uint16_t* date, uint16_t* time) = NULL;
@@ -1121,7 +1125,11 @@ uint8_t SdFile::truncate(uint32_t length) {
* for a read-only file, device is full, a corrupt file system or an I/O error.
*
*/
+#if ARDUINO >= 100
+size_t SdFile::write(const void* buf, uint16_t nbyte) {
+#else
int16_t SdFile::write(const void* buf, uint16_t nbyte) {
+#endif
// convert void* to uint8_t* - must be before goto statements
const uint8_t* src = reinterpret_cast<const uint8_t*>(buf);
@@ -1219,18 +1227,30 @@ int16_t SdFile::write(const void* buf, uint16_t nbyte) {
*
* Use SdFile::writeError to check for errors.
*/
+#if ARDUINO >= 100
+size_t SdFile::write(uint8_t b) {
+ return write(&b, 1);
+}
+#else
void SdFile::write(uint8_t b) {
write(&b, 1);
}
+#endif
//------------------------------------------------------------------------------
/**
* Write a string to a file. Used by the Arduino Print class.
*
* Use SdFile::writeError to check for errors.
*/
+#if ARDUINO >= 100
+size_t SdFile::write(const char* str) {
+ return write(str, strlen(str));
+}
+#else
void SdFile::write(const char* str) {
write(str, strlen(str));
}
+#endif
//------------------------------------------------------------------------------
/**
* Write a PROGMEM string to a file.

0 comments on commit 587d4ec

Please sign in to comment.