Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix EEPROM saving issue when issuing a RESET command via a serial ter… #57

Merged
merged 4 commits into from
Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 16 additions & 7 deletions firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.cpp
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#endif

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

#endif
#endif