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:
parent
eb052133a3
commit
106e6c85c3
4 changed files with 20 additions and 20 deletions
|
|
@ -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 configuration with: CONFIG
|
||||||
You can query the current state (including ADC measurements) with: STATE
|
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:
|
These commands should be wrapped in this format:
|
||||||
CMD INT
|
CMD INT
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,9 @@ int Debug = 0;
|
||||||
long voltMeterConstant = VM_CONST_DEFAULT;
|
long voltMeterConstant = VM_CONST_DEFAULT;
|
||||||
uint8_t pP_i2c_address = 0xa0;
|
uint8_t pP_i2c_address = 0xa0;
|
||||||
|
|
||||||
void resetEEPROM() {
|
void eraseEEPROM() {
|
||||||
|
|
||||||
resetConfig();
|
setDefaultConfig();
|
||||||
|
|
||||||
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);
|
||||||
|
|
@ -24,50 +24,50 @@ void resetEEPROM() {
|
||||||
EEPROM.put(VM_CONST_ADDRESS, voltMeterConstant);
|
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() {
|
void restoreConfig() {
|
||||||
int temp;
|
int temp;
|
||||||
|
|
||||||
bool reset = false;
|
bool erase = false;
|
||||||
|
|
||||||
EEPROM.get(GAIN_FACTOR_ADDRESS, temp);
|
EEPROM.get(GAIN_FACTOR_ADDRESS, temp);
|
||||||
if (temp < 0 || temp > 4) {
|
if (temp < 0 || temp > 4) {
|
||||||
reset = true;
|
erase = 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) {
|
||||||
reset = true;
|
erase = 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) {
|
||||||
reset = true;
|
erase = 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) {
|
||||||
reset = true;
|
erase = 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) {
|
||||||
reset = true;
|
erase = 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) {
|
||||||
reset = true;
|
erase = true;
|
||||||
} else {
|
} else {
|
||||||
Hyst = temp;
|
Hyst = temp;
|
||||||
}
|
}
|
||||||
|
|
@ -75,17 +75,17 @@ 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) {
|
||||||
reset = true;
|
erase = true;
|
||||||
} else {
|
} else {
|
||||||
voltMeterConstant = longTemp;
|
voltMeterConstant = longTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reset) {
|
if (erase) {
|
||||||
resetEEPROM();
|
eraseEEPROM();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void resetConfig() {
|
void setDefaultConfig() {
|
||||||
GAIN_FACTOR = GAIN_FACTOR_DEFAULT;
|
GAIN_FACTOR = GAIN_FACTOR_DEFAULT;
|
||||||
followerThrs = FOLLOWER_THRESHOLD_DEFAULT;
|
followerThrs = FOLLOWER_THRESHOLD_DEFAULT;
|
||||||
compThrs = COMP_THRESHOLD_DEFAULT;
|
compThrs = COMP_THRESHOLD_DEFAULT;
|
||||||
|
|
|
||||||
|
|
@ -60,8 +60,8 @@
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void resetEEPROM();
|
void eraseEEPROM();
|
||||||
void resetConfig();
|
void setDefaultConfig();
|
||||||
void restoreConfig();
|
void restoreConfig();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -222,8 +222,8 @@ void updateParams() {
|
||||||
else if (strcmp(serialMessageIn, "CONFIG") == 0) {
|
else if (strcmp(serialMessageIn, "CONFIG") == 0) {
|
||||||
serialPrintConfig();
|
serialPrintConfig();
|
||||||
}
|
}
|
||||||
else if (strcmp(serialMessageIn, "RESET") == 0) {
|
else if (strcmp(serialMessageIn, "ERASE") == 0) {
|
||||||
resetEEPROM();
|
eraseEEPROM();
|
||||||
serialPrintConfig();
|
serialPrintConfig();
|
||||||
}
|
}
|
||||||
else if (strcmp(serialMessageIn, "STATE") == 0) {
|
else if (strcmp(serialMessageIn, "STATE") == 0) {
|
||||||
|
|
@ -238,7 +238,7 @@ void updateParams() {
|
||||||
// Serial.println("To change ADC hysteresis value: HYST [integer]");
|
// Serial.println("To change ADC hysteresis value: HYST [integer]");
|
||||||
// Serial.println("To enable or disable debug output: DEBUG [0|1]");
|
// Serial.println("To enable or disable debug output: DEBUG [0|1]");
|
||||||
// Serial.println("To print current config: CONFIG");
|
// 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("To print current state: STATE");
|
||||||
// Serial.println("");
|
// Serial.println("");
|
||||||
// Serial.println("Commands are entered in this format:");
|
// Serial.println("Commands are entered in this format:");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue