2018-02-18 01:44:04 +00:00
|
|
|
#include "teensy-prefs.h"
|
|
|
|
|
2020-12-29 02:48:00 +00:00
|
|
|
#include <Arduino.h>
|
2018-02-18 01:44:04 +00:00
|
|
|
#include <EEPROM.h>
|
|
|
|
|
|
|
|
TeensyPrefs::TeensyPrefs()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
TeensyPrefs::~TeensyPrefs()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TeensyPrefs::readPrefs(prefs_t *readTo)
|
|
|
|
{
|
|
|
|
uint8_t *pp = (uint8_t *)readTo;
|
|
|
|
for (uint16_t i=0; i<sizeof(prefs_t); i++) {
|
|
|
|
*pp++ = EEPROM.read(i);
|
|
|
|
}
|
|
|
|
|
2021-01-19 23:40:13 +00:00
|
|
|
if (readTo->magic != PREFSMAGIC ||
|
|
|
|
readTo->magicFooter != PREFSMAGIC) {
|
2018-02-18 01:44:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (readTo->prefsSize != sizeof(prefs_t)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (readTo->version != PREFSVERSION) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TeensyPrefs::writePrefs(prefs_t *newPrefs)
|
|
|
|
{
|
|
|
|
uint8_t *pp = (uint8_t *)newPrefs;
|
|
|
|
for (uint16_t i=0; i<sizeof(prefs_t); i++) {
|
|
|
|
EEPROM.write(i, *pp++);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|