1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-15 04:15:44 +03:00

Add default display to cli get command if value has been changed

Presents the user with the default value for reference when displaying a parameter with the "get" command - but only if the current value differs from the default.
This commit is contained in:
Bruce Luckcuck 2018-05-21 17:25:20 -04:00
parent 041362614b
commit fc2f01cdf7

View file

@ -3075,6 +3075,24 @@ static void cliDefaults(char *cmdline)
}
}
void cliPrintVarDefault(const clivalue_t *value)
{
const pgRegistry_t *pg = pgFind(value->pgn);
if (pg) {
const char *defaultFormat = "Default value: ";
const int valueOffset = getValueOffset(value);
memcpy(pg->copy, pg->address, pg->size);
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();
}
memcpy(pg->address, pg->copy, pg->size);
}
}
STATIC_UNIT_TESTED void cliGet(char *cmdline)
{
const clivalue_t *val;
@ -3083,12 +3101,14 @@ STATIC_UNIT_TESTED void cliGet(char *cmdline)
for (uint32_t i = 0; i < valueTableEntryCount; i++) {
if (strcasestr(valueTable[i].name, cmdline)) {
val = &valueTable[i];
if (matchedCommands > 0) {
cliPrintLinefeed();
}
cliPrintf("%s = ", valueTable[i].name);
cliPrintVar(val, 0);
cliPrintLinefeed();
cliPrintVarRange(val);
cliPrintLinefeed();
cliPrintVarDefault(val);
matchedCommands++;
}
}