Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added EEPROM support for char*, char const* and String. #496

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading