From 0e7862c3c48773e81af0f31992e36e410a1f1e11 Mon Sep 17 00:00:00 2001 From: Ken <> Date: Wed, 30 Oct 2019 02:00:36 -0400 Subject: [PATCH] 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. --- .../src/pP_config.cpp | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.cpp b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.cpp index 76e33b3..4c38f21 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.cpp +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.cpp @@ -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() {