|
|
@ -23,33 +23,33 @@ namespace KaleidoscopePlugins {
|
|
|
|
struct EEPROMSettings::settings EEPROMSettings::settings;
|
|
|
|
struct EEPROMSettings::settings EEPROMSettings::settings;
|
|
|
|
bool EEPROMSettings::_isValid;
|
|
|
|
bool EEPROMSettings::_isValid;
|
|
|
|
bool EEPROMSettings::sealed;
|
|
|
|
bool EEPROMSettings::sealed;
|
|
|
|
uint16_t EEPROMSettings::nextStart = sizeof (EEPROMSettings::settings);
|
|
|
|
uint16_t EEPROMSettings::nextStart = sizeof(EEPROMSettings::settings);
|
|
|
|
|
|
|
|
|
|
|
|
EEPROMSettings::EEPROMSettings (void) {
|
|
|
|
EEPROMSettings::EEPROMSettings(void) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
EEPROMSettings::begin (void) {
|
|
|
|
EEPROMSettings::begin(void) {
|
|
|
|
EEPROM.get (0, settings);
|
|
|
|
EEPROM.get(0, settings);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
bool
|
|
|
|
EEPROMSettings::isValid (void) {
|
|
|
|
EEPROMSettings::isValid(void) {
|
|
|
|
return _isValid;
|
|
|
|
return _isValid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t
|
|
|
|
uint16_t
|
|
|
|
EEPROMSettings::crc (void) {
|
|
|
|
EEPROMSettings::crc(void) {
|
|
|
|
if (sealed)
|
|
|
|
if (sealed)
|
|
|
|
return settings.crc;
|
|
|
|
return settings.crc;
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
EEPROMSettings::seal (void) {
|
|
|
|
EEPROMSettings::seal(void) {
|
|
|
|
sealed = true;
|
|
|
|
sealed = true;
|
|
|
|
|
|
|
|
|
|
|
|
CRC.finalize ();
|
|
|
|
CRC.finalize();
|
|
|
|
|
|
|
|
|
|
|
|
if (settings.magic[0] != 'K' || settings.magic[1] != 'S') {
|
|
|
|
if (settings.magic[0] != 'K' || settings.magic[1] != 'S') {
|
|
|
|
settings.magic[0] = 'K';
|
|
|
|
settings.magic[0] = 'K';
|
|
|
@ -57,7 +57,7 @@ EEPROMSettings::seal (void) {
|
|
|
|
settings.version = 0;
|
|
|
|
settings.version = 0;
|
|
|
|
settings.crc = CRC.crc;
|
|
|
|
settings.crc = CRC.crc;
|
|
|
|
|
|
|
|
|
|
|
|
return update ();
|
|
|
|
return update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (settings.crc != CRC.crc)
|
|
|
|
if (settings.crc != CRC.crc)
|
|
|
@ -65,45 +65,45 @@ EEPROMSettings::seal (void) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t
|
|
|
|
uint16_t
|
|
|
|
EEPROMSettings::requestSlice (uint16_t size) {
|
|
|
|
EEPROMSettings::requestSlice(uint16_t size) {
|
|
|
|
if (sealed)
|
|
|
|
if (sealed)
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t start = nextStart;
|
|
|
|
uint16_t start = nextStart;
|
|
|
|
nextStart += size;
|
|
|
|
nextStart += size;
|
|
|
|
|
|
|
|
|
|
|
|
CRC.update ((const void *)&size, sizeof (size));
|
|
|
|
CRC.update((const void *)&size, sizeof(size));
|
|
|
|
|
|
|
|
|
|
|
|
return start;
|
|
|
|
return start;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
EEPROMSettings::invalidate (void) {
|
|
|
|
EEPROMSettings::invalidate(void) {
|
|
|
|
_isValid = false;
|
|
|
|
_isValid = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint16_t
|
|
|
|
uint16_t
|
|
|
|
EEPROMSettings::used (void) {
|
|
|
|
EEPROMSettings::used(void) {
|
|
|
|
return nextStart;
|
|
|
|
return nextStart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
EEPROMSettings::update (void) {
|
|
|
|
EEPROMSettings::update(void) {
|
|
|
|
settings.crc = CRC.crc;
|
|
|
|
settings.crc = CRC.crc;
|
|
|
|
|
|
|
|
|
|
|
|
EEPROM.put (0, settings);
|
|
|
|
EEPROM.put(0, settings);
|
|
|
|
_isValid = true;
|
|
|
|
_isValid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t
|
|
|
|
uint8_t
|
|
|
|
EEPROMSettings::version (void) {
|
|
|
|
EEPROMSettings::version(void) {
|
|
|
|
return settings.version;
|
|
|
|
return settings.version;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
EEPROMSettings::version (uint8_t ver) {
|
|
|
|
EEPROMSettings::version(uint8_t ver) {
|
|
|
|
settings.version = ver;
|
|
|
|
settings.version = ver;
|
|
|
|
update ();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|