Skip to content

Commit 5a23710

Browse files
committed
Move file allocations outside of beginSD(), where they are used.
1 parent 9d88742 commit 5a23710

File tree

3 files changed

+34
-23
lines changed

3 files changed

+34
-23
lines changed

Firmware/RTK_Surveyor/Begin.ino

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -408,29 +408,7 @@ void beginSD()
408408
//Mark card not yet usable for logging
409409
sdCardSize = 0;
410410
outOfSDSpace = true;
411-
412-
//Allocate the ubxFile
413-
if (!ubxFile)
414-
{
415-
ubxFile = new FileSdFatMMC;
416-
if (!ubxFile)
417-
{
418-
systemPrintln("Failed to allocate ubxFile!");
419-
break;
420-
}
421-
}
422-
423-
//Allocate the managerTempFile
424-
if (!managerTempFile)
425-
{
426-
managerTempFile = new FileSdFatMMC;
427-
if (!managerTempFile)
428-
{
429-
systemPrintln("Failed to allocate managerTempFile!");
430-
break;
431-
}
432-
}
433-
411+
434412
systemPrintln("microSD: Online");
435413
online.microSD = true;
436414
break;

Firmware/RTK_Surveyor/Form.ino

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,17 @@ static void handleFirmwareFileDownload(AsyncWebServerRequest *request)
229229

230230
if (managerFileOpen == false)
231231
{
232+
//Allocate the managerTempFile
233+
if (!managerTempFile)
234+
{
235+
managerTempFile = new FileSdFatMMC;
236+
if (!managerTempFile)
237+
{
238+
systemPrintln("Failed to allocate managerTempFile!");
239+
break;
240+
}
241+
}
242+
232243
if (managerTempFile->open(fileName, O_READ) == true)
233244
managerFileOpen = true;
234245
else
@@ -1342,6 +1353,17 @@ void handleUpload(AsyncWebServerRequest * request, String filename, size_t index
13421353
char tempFileName[50];
13431354
filename.toCharArray(tempFileName, sizeof(tempFileName));
13441355

1356+
//Allocate the managerTempFile
1357+
if (!managerTempFile)
1358+
{
1359+
managerTempFile = new FileSdFatMMC;
1360+
if (!managerTempFile)
1361+
{
1362+
systemPrintln("Failed to allocate managerTempFile!");
1363+
break;
1364+
}
1365+
}
1366+
13451367
//Attempt to gain access to the SD card
13461368
if (xSemaphoreTake(sdCardSemaphore, fatSemaphore_longWait_ms) == pdPASS)
13471369
{

Firmware/RTK_Surveyor/menuMessages.ino

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,17 @@ void beginLogging(const char *customFileName)
366366
strcpy(logFileName, customFileName);
367367
}
368368

369+
//Allocate the ubxFile
370+
if (!ubxFile)
371+
{
372+
ubxFile = new FileSdFatMMC;
373+
if (!ubxFile)
374+
{
375+
systemPrintln("Failed to allocate ubxFile!");
376+
return;
377+
}
378+
}
379+
369380
//Attempt to write to file system. This avoids collisions with file writing in F9PSerialReadTask()
370381
if (xSemaphoreTake(sdCardSemaphore, fatSemaphore_longWait_ms) == pdPASS)
371382
{

0 commit comments

Comments
 (0)