Skip to content

Commit

Permalink
Add save_no_reboot, exit_no_reboot, add config command header/footer
Browse files Browse the repository at this point in the history
  • Loading branch information
mricho authored and nerdCopter committed May 27, 2022
1 parent 7c103b7 commit 051b3ed
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion src/main/cli/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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++)
{
Expand Down Expand Up @@ -4751,6 +4782,7 @@ static void cliConfig(const char *cmdName, char *cmdline)
cliPrintf(",\"imuf\":\"%lu\"", imufCurrentVersion);
#endif
cliPrintLine("}");
cliPrintLine("----- CONFIG END -----");
}
#endif

Expand Down Expand Up @@ -6785,6 +6817,7 @@ const clicmd_t cmdTable[] = {
CLI_COMMAND_DEF("escprog", "passthrough esc to serial", "<mode [sk/bl/ki/cc]> <index>", 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),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 051b3ed

Please sign in to comment.