Skip to content

Commit

Permalink
Added EEPROM support for char*, char const* and String.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfjlaros committed Sep 3, 2022
1 parent 3cd6c80 commit fcb276c
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion libraries/EEPROM/src/EEPROM.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<char*>(data));
}

String& put(int idx, String& data) {
put(idx, data.c_str());
return data;
}
};

static EEPROMClass EEPROM;
Expand Down

0 comments on commit fcb276c

Please sign in to comment.