|
1 | 1 | //Display current system status |
2 | 2 | void menuSystem() |
3 | 3 | { |
4 | | - bool sdCardAlreadyMounted; |
5 | | - |
6 | 4 | while (1) |
7 | 5 | { |
8 | 6 | systemPrintln(); |
@@ -307,35 +305,7 @@ void menuSystem() |
307 | 305 | } |
308 | 306 | else if ((incoming == 'f') && (settings.enableSD == true) && (online.microSD == true)) |
309 | 307 | { |
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(); |
339 | 309 | } |
340 | 310 | // Support mode switching |
341 | 311 | else if (incoming == 'B') { |
@@ -508,7 +478,7 @@ void menuDebug() |
508 | 478 | systemPrintln(); |
509 | 479 | systemPrintln("Menu: Debug"); |
510 | 480 |
|
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", |
512 | 482 | failedParserMessages_NMEA, |
513 | 483 | failedParserMessages_RTCM, |
514 | 484 | failedParserMessages_UBX); |
@@ -918,3 +888,87 @@ void printCurrentConditionsNMEA() |
918 | 888 | systemPrintln(nmeaMessage); |
919 | 889 | } |
920 | 890 | } |
| 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