Merge pull request #10755 from mikeller/add_parameter_group_reset_defaults
Added resetting to defaults for individual parameter groups.
This commit is contained in:
commit
33dd967736
|
@ -679,10 +679,12 @@ static void backupPgConfig(const pgRegistry_t *pg)
|
|||
memcpy(pg->copy, pg->address, pg->size);
|
||||
}
|
||||
|
||||
static void restorePgConfig(const pgRegistry_t *pg)
|
||||
static void restorePgConfig(const pgRegistry_t *pg, uint16_t notToRestoreGroupId)
|
||||
{
|
||||
if (!notToRestoreGroupId || pgN(pg) != notToRestoreGroupId) {
|
||||
memcpy(pg->address, pg->copy, pg->size);
|
||||
}
|
||||
}
|
||||
|
||||
static void backupConfigs(void)
|
||||
{
|
||||
|
@ -690,7 +692,6 @@ static void backupConfigs(void)
|
|||
return;
|
||||
}
|
||||
|
||||
// make copies of configs to do differencing
|
||||
PG_FOREACH(pg) {
|
||||
backupPgConfig(pg);
|
||||
}
|
||||
|
@ -698,14 +699,14 @@ static void backupConfigs(void)
|
|||
configIsInCopy = true;
|
||||
}
|
||||
|
||||
static void restoreConfigs(void)
|
||||
static void restoreConfigs(uint16_t notToRestoreGroupId)
|
||||
{
|
||||
if (!configIsInCopy) {
|
||||
return;
|
||||
}
|
||||
|
||||
PG_FOREACH(pg) {
|
||||
restorePgConfig(pg);
|
||||
restorePgConfig(pg, notToRestoreGroupId);
|
||||
}
|
||||
|
||||
configIsInCopy = false;
|
||||
|
@ -4325,6 +4326,7 @@ bool hasCustomDefaults(void)
|
|||
static void cliDefaults(const char *cmdName, char *cmdline)
|
||||
{
|
||||
bool saveConfigs = true;
|
||||
uint16_t parameterGroupId = 0;
|
||||
#if defined(USE_CUSTOM_DEFAULTS)
|
||||
bool useCustomDefaults = true;
|
||||
#elif defined(USE_CUSTOM_DEFAULTS_ADDRESS)
|
||||
|
@ -4334,14 +4336,31 @@ static void cliDefaults(const char *cmdName, char *cmdline)
|
|||
}
|
||||
#endif
|
||||
|
||||
if (isEmpty(cmdline)) {
|
||||
} else if (strncasecmp(cmdline, "nosave", 6) == 0) {
|
||||
char *saveptr;
|
||||
char* tok = strtok_r(cmdline, " ", &saveptr);
|
||||
int index = 0;
|
||||
bool expectParameterGroupId = false;
|
||||
while (tok != NULL) {
|
||||
if (expectParameterGroupId) {
|
||||
parameterGroupId = atoi(tok);
|
||||
expectParameterGroupId = false;
|
||||
|
||||
if (!parameterGroupId) {
|
||||
cliShowParseError(cmdName);
|
||||
|
||||
return;
|
||||
}
|
||||
} else if (strcasestr(tok, "group_id")) {
|
||||
expectParameterGroupId = true;
|
||||
} else if (strcasestr(tok, "nosave")) {
|
||||
saveConfigs = false;
|
||||
#if defined(USE_CUSTOM_DEFAULTS)
|
||||
} else if (strncasecmp(cmdline, "bare", 4) == 0) {
|
||||
} else if (strcasestr(tok, "bare")) {
|
||||
useCustomDefaults = false;
|
||||
} else if (strncasecmp(cmdline, "show", 4) == 0) {
|
||||
if (hasCustomDefaults()) {
|
||||
} else if (strcasestr(tok, "show")) {
|
||||
if (index != 0) {
|
||||
cliShowParseError(cmdName);
|
||||
} else if (hasCustomDefaults()) {
|
||||
char *customDefaultsPtr = customDefaultsStart;
|
||||
while (customDefaultsHasNext(customDefaultsPtr)) {
|
||||
if (*customDefaultsPtr != '\n') {
|
||||
|
@ -4358,12 +4377,27 @@ static void cliDefaults(const char *cmdName, char *cmdline)
|
|||
return;
|
||||
#endif
|
||||
} else {
|
||||
cliPrintError(cmdName, "INVALID OPTION");
|
||||
cliShowParseError(cmdName);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
index++;
|
||||
tok = strtok_r(NULL, " ", &saveptr);
|
||||
}
|
||||
|
||||
if (expectParameterGroupId) {
|
||||
cliShowParseError(cmdName);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (parameterGroupId) {
|
||||
cliPrintLinef("\r\n# resetting group %d to defaults", parameterGroupId);
|
||||
backupConfigs();
|
||||
} else {
|
||||
cliPrintHashLine("resetting to defaults");
|
||||
}
|
||||
|
||||
resetConfig();
|
||||
|
||||
|
@ -4381,6 +4415,10 @@ static void cliDefaults(const char *cmdName, char *cmdline)
|
|||
}
|
||||
#endif
|
||||
|
||||
if (parameterGroupId) {
|
||||
restoreConfigs(parameterGroupId);
|
||||
}
|
||||
|
||||
if (saveConfigs && tryPrepareSave(cmdName)) {
|
||||
writeUnmodifiedConfigToEEPROM();
|
||||
|
||||
|
@ -4442,7 +4480,7 @@ STATIC_UNIT_TESTED void cliGet(const char *cmdName, char *cmdline)
|
|||
}
|
||||
}
|
||||
|
||||
restoreConfigs();
|
||||
restoreConfigs(0);
|
||||
|
||||
pidProfileIndexToUse = CURRENT_PROFILE_INDEX;
|
||||
rateProfileIndexToUse = CURRENT_PROFILE_INDEX;
|
||||
|
@ -6331,7 +6369,7 @@ static void printConfig(const char *cmdName, char *cmdline, bool doDiff)
|
|||
#endif
|
||||
|
||||
// restore configs from copies
|
||||
restoreConfigs();
|
||||
restoreConfigs(0);
|
||||
}
|
||||
|
||||
static void cliDump(const char *cmdName, char *cmdline)
|
||||
|
@ -6436,9 +6474,9 @@ const clicmd_t cmdTable[] = {
|
|||
CLI_COMMAND_DEF("color", "configure colors", NULL, cliColor),
|
||||
#endif
|
||||
#if defined(USE_CUSTOM_DEFAULTS)
|
||||
CLI_COMMAND_DEF("defaults", "reset to defaults and reboot", "[nosave|bare|show]", cliDefaults),
|
||||
CLI_COMMAND_DEF("defaults", "reset to defaults and reboot", "{show} {nosave} {bare} {group_id <id>}", cliDefaults),
|
||||
#else
|
||||
CLI_COMMAND_DEF("defaults", "reset to defaults and reboot", "[nosave|show]", cliDefaults),
|
||||
CLI_COMMAND_DEF("defaults", "reset to defaults and reboot", "{nosave}", cliDefaults),
|
||||
#endif
|
||||
CLI_COMMAND_DEF("diff", "list configuration changes from default", "[master|profile|rates|hardware|all] {defaults|bare}", cliDiff),
|
||||
#ifdef USE_RESOURCE_MGMT
|
||||
|
|
Loading…
Reference in New Issue