From 3f91f706a9eeeac1e2b593308b95db4497d5db78 Mon Sep 17 00:00:00 2001 From: mricho <3901301+RiskoFPV@users.noreply.github.com> Date: Fri, 27 May 2022 03:11:05 -0400 Subject: [PATCH] Add save_no_reboot, exit_no_reboot, add config command header/footer --- src/main/cli/cli.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/main/cli/cli.c b/src/main/cli/cli.c index 843e553781..0a91e6ec41 100644 --- a/src/main/cli/cli.c +++ b/src/main/cli/cli.c @@ -31,6 +31,7 @@ // FIXME remove this for targets that don't need a CLI. Perhaps use a no-op macro when USE_CLI is not enabled // signal that we're in cli mode bool cliMode = false; +bool cliExited = false; #ifdef USE_CLI @@ -3607,6 +3608,24 @@ static void cliExit(const char *cmdName, char *cmdline) cliReboot(); } +static void cliExitNoReboot(const char *cmdName, char *cmdline) +{ + UNUSED(cmdName); + UNUSED(cmdline); + + cliPrintHashLine("leaving CLI mode, unsaved changes lost"); + cliWriterFlush(); + + *cliBuffer = '\0'; + bufferIndex = 0; + cliMode = false; + cliExited = true; + // incase a motor was left running during motortest, clear it here + mixerResetDisarmedMotors(); + waitForSerialPortToFinishTransmitting(cliPort); + motorShutdown(); +} + #ifdef USE_GPS static void cliGpsPassthrough(const char *cmdName, char *cmdline) { @@ -4266,6 +4285,18 @@ static void cliSave(const char *cmdName, char *cmdline) } } +static void cliSaveNoReboot(const char *cmdName, char *cmdline) +{ + UNUSED(cmdline); + + if (tryPrepareSave(cmdName)) { + writeEEPROM(); + readEEPROM(); + cliPrintHashLine("saving"); + + } +} + #if defined(USE_CUSTOM_DEFAULTS) bool resetConfigToCustomDefaults(void) { @@ -4723,7 +4754,7 @@ static void cliRateProfilesJson(const char *cmdName) static void cliConfig(const char *cmdName, char *cmdline) { UNUSED(cmdline); - + cliPrintLine("----- CONFIG START -----"); cliPrintLine("{"); for (uint32_t i = 0; i < valueTableEntryCount; i++) { @@ -4751,6 +4782,7 @@ static void cliConfig(const char *cmdName, char *cmdline) cliPrintf(",\"imuf\":\"%lu\"", imufCurrentVersion); #endif cliPrintLine("}"); + cliPrintLine("----- CONFIG END -----"); } #endif @@ -6785,6 +6817,7 @@ const clicmd_t cmdTable[] = { CLI_COMMAND_DEF("escprog", "passthrough esc to serial", " ", cliEscPassthrough), #endif CLI_COMMAND_DEF("exit", NULL, NULL, cliExit), + CLI_COMMAND_DEF("exit_no_reboot", NULL, NULL, cliExitNoReboot), CLI_COMMAND_DEF("feature", "configure features", "list\r\n" "\t<->[name]", cliFeature), @@ -6845,6 +6878,7 @@ const clicmd_t cmdTable[] = { CLI_COMMAND_DEF("rxfail", "show/set rx failsafe settings", NULL, cliRxFailsafe), CLI_COMMAND_DEF("rxrange", "configure rx channel ranges", NULL, cliRxRange), CLI_COMMAND_DEF("save", "save and reboot", NULL, cliSave), + CLI_COMMAND_DEF("save_no_reboot", "save without reboot", NULL, cliSaveNoReboot), #ifdef USE_SDCARD CLI_COMMAND_DEF("sd_info", "sdcard info", NULL, cliSdInfo), #endif @@ -7113,6 +7147,9 @@ static bool cliProcessCustomDefaults(bool quiet) void cliEnter(serialPort_t *serialPort) { + if (cliExited) { // required for exit_no_reboot + return; + } cliMode = true; cliPort = serialPort; setPrintfSerialPort(cliPort);