These code changes are for resetting the config values to the default values by issuing the ERASE word via a serial terminal.

This change was made for clarity sake, as ERASE stands out more than the previous RESET word, which could be mistaken for just rebooting the board.
This commit is contained in:
Ken 2019-10-31 01:33:13 -04:00
parent eb052133a3
commit 106e6c85c3
4 changed files with 20 additions and 20 deletions

View file

@ -45,7 +45,7 @@ You can also enable or disable DEBUG output with: DEBUG [0|1]
You can query the current configuration with: CONFIG
You can query the current state (including ADC measurements) with: STATE
To reset all settings to defaults, use: RESET
To set all settings to defaults, use: ERASE
These commands should be wrapped in this format:
CMD INT

View file

@ -11,9 +11,9 @@ int Debug = 0;
long voltMeterConstant = VM_CONST_DEFAULT;
uint8_t pP_i2c_address = 0xa0;
void resetEEPROM() {
void eraseEEPROM() {
resetConfig();
setDefaultConfig();
EEPROM.put(GAIN_FACTOR_ADDRESS, GAIN_FACTOR);
EEPROM.put(FOLLOWER_THRESHOLD_ADDRESS, followerThrs);
@ -24,50 +24,50 @@ void resetEEPROM() {
EEPROM.put(VM_CONST_ADDRESS, voltMeterConstant);
}
// Restore config from EEPROM, otherwise reset config and write to EEPROM
// Restore config from EEPROM, otherwise erase config and write to EEPROM
void restoreConfig() {
int temp;
bool reset = false;
bool erase = false;
EEPROM.get(GAIN_FACTOR_ADDRESS, temp);
if (temp < 0 || temp > 4) {
reset = true;
erase = true;
} else {
GAIN_FACTOR = temp;
}
EEPROM.get(FOLLOWER_THRESHOLD_ADDRESS, temp);
if (temp < 0 || temp > 5000) {
reset = true;
erase = true;
} else {
followerThrs = temp;
}
EEPROM.get(COMP_THRESHOLD_ADDRESS, temp);
if (temp < 0 || temp > 5000) {
reset = true;
erase = true;
} else {
compThrs = temp;
}
EEPROM.get(LOOP_DUR_ADDRESS, temp);
if (temp < 0 && temp > 1000) {
reset = true;
erase = true;
} else {
LOOP_DUR = temp;
}
EEPROM.get(TRG_DUR_ADDRESS, temp);
if (temp < 0 || temp > 1000) {
reset = true;
erase = true;
} else {
TRG_DUR = temp;
}
EEPROM.get(HYST_ADDRESS, temp);
if (temp < 0 || temp > 1000) {
reset = true;
erase = true;
} else {
Hyst = temp;
}
@ -75,17 +75,17 @@ void restoreConfig() {
long longTemp;
EEPROM.get(VM_CONST_ADDRESS, longTemp);
if (longTemp < 1000000L || longTemp > 1200000L) {
reset = true;
erase = true;
} else {
voltMeterConstant = longTemp;
}
if (reset) {
resetEEPROM();
if (erase) {
eraseEEPROM();
}
}
void resetConfig() {
void setDefaultConfig() {
GAIN_FACTOR = GAIN_FACTOR_DEFAULT;
followerThrs = FOLLOWER_THRESHOLD_DEFAULT;
compThrs = COMP_THRESHOLD_DEFAULT;

View file

@ -60,8 +60,8 @@
#endif
#endif
void resetEEPROM();
void resetConfig();
void eraseEEPROM();
void setDefaultConfig();
void restoreConfig();
#endif

View file

@ -222,8 +222,8 @@ void updateParams() {
else if (strcmp(serialMessageIn, "CONFIG") == 0) {
serialPrintConfig();
}
else if (strcmp(serialMessageIn, "RESET") == 0) {
resetEEPROM();
else if (strcmp(serialMessageIn, "ERASE") == 0) {
eraseEEPROM();
serialPrintConfig();
}
else if (strcmp(serialMessageIn, "STATE") == 0) {
@ -238,7 +238,7 @@ void updateParams() {
// Serial.println("To change ADC hysteresis value: HYST [integer]");
// Serial.println("To enable or disable debug output: DEBUG [0|1]");
// Serial.println("To print current config: CONFIG");
// Serial.println("To reset config to defaults: RESET");
// Serial.println("To set config to defaults: ERASE");
// Serial.println("To print current state: STATE");
// Serial.println("");
// Serial.println("Commands are entered in this format:");