Skip to content

Commit e906fbc

Browse files
committed
Pass state of sdSemaphore into factoryReset()
Fix for issue #519
1 parent 8816c55 commit e906fbc

File tree

5 files changed

+29
-20
lines changed

5 files changed

+29
-20
lines changed

Firmware/RTK_Surveyor/Begin.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ void beginSystemState()
980980
if (systemState > STATE_NOT_SET)
981981
{
982982
systemPrintln("Unknown state - factory reset");
983-
factoryReset();
983+
factoryReset(false); //We do not have the SD semaphore
984984
}
985985

986986
if (productVariant == RTK_SURVEYOR)

Firmware/RTK_Surveyor/Form.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@ void updateSettingWithValue(const char *settingName, const char *settingValueStr
13501350
requestChangeState(STATE_ROVER_NOT_STARTED); // If update failed, return to Rover mode.
13511351
}
13521352
else if (strcmp(settingName, "factoryDefaultReset") == 0)
1353-
factoryReset();
1353+
factoryReset(false); //We do not have the sdSemaphore
13541354
else if (strcmp(settingName, "exitAndReset") == 0)
13551355
{
13561356
// Confirm receipt

Firmware/RTK_Surveyor/NVM.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,8 @@ bool parseLine(char *str, Settings *settings)
738738
// If user sets sizeOfSettings to -1 in config file, RTK Surveyor will factory reset
739739
if (d == -1)
740740
{
741-
factoryReset(); // Erase file system, erase settings file, reset u-blox module, display message on OLED
741+
// Erase file system, erase settings file, reset u-blox module, display message on OLED
742+
factoryReset(true); //We already have the SD semaphore
742743
}
743744

744745
// Check to see if this setting file is compatible with this version of RTK Surveyor

Firmware/RTK_Surveyor/menuMain.ino

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ void menuMain()
3737
systemPrint("** Bluetooth broadcasting as: ");
3838
systemPrint(deviceName);
3939
systemPrintln(" **");
40-
#else // COMPILE_BT
40+
#else // COMPILE_BT
4141
systemPrintln("** Bluetooth Not Compiled **");
42-
#endif // COMPILE_BT
42+
#endif // COMPILE_BT
4343

4444
systemPrintln("Menu: Main");
4545

@@ -58,25 +58,25 @@ void menuMain()
5858

5959
#ifdef COMPILE_WIFI
6060
systemPrintln("6) Configure WiFi");
61-
#else // COMPILE_WIFI
61+
#else // COMPILE_WIFI
6262
systemPrintln("6) **WiFi Not Compiled**");
63-
#endif // COMPILE_WIFI
63+
#endif // COMPILE_WIFI
6464

6565
#ifdef COMPILE_ETHERNET
6666
if (HAS_ETHERNET)
6767
{
6868
systemPrintln("e) Configure Ethernet");
6969
systemPrintln("n) Configure NTP");
7070
}
71-
#endif // COMPILE_ETHERNET
71+
#endif // COMPILE_ETHERNET
7272

7373
systemPrintln("p) Configure User Profiles");
7474

7575
#ifdef COMPILE_ESPNOW
7676
systemPrintln("r) Configure Radios");
77-
#else // COMPILE_ESPNOW
77+
#else // COMPILE_ESPNOW
7878
systemPrintln("r) **ESP-Now Not Compiled**");
79-
#endif // COMPILE_ESPNOW
79+
#endif // COMPILE_ESPNOW
8080

8181
if (online.lband == true)
8282
systemPrintln("P) Configure PointPerfect");
@@ -119,7 +119,7 @@ void menuMain()
119119
#ifdef COMPILE_ESPNOW
120120
else if (incoming == 'r')
121121
menuRadio();
122-
#endif // COMPILE_ESPNOW
122+
#endif // COMPILE_ESPNOW
123123
else if (incoming == 'f')
124124
menuFirmware();
125125
else if (incoming == 'b')
@@ -262,7 +262,7 @@ void menuUserProfiles()
262262
if (SD_MMC.exists(settingsFileName))
263263
SD_MMC.remove(settingsFileName);
264264
}
265-
#endif // COMPILE_SD_MMC
265+
#endif // COMPILE_SD_MMC
266266
}
267267

268268
recordProfileNumber(0); // Move to Profile1
@@ -334,18 +334,22 @@ void changeProfileNumber(byte newProfileNumber)
334334
}
335335

336336
// Erase all settings. Upon restart, unit will use defaults
337-
void factoryReset()
337+
void factoryReset(bool alreadyHasSemaphore)
338338
{
339339
displaySytemReset(); // Display friendly message on OLED
340340

341341
tasksStopUART2();
342342

343+
Serial.println("remove old files");
344+
343345
// Attempt to write to file system. This avoids collisions with file writing from other functions like
344-
// recordSystemSettingsToFile() and F9PSerialReadTask() if (settings.enableSD && online.microSD) //Don't check
345-
// settings.enableSD - it could be corrupt
346+
// recordSystemSettingsToFile() and F9PSerialReadTask() if (settings.enableSD && online.microSD)
347+
//Don't check settings.enableSD - it could be corrupt
346348
if (online.microSD)
347349
{
348-
if (xSemaphoreTake(sdCardSemaphore, fatSemaphore_longWait_ms) == pdPASS)
350+
Serial.println("2 - remove old files");
351+
352+
if (alreadyHasSemaphore == true || xSemaphoreTake(sdCardSemaphore, fatSemaphore_longWait_ms) == pdPASS)
349353
{
350354
if (USE_SPI_MICROSD)
351355
{
@@ -363,16 +367,20 @@ void factoryReset()
363367
SD_MMC.remove(stationCoordinateECEFFileName); // Remove station files
364368
SD_MMC.remove(stationCoordinateGeodeticFileName);
365369
}
366-
#endif // COMPILE_SD_MMC
370+
#endif // COMPILE_SD_MMC
367371

368372
xSemaphoreGive(sdCardSemaphore);
369373
} // End sdCardSemaphore
370374
else
371375
{
376+
char semaphoreHolder[50];
377+
getSemaphoreFunction(semaphoreHolder);
378+
372379
// An error occurs when a settings file is on the microSD card and it is not
373380
// deleted, as such the settings on the microSD card will be loaded when the
374381
// RTK reboots, resulting in failure to achieve the factory reset condition
375-
systemPrintf("sdCardSemaphore failed to yield, menuMain.ino line %d\r\n", __LINE__);
382+
log_d("sdCardSemaphore failed to yield, held by %s, menuMain.ino line %d\r\n", semaphoreHolder,
383+
__LINE__);
376384
}
377385
}
378386

@@ -512,5 +520,5 @@ void menuRadio()
512520
radioStart();
513521

514522
clearBuffer(); // Empty buffer of any newline chars
515-
#endif // COMPILE_ESPNOW
523+
#endif // COMPILE_ESPNOW
516524
}

Firmware/RTK_Surveyor/menuSystem.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ void menuSystem()
327327
byte bContinue = getCharacterNumber();
328328
if (bContinue == 'y')
329329
{
330-
factoryReset();
330+
factoryReset(false); //We do not have the SD semaphore
331331
}
332332
else
333333
systemPrintln("Reset aborted");

0 commit comments

Comments
 (0)