Merge pull request #57 from klcjr89/master

Fix EEPROM saving issue when issuing a RESET command via a serial ter…
This commit is contained in:
Alan Weinstock 2019-10-30 09:56:26 -07:00 committed by GitHub
commit 61d7bd659b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 8 deletions

View file

@ -12,6 +12,9 @@ long voltMeterConstant = VM_CONST_DEFAULT;
uint8_t pP_i2c_address = 0xa0; uint8_t pP_i2c_address = 0xa0;
void resetEEPROM() { void resetEEPROM() {
resetConfig();
EEPROM.put(GAIN_FACTOR_ADDRESS, GAIN_FACTOR); EEPROM.put(GAIN_FACTOR_ADDRESS, GAIN_FACTOR);
EEPROM.put(FOLLOWER_THRESHOLD_ADDRESS, followerThrs); EEPROM.put(FOLLOWER_THRESHOLD_ADDRESS, followerThrs);
EEPROM.put(COMP_THRESHOLD_ADDRESS, compThrs); EEPROM.put(COMP_THRESHOLD_ADDRESS, compThrs);
@ -25,44 +28,46 @@ void resetEEPROM() {
void restoreConfig() { void restoreConfig() {
int temp; int temp;
bool reset = false;
EEPROM.get(GAIN_FACTOR_ADDRESS, temp); EEPROM.get(GAIN_FACTOR_ADDRESS, temp);
if (temp < 0 || temp > 4) { if (temp < 0 || temp > 4) {
resetEEPROM(); reset = true;
} else { } else {
GAIN_FACTOR = temp; GAIN_FACTOR = temp;
} }
EEPROM.get(FOLLOWER_THRESHOLD_ADDRESS, temp); EEPROM.get(FOLLOWER_THRESHOLD_ADDRESS, temp);
if (temp < 0 || temp > 5000) { if (temp < 0 || temp > 5000) {
resetEEPROM(); reset = true;
} else { } else {
followerThrs = temp; followerThrs = temp;
} }
EEPROM.get(COMP_THRESHOLD_ADDRESS, temp); EEPROM.get(COMP_THRESHOLD_ADDRESS, temp);
if (temp < 0 || temp > 5000) { if (temp < 0 || temp > 5000) {
resetEEPROM(); reset = true;
} else { } else {
compThrs = temp; compThrs = temp;
} }
EEPROM.get(LOOP_DUR_ADDRESS, temp); EEPROM.get(LOOP_DUR_ADDRESS, temp);
if (temp < 0 && temp > 1000) { if (temp < 0 && temp > 1000) {
resetEEPROM(); reset = true;
} else { } else {
LOOP_DUR = temp; LOOP_DUR = temp;
} }
EEPROM.get(TRG_DUR_ADDRESS, temp); EEPROM.get(TRG_DUR_ADDRESS, temp);
if (temp < 0 || temp > 1000) { if (temp < 0 || temp > 1000) {
resetEEPROM(); reset = true;
} else { } else {
TRG_DUR = temp; TRG_DUR = temp;
} }
EEPROM.get(HYST_ADDRESS, temp); EEPROM.get(HYST_ADDRESS, temp);
if (temp < 0 || temp > 1000) { if (temp < 0 || temp > 1000) {
resetEEPROM(); reset = true;
} else { } else {
Hyst = temp; Hyst = temp;
} }
@ -70,10 +75,14 @@ void restoreConfig() {
long longTemp; long longTemp;
EEPROM.get(VM_CONST_ADDRESS, longTemp); EEPROM.get(VM_CONST_ADDRESS, longTemp);
if (longTemp < 1000000L || longTemp > 1200000L) { if (longTemp < 1000000L || longTemp > 1200000L) {
resetEEPROM(); reset = true;
} else { } else {
voltMeterConstant = longTemp; voltMeterConstant = longTemp;
} }
if (reset) {
resetEEPROM();
}
} }
void resetConfig() { void resetConfig() {

View file

@ -61,6 +61,7 @@
#endif #endif
void resetEEPROM(); void resetEEPROM();
void resetConfig();
void restoreConfig(); void restoreConfig();
#endif #endif