mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-14 20:10:18 +03:00
Refactor to support target specific defaults
Also remove redundant call to targetConfiguration()
This commit is contained in:
parent
40a88ada81
commit
361af53c2b
1 changed files with 36 additions and 31 deletions
|
@ -225,6 +225,32 @@ static void restorePgConfig(const pgRegistry_t *pg)
|
|||
memcpy(pg->address, pg->copy, pg->size);
|
||||
}
|
||||
|
||||
static void backupConfigs(void)
|
||||
{
|
||||
// make copies of configs to do differencing
|
||||
PG_FOREACH(pg) {
|
||||
backupPgConfig(pg);
|
||||
}
|
||||
|
||||
configIsInCopy = true;
|
||||
}
|
||||
|
||||
static void restoreConfigs(void)
|
||||
{
|
||||
PG_FOREACH(pg) {
|
||||
restorePgConfig(pg);
|
||||
}
|
||||
|
||||
configIsInCopy = false;
|
||||
}
|
||||
|
||||
static void backupAndResetConfigs(void)
|
||||
{
|
||||
backupConfigs();
|
||||
// reset all configs to defaults to do differencing
|
||||
resetConfigs();
|
||||
}
|
||||
|
||||
static void cliPrint(const char *str)
|
||||
{
|
||||
while (*str) {
|
||||
|
@ -459,7 +485,11 @@ static uint16_t getValueOffset(const clivalue_t *value)
|
|||
void *cliGetValuePointer(const clivalue_t *value)
|
||||
{
|
||||
const pgRegistry_t* rec = pgFind(value->pgn);
|
||||
return CONST_CAST(void *, rec->address + getValueOffset(value));
|
||||
if (configIsInCopy) {
|
||||
return CONST_CAST(void *, rec->copy + getValueOffset(value));
|
||||
} else {
|
||||
return CONST_CAST(void *, rec->address + getValueOffset(value));
|
||||
}
|
||||
}
|
||||
|
||||
const void *cliGetDefaultPointer(const clivalue_t *value)
|
||||
|
@ -3091,15 +3121,12 @@ void cliPrintVarDefault(const clivalue_t *value)
|
|||
if (pg) {
|
||||
const char *defaultFormat = "Default value: ";
|
||||
const int valueOffset = getValueOffset(value);
|
||||
backupPgConfig(pg);
|
||||
pgReset(pg);
|
||||
const bool equalsDefault = valuePtrEqualsDefault(value, pg->copy + valueOffset, pg->address + valueOffset);
|
||||
if (!equalsDefault) {
|
||||
cliPrintf(defaultFormat, value->name);
|
||||
printValuePointer(value, (uint8_t*)pg->address + valueOffset, false);
|
||||
cliPrintLinefeed();
|
||||
}
|
||||
restorePgConfig(pg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3108,6 +3135,8 @@ STATIC_UNIT_TESTED void cliGet(char *cmdline)
|
|||
const clivalue_t *val;
|
||||
int matchedCommands = 0;
|
||||
|
||||
backupAndResetConfigs();
|
||||
|
||||
for (uint32_t i = 0; i < valueTableEntryCount; i++) {
|
||||
if (strcasestr(valueTable[i].name, cmdline)) {
|
||||
val = &valueTable[i];
|
||||
|
@ -3123,6 +3152,7 @@ STATIC_UNIT_TESTED void cliGet(char *cmdline)
|
|||
}
|
||||
}
|
||||
|
||||
restoreConfigs();
|
||||
|
||||
if (matchedCommands) {
|
||||
return;
|
||||
|
@ -3897,25 +3927,6 @@ error:
|
|||
}
|
||||
#endif
|
||||
|
||||
static void backupConfigs(void)
|
||||
{
|
||||
// make copies of configs to do differencing
|
||||
PG_FOREACH(pg) {
|
||||
backupPgConfig(pg);
|
||||
}
|
||||
|
||||
configIsInCopy = true;
|
||||
}
|
||||
|
||||
static void restoreConfigs(void)
|
||||
{
|
||||
PG_FOREACH(pg) {
|
||||
restorePgConfig(pg);
|
||||
}
|
||||
|
||||
configIsInCopy = false;
|
||||
}
|
||||
|
||||
static void printConfig(char *cmdline, bool doDiff)
|
||||
{
|
||||
uint8_t dumpMask = DUMP_MASTER;
|
||||
|
@ -3935,14 +3946,8 @@ static void printConfig(char *cmdline, bool doDiff)
|
|||
if (doDiff) {
|
||||
dumpMask = dumpMask | DO_DIFF;
|
||||
}
|
||||
|
||||
backupConfigs();
|
||||
// reset all configs to defaults to do differencing
|
||||
resetConfigs();
|
||||
|
||||
#if defined(USE_TARGET_CONFIG)
|
||||
targetConfiguration();
|
||||
#endif
|
||||
|
||||
backupAndResetConfigs();
|
||||
if (checkCommand(options, "defaults")) {
|
||||
dumpMask = dumpMask | SHOW_DEFAULTS; // add default values as comments for changed values
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue