This code change reduces the amount of EEPROM writes that could potentially occur within a short period of time, thus making the EEPROM last longer.

This commit is contained in:
Ken 2019-10-30 02:00:36 -04:00
parent 7cdb535fdf
commit 0e7862c3c4

View file

@ -27,45 +27,47 @@ void resetEEPROM() {
// Restore config from EEPROM, otherwise reset config and write to EEPROM
void restoreConfig() {
int temp;
bool reset = false;
EEPROM.get(GAIN_FACTOR_ADDRESS, temp);
if (temp < 0 || temp > 4) {
resetEEPROM();
reset = true;
} else {
GAIN_FACTOR = temp;
}
EEPROM.get(FOLLOWER_THRESHOLD_ADDRESS, temp);
if (temp < 0 || temp > 5000) {
resetEEPROM();
reset = true;
} else {
followerThrs = temp;
}
EEPROM.get(COMP_THRESHOLD_ADDRESS, temp);
if (temp < 0 || temp > 5000) {
resetEEPROM();
reset = true;
} else {
compThrs = temp;
}
EEPROM.get(LOOP_DUR_ADDRESS, temp);
if (temp < 0 && temp > 1000) {
resetEEPROM();
reset = true;
} else {
LOOP_DUR = temp;
}
EEPROM.get(TRG_DUR_ADDRESS, temp);
if (temp < 0 || temp > 1000) {
resetEEPROM();
reset = true;
} else {
TRG_DUR = temp;
}
EEPROM.get(HYST_ADDRESS, temp);
if (temp < 0 || temp > 1000) {
resetEEPROM();
reset = true;
} else {
Hyst = temp;
}
@ -73,10 +75,14 @@ void restoreConfig() {
long longTemp;
EEPROM.get(VM_CONST_ADDRESS, longTemp);
if (longTemp < 1000000L || longTemp > 1200000L) {
resetEEPROM();
reset = true;
} else {
voltMeterConstant = longTemp;
}
if (reset) {
resetEEPROM();
}
}
void resetConfig() {