Skip to content

Commit b79c91d

Browse files
committed
Test for online EEPROM before accessing.
1 parent 69989bc commit b79c91d

File tree

1 file changed

+35
-13
lines changed

1 file changed

+35
-13
lines changed

Firmware/RTK_Surveyor/NVM.ino

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
void loadSettings()
22
{
3+
if (online.eeprom == false)
4+
{
5+
ESP_LOGD(TAG, "Error: EEPROM not online");
6+
return;
7+
}
8+
39
//First load any settings from NVM
410
//After, we'll load settings from config file if available
511
//We'll then re-record settings so that the settings from the file over-rides internal NVM settings
@@ -41,25 +47,44 @@ void loadSettings()
4147
recordSystemSettings();
4248
}
4349

50+
//Load settings without recording
51+
//Used at very first boot to test for resetCounter
52+
void loadSettingsPartial()
53+
{
54+
if (online.eeprom == false)
55+
{
56+
ESP_LOGD(TAG, "Error: EEPROM not online");
57+
return;
58+
}
59+
60+
//Check to see if EEPROM is blank
61+
uint32_t testRead = 0;
62+
if (EEPROM.get(0, testRead) == 0xFFFFFFFF)
63+
return; //EEPROM is blank, assume default settings
64+
65+
EEPROM.get(0, settings); //Read current settings
66+
}
67+
4468
//Record the current settings struct to EEPROM and then to config file
4569
void recordSystemSettings()
4670
{
4771
settings.sizeOfSettings = sizeof(settings);
4872
if (settings.sizeOfSettings > EEPROM_SIZE)
4973
{
50-
displayError("EEPROM");
74+
Serial.printf("Size of settings is %d bytes\n\r", sizeof(settings));
75+
Serial.println(F("Increase the EEPROM footprint!"));
76+
displayError("EEPROM"); //Hard freeze
77+
}
5178

52-
while (1) //Hard freeze
53-
{
54-
Serial.printf("Size of settings is %d bytes\n\r", sizeof(settings));
55-
Serial.println(F("Increase the EEPROM footprint!"));
56-
delay(1000);
57-
}
79+
if (online.eeprom == true)
80+
{
81+
EEPROM.put(0, settings);
82+
EEPROM.commit();
83+
delay(1); //Give CPU time to pet WDT
5884
}
85+
else
86+
ESP_LOGD(TAG, "Error: EEPROM not online");
5987

60-
EEPROM.put(0, settings);
61-
EEPROM.commit();
62-
delay(1); //Give CPU time to pet WDT
6388
recordSystemSettingsToFile();
6489
}
6590

@@ -142,7 +167,6 @@ void recordSystemSettingsToFile()
142167
settingsFile.println("enableSensorFusion=" + (String)settings.enableSensorFusion);
143168
settingsFile.println("autoIMUmountAlignment=" + (String)settings.autoIMUmountAlignment);
144169
settingsFile.println("enableResetDisplay=" + (String)settings.enableResetDisplay);
145-
settingsFile.println("resetCount=" + (String)settings.resetCount);
146170

147171
//Record constellation settings
148172
for (int x = 0 ; x < MAX_CONSTELLATIONS ; x++)
@@ -411,8 +435,6 @@ bool parseLine(char* str) {
411435
settings.autoIMUmountAlignment = d;
412436
else if (strcmp(settingName, "enableResetDisplay") == 0)
413437
settings.enableResetDisplay = d;
414-
else if (strcmp(settingName, "resetCount") == 0)
415-
settings.resetCount = d;
416438

417439
//Check for bulk settings (constellations and message rates)
418440
//Must be last on else list

0 commit comments

Comments
 (0)