Skip to content

Commit

Permalink
This code change reduces the amount of EEPROM writes that could poten…
Browse files Browse the repository at this point in the history
…tially occur within a short period of time, thus making the EEPROM last longer.
  • Loading branch information
Ken committed Oct 30, 2019
1 parent 7cdb535 commit 0e7862c
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.cpp
Expand Up @@ -27,56 +27,62 @@ 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;
}

long longTemp;
EEPROM.get(VM_CONST_ADDRESS, longTemp);
if (longTemp < 1000000L || longTemp > 1200000L) {
resetEEPROM();
reset = true;
} else {
voltMeterConstant = longTemp;
}

if (reset) {
resetEEPROM();
}
}

void resetConfig() {
Expand Down

0 comments on commit 0e7862c

Please sign in to comment.