Skip to content

Commit 4550b3f

Browse files
committed
Add option to print profile. Resolves #609
1 parent d90f8f7 commit 4550b3f

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

Firmware/RTK_Everywhere/NVM.ino

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,69 @@ bool loadSystemSettingsFromFileLFS(char *fileName, const char *findMe, char *fou
892892
return (true);
893893
}
894894

895+
bool printSystemSettingsFromFileLFS(char *fileName)
896+
{
897+
// log_d("printing setting fileName: %s", fileName);
898+
899+
if (!LittleFS.exists(fileName))
900+
{
901+
// log_d("settingsFile not found in LittleFS\r\n");
902+
return (false);
903+
}
904+
905+
File settingsFile = LittleFS.open(fileName, FILE_READ);
906+
if (!settingsFile)
907+
{
908+
// log_d("settingsFile not found in LittleFS\r\n");
909+
return (false);
910+
}
911+
912+
char line[100];
913+
int lineNumber = 0;
914+
915+
systemPrintln();
916+
systemPrintln("--------------------------------------------------------------------------------");
917+
918+
while (settingsFile.available())
919+
{
920+
// Get the next line from the file
921+
int n;
922+
n = getLine(&settingsFile, line, sizeof(line));
923+
924+
if (n <= 0)
925+
{
926+
systemPrintf("Failed to read line %d from settings file\r\n", lineNumber);
927+
}
928+
else if (line[n - 1] != '\n' && n == (sizeof(line) - 1))
929+
{
930+
systemPrintf("Settings line %d too long\r\n", lineNumber);
931+
if (lineNumber == 0)
932+
{
933+
// If we can't read the first line of the settings file, give up
934+
systemPrintln("Giving up on settings file");
935+
return (false);
936+
}
937+
}
938+
else
939+
{
940+
systemPrintln(line);
941+
}
942+
943+
lineNumber++;
944+
if (lineNumber > 800) // Arbitrary limit. Catch corrupt files.
945+
{
946+
systemPrintf("Max line number exceeded. Giving up reading file: %s\r\n", fileName);
947+
break;
948+
}
949+
}
950+
951+
systemPrintln("--------------------------------------------------------------------------------");
952+
systemPrintln();
953+
954+
settingsFile.close();
955+
return (true);
956+
}
957+
895958
// Convert a given line from file into a settingName and value
896959
// Sets the setting if the name is known
897960
// The order of variables matches the order found in settings.h

Firmware/RTK_Everywhere/menuMain.ino

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ void menuUserProfiles()
350350

351351
systemPrintf("%d) Delete profile '%s'\r\n", MAX_PROFILE_COUNT + 3, profileNames[profileNumber]);
352352

353+
systemPrintf("%d) Print profile\r\n", MAX_PROFILE_COUNT + 4);
354+
353355
systemPrintln("x) Exit");
354356

355357
int incoming = getUserInputNumber(); // Returns EXIT, TIMEOUT, or long
@@ -424,6 +426,21 @@ void menuUserProfiles()
424426
else
425427
systemPrintln("Delete aborted");
426428
}
429+
else if (incoming == MAX_PROFILE_COUNT + 4)
430+
{
431+
// Print profile
432+
systemPrintf("Select the profile to be printed (1-%d): ",MAX_PROFILE_COUNT);
433+
434+
int printThis = getUserInputNumber(); // Returns EXIT, TIMEOUT, or long
435+
436+
if (printThis >= 1 && printThis <= MAX_PROFILE_COUNT)
437+
{
438+
char printFileName[60];
439+
snprintf(printFileName, sizeof(printFileName), "/%s_Settings_%d.txt", platformFilePrefix,
440+
printThis - 1);
441+
printSystemSettingsFromFileLFS(printFileName);
442+
}
443+
}
427444

428445
else if (incoming == INPUT_RESPONSE_GETNUMBER_EXIT)
429446
break;

0 commit comments

Comments
 (0)