Skip to content

Commit

Permalink
Be compatible to Arduino IDE > 1.5.0
Browse files Browse the repository at this point in the history
Based on PR #2 just with backwards compatibility
  • Loading branch information
Christopher Schirner committed Feb 24, 2015
1 parent 743943d commit a0c11f6
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions Flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,30 @@ class _Printable
class _FLASH_STRING : public _Printable
{
public:
#if ARDUINO >= 150
_FLASH_STRING(const char *arr PROGMEM);
#else
_FLASH_STRING(const prog_char *arr);
#endif

size_t length() const
{ return strlen_P(_arr); }

char *copy(char *to, size_t size = -1, size_t offset = 0) const
{
#if ARDUINO >= 150
return size == (size_t)-1 ?
#else
return size == -1 ?
#endif
strcpy_P(to, _arr + offset) : strncpy_P(to, _arr + offset, size);
}

const prog_char *access() const
{ return _arr; }
#if ARDUINO >= 150
const char *access() const PROGMEM { return _arr; }
#else
const prog_char *access() const { return _arr; }
#endif

const _Printable &Printable() const
{ return *this; }
Expand All @@ -90,7 +101,12 @@ class _FLASH_STRING : public _Printable
void print(Print &stream) const;

private:
#if ARDUINO >= 150
const char *_arr PROGMEM;
#else
const prog_char *_arr;
#endif

};

/* _FLASH_ARRAY template class. Use the FLASH_ARRAY() macro to create these. */
Expand Down Expand Up @@ -180,8 +196,11 @@ class _FLASH_TABLE : public _Printable
class _FLASH_STRING_ARRAY : public _Printable
{
public:
_FLASH_STRING_ARRAY(const prog_char **arr, size_t count) : _arr(arr), _size(count)
{ }
#if ARDUINO >= 150
_FLASH_STRING_ARRAY(const char **arr PROGMEM, size_t count) : _arr(arr), _size(count) {}
#else
_FLASH_STRING_ARRAY(const prog_char **arr, size_t count) : _arr(arr), _size(count) {}
#endif

size_t count() const
{ return _size; }
Expand All @@ -200,7 +219,12 @@ class _FLASH_STRING_ARRAY : public _Printable
}

private:
#if ARDUINO >= 150
const char **_arr PROGMEM;
#else
const prog_char **_arr;
#endif

size_t _size;
};

Expand Down Expand Up @@ -230,4 +254,4 @@ inline Print &operator <<(Print &stream, const _FLASH_TABLE<T> &printable)
inline Print &operator <<(Print &stream, const _FLASH_STRING_ARRAY &printable)
{ printable.print(stream); return stream; }

#endif // def __FLASH_H__
#endif // def __FLASH_H__

0 comments on commit a0c11f6

Please sign in to comment.