Skip to content

Commit

Permalink
These code changes are for resetting the config values to the default…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
Ken committed Oct 31, 2019
1 parent eb05213 commit 106e6c8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
Expand Up @@ -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
Expand Down
28 changes: 14 additions & 14 deletions firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.cpp
Expand Up @@ -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);
Expand All @@ -24,68 +24,68 @@ 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;
}

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;
Expand Down
4 changes: 2 additions & 2 deletions firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.h
Expand Up @@ -60,8 +60,8 @@
#endif
#endif

void resetEEPROM();
void resetConfig();
void eraseEEPROM();
void setDefaultConfig();
void restoreConfig();

#endif
6 changes: 3 additions & 3 deletions firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_serial.h
Expand Up @@ -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) {
Expand All @@ -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:");
Expand Down

0 comments on commit 106e6c8

Please sign in to comment.