From 22d4535e79e09416c48ec0bdbb3e18b1c3ea3430 Mon Sep 17 00:00:00 2001 From: Ken <> Date: Wed, 30 Oct 2019 01:00:35 -0400 Subject: [PATCH 1/4] Fix EEPROM saving issue when issuing a RESET command via a serial terminal. --- firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.cpp | 3 +++ firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.h | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) 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 9472c15..76e33b3 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 @@ -12,6 +12,9 @@ long voltMeterConstant = VM_CONST_DEFAULT; uint8_t pP_i2c_address = 0xa0; void resetEEPROM() { + + resetConfig(); + EEPROM.put(GAIN_FACTOR_ADDRESS, GAIN_FACTOR); EEPROM.put(FOLLOWER_THRESHOLD_ADDRESS, followerThrs); EEPROM.put(COMP_THRESHOLD_ADDRESS, compThrs); diff --git a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.h b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.h index 406db87..b5d57f1 100644 --- a/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.h +++ b/firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.h @@ -61,6 +61,7 @@ #endif void resetEEPROM(); +void resetConfig(); void restoreConfig(); -#endif \ No newline at end of file +#endif From 13d8b32b59bb481768c44eed08d2fb6476c72a4b Mon Sep 17 00:00:00 2001 From: Ken <> Date: Wed, 30 Oct 2019 01:06:44 -0400 Subject: [PATCH 2/4] Update .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 0d7fe64..8adcc0f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ Eagle_Files/**/*.B\#* Eagle_Files/**/*.s\#* docs/**/*.odt\#* site/* +ICSP Pinout.png +SparkFun Programmer Pinout.png From 7cdb535fdfc5b6280eab2265c2807bb9298b60f7 Mon Sep 17 00:00:00 2001 From: Ken <> Date: Wed, 30 Oct 2019 01:26:39 -0400 Subject: [PATCH 3/4] Update .gitignore --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index 8adcc0f..0d7fe64 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,3 @@ Eagle_Files/**/*.B\#* Eagle_Files/**/*.s\#* docs/**/*.odt\#* site/* -ICSP Pinout.png -SparkFun Programmer Pinout.png From 0e7862c3c48773e81af0f31992e36e410a1f1e11 Mon Sep 17 00:00:00 2001 From: Ken <> Date: Wed, 30 Oct 2019 02:00:36 -0400 Subject: [PATCH 4/4] 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() {