Skip to content

Commit

Permalink
Merge pull request #57 from klcjr89/master
Browse files Browse the repository at this point in the history
Fix EEPROM saving issue when issuing a RESET command via a serial ter…
  • Loading branch information
pyr0ball committed Oct 30, 2019
2 parents 5e69da1 + 0e7862c commit 61d7bd6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
23 changes: 16 additions & 7 deletions firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.cpp
Expand Up @@ -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);
Expand All @@ -24,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
3 changes: 2 additions & 1 deletion firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.h
Expand Up @@ -61,6 +61,7 @@
#endif

void resetEEPROM();
void resetConfig();
void restoreConfig();

#endif
#endif

0 comments on commit 61d7bd6

Please sign in to comment.