Skip to content

Commit 1def858

Browse files
committed
Display files in a BT friendly way
#384
1 parent a676d5a commit 1def858

File tree

1 file changed

+86
-32
lines changed

1 file changed

+86
-32
lines changed

Firmware/RTK_Surveyor/menuSystem.ino

Lines changed: 86 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//Display current system status
22
void menuSystem()
33
{
4-
bool sdCardAlreadyMounted;
5-
64
while (1)
75
{
86
systemPrintln();
@@ -307,35 +305,7 @@ void menuSystem()
307305
}
308306
else if ((incoming == 'f') && (settings.enableSD == true) && (online.microSD == true))
309307
{
310-
sdCardAlreadyMounted = online.microSD;
311-
if (!online.microSD)
312-
beginSD();
313-
314-
//Notify the user if the microSD card is not available
315-
if (!online.microSD)
316-
systemPrintln("microSD card not online!");
317-
else
318-
{
319-
//Attempt to write to file system. This avoids collisions with file writing from other functions like recordSystemSettingsToFile() and F9PSerialReadTask()
320-
if (xSemaphoreTake(sdCardSemaphore, fatSemaphore_longWait_ms) == pdPASS)
321-
{
322-
markSemaphore(FUNCTION_FILELIST);
323-
324-
systemPrintln("Files found (date time size name):\r\n");
325-
sd->ls(LS_R | LS_DATE | LS_SIZE);
326-
}
327-
else
328-
{
329-
//Error failed to list the contents of the microSD card
330-
systemPrintf("sdCardSemaphore failed to yield, menuSystem.ino line %d\r\n", __LINE__);
331-
}
332-
333-
//Release the SD card if not originally mounted
334-
if (sdCardAlreadyMounted)
335-
xSemaphoreGive(sdCardSemaphore);
336-
else
337-
endSD(true, true);
338-
}
308+
printFileList();
339309
}
340310
// Support mode switching
341311
else if (incoming == 'B') {
@@ -508,7 +478,7 @@ void menuDebug()
508478
systemPrintln();
509479
systemPrintln("Menu: Debug");
510480

511-
systemPrintf("Filtered by parser: %d NMEA / %d RTCM / %d UBX\n\r",
481+
systemPrintf("Filtered by parser: %d NMEA / %d RTCM / %d UBX\r\n",
512482
failedParserMessages_NMEA,
513483
failedParserMessages_RTCM,
514484
failedParserMessages_UBX);
@@ -918,3 +888,87 @@ void printCurrentConditionsNMEA()
918888
systemPrintln(nmeaMessage);
919889
}
920890
}
891+
892+
//When called, prints the contents of root folder list of files on SD card
893+
//This allows us to replace the sd.ls() function to point at Serial and BT outputs
894+
void printFileList()
895+
{
896+
bool sdCardAlreadyMounted = online.microSD;
897+
if (!online.microSD)
898+
beginSD();
899+
900+
//Notify the user if the microSD card is not available
901+
if (!online.microSD)
902+
systemPrintln("microSD card not online!");
903+
else
904+
{
905+
//Attempt to gain access to the SD card
906+
if (xSemaphoreTake(sdCardSemaphore, fatSemaphore_longWait_ms) == pdPASS)
907+
{
908+
markSemaphore(FUNCTION_PRINT_FILE_LIST);
909+
910+
SdFile dir;
911+
dir.open("/"); //Open root
912+
uint16_t fileCount = 0;
913+
914+
SdFile tempFile;
915+
916+
systemPrintln("Files found:");
917+
918+
while (tempFile.openNext(&dir, O_READ))
919+
{
920+
if (tempFile.isFile())
921+
{
922+
fileCount++;
923+
924+
//2017-05-19 187362648 800_0291.MOV
925+
926+
//Get File Date from sdFat
927+
uint16_t fileDate;
928+
uint16_t fileTime;
929+
tempFile.getCreateDateTime(&fileDate, &fileTime);
930+
931+
//Convert sdFat file date fromat into YYYY-MM-DD
932+
char fileDateChar[20];
933+
sprintf(fileDateChar, "%d-%02d-%02d",
934+
((fileDate >> 9) + 1980), //Year
935+
((fileDate >> 5) & 0b1111), //Month
936+
(fileDate & 0b11111) //Day
937+
);
938+
939+
char fileSizeChar[20];
940+
stringHumanReadableSize(tempFile.fileSize()).toCharArray(fileSizeChar, sizeof(fileSizeChar));
941+
942+
char fileName[50]; //Handle long file names
943+
tempFile.getName(fileName, sizeof(fileName));
944+
945+
char fileRecord[100];
946+
sprintf(fileRecord, "%s\t%s\t%s", fileDateChar, fileSizeChar, fileName);
947+
948+
systemPrintln(fileRecord);
949+
}
950+
}
951+
952+
dir.close();
953+
tempFile.close();
954+
955+
if (fileCount == 0)
956+
systemPrintln("No files found");
957+
}
958+
else
959+
{
960+
char semaphoreHolder[50];
961+
getSemaphoreFunction(semaphoreHolder);
962+
963+
//This is an error because the current settings no longer match the settings
964+
//on the microSD card, and will not be restored to the expected settings!
965+
systemPrintf("sdCardSemaphore failed to yield, held by %s, menuSystem.ino line %d\r\n", semaphoreHolder, __LINE__);
966+
}
967+
968+
//Release the SD card if not originally mounted
969+
if (sdCardAlreadyMounted)
970+
xSemaphoreGive(sdCardSemaphore);
971+
else
972+
endSD(true, true);
973+
}
974+
}

0 commit comments

Comments
 (0)