mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-14 20:10:18 +03:00
Merge pull request #5935 from etracer65/cli_get_display_default
Add default display to cli get command if value has been changed
This commit is contained in:
commit
7ab2d0c7fd
1 changed files with 65 additions and 30 deletions
|
@ -215,6 +215,42 @@ static const char * const *sensorHardwareNames[] = {
|
|||
};
|
||||
#endif // USE_SENSOR_NAMES
|
||||
|
||||
static void backupPgConfig(const pgRegistry_t *pg)
|
||||
{
|
||||
memcpy(pg->copy, pg->address, pg->size);
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -449,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)
|
||||
|
@ -3075,24 +3115,44 @@ 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);
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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];
|
||||
if (matchedCommands > 0) {
|
||||
cliPrintLinefeed();
|
||||
}
|
||||
cliPrintf("%s = ", valueTable[i].name);
|
||||
cliPrintVar(val, 0);
|
||||
cliPrintLinefeed();
|
||||
cliPrintVarRange(val);
|
||||
cliPrintLinefeed();
|
||||
|
||||
cliPrintVarDefault(val);
|
||||
matchedCommands++;
|
||||
}
|
||||
}
|
||||
|
||||
restoreConfigs();
|
||||
|
||||
if (matchedCommands) {
|
||||
return;
|
||||
|
@ -3870,25 +3930,6 @@ error:
|
|||
}
|
||||
#endif
|
||||
|
||||
static void backupConfigs(void)
|
||||
{
|
||||
// make copies of configs to do differencing
|
||||
PG_FOREACH(pg) {
|
||||
memcpy(pg->copy, pg->address, pg->size);
|
||||
}
|
||||
|
||||
configIsInCopy = true;
|
||||
}
|
||||
|
||||
static void restoreConfigs(void)
|
||||
{
|
||||
PG_FOREACH(pg) {
|
||||
memcpy(pg->address, pg->copy, pg->size);
|
||||
}
|
||||
|
||||
configIsInCopy = false;
|
||||
}
|
||||
|
||||
static void printConfig(char *cmdline, bool doDiff)
|
||||
{
|
||||
uint8_t dumpMask = DUMP_MASTER;
|
||||
|
@ -3908,14 +3949,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