From 8e6d333ee8e7e310115eae646f6f8bf196e9b850 Mon Sep 17 00:00:00 2001 From: "Jeroen F.J. Laros" Date: Sat, 3 Sep 2022 14:59:40 +0200 Subject: [PATCH] Added EEPROM support for `char*`, `char const*` and `String`. --- libraries/EEPROM/src/EEPROM.h | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/libraries/EEPROM/src/EEPROM.h b/libraries/EEPROM/src/EEPROM.h index c8ec271be..07c2cff09 100644 --- a/libraries/EEPROM/src/EEPROM.h +++ b/libraries/EEPROM/src/EEPROM.h @@ -133,13 +133,40 @@ struct EEPROMClass{ for( int count = sizeof(T) ; count ; --count, ++e ) *ptr++ = *e; return t; } - + + String& get(int idx, String& data) { + data = ""; + char c; + for (size_t i = idx; (c = get(i, c)); i++) { + data += c; + } + return data; + } + template< typename T > const T &put( int idx, const T &t ){ EEPtr e = idx; const uint8_t *ptr = (const uint8_t*) &t; for( int count = sizeof(T) ; count ; --count, ++e ) (*e).update( *ptr++ ); return t; } + + char* put(int idx, char* data) { + size_t i; + for (i = 0; data[i]; i++) { + put(idx + i, data[i]); + } + put (idx + i, '\x00'); + return data; + } + + char const* put(int idx, char const* data) { + return put(idx, const_cast(data)); + } + + String& put(int idx, String& data) { + put(idx, data.c_str()); + return data; + } }; static EEPROMClass EEPROM;