mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-15 20:35:33 +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
|
#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)
|
static void cliPrint(const char *str)
|
||||||
{
|
{
|
||||||
while (*str) {
|
while (*str) {
|
||||||
|
@ -449,7 +485,11 @@ static uint16_t getValueOffset(const clivalue_t *value)
|
||||||
void *cliGetValuePointer(const clivalue_t *value)
|
void *cliGetValuePointer(const clivalue_t *value)
|
||||||
{
|
{
|
||||||
const pgRegistry_t* rec = pgFind(value->pgn);
|
const pgRegistry_t* rec = pgFind(value->pgn);
|
||||||
|
if (configIsInCopy) {
|
||||||
|
return CONST_CAST(void *, rec->copy + getValueOffset(value));
|
||||||
|
} else {
|
||||||
return CONST_CAST(void *, rec->address + getValueOffset(value));
|
return CONST_CAST(void *, rec->address + getValueOffset(value));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const void *cliGetDefaultPointer(const clivalue_t *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)
|
STATIC_UNIT_TESTED void cliGet(char *cmdline)
|
||||||
{
|
{
|
||||||
const clivalue_t *val;
|
const clivalue_t *val;
|
||||||
int matchedCommands = 0;
|
int matchedCommands = 0;
|
||||||
|
|
||||||
|
backupAndResetConfigs();
|
||||||
|
|
||||||
for (uint32_t i = 0; i < valueTableEntryCount; i++) {
|
for (uint32_t i = 0; i < valueTableEntryCount; i++) {
|
||||||
if (strcasestr(valueTable[i].name, cmdline)) {
|
if (strcasestr(valueTable[i].name, cmdline)) {
|
||||||
val = &valueTable[i];
|
val = &valueTable[i];
|
||||||
|
if (matchedCommands > 0) {
|
||||||
|
cliPrintLinefeed();
|
||||||
|
}
|
||||||
cliPrintf("%s = ", valueTable[i].name);
|
cliPrintf("%s = ", valueTable[i].name);
|
||||||
cliPrintVar(val, 0);
|
cliPrintVar(val, 0);
|
||||||
cliPrintLinefeed();
|
cliPrintLinefeed();
|
||||||
cliPrintVarRange(val);
|
cliPrintVarRange(val);
|
||||||
cliPrintLinefeed();
|
cliPrintVarDefault(val);
|
||||||
|
|
||||||
matchedCommands++;
|
matchedCommands++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
restoreConfigs();
|
||||||
|
|
||||||
if (matchedCommands) {
|
if (matchedCommands) {
|
||||||
return;
|
return;
|
||||||
|
@ -3870,25 +3930,6 @@ error:
|
||||||
}
|
}
|
||||||
#endif
|
#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)
|
static void printConfig(char *cmdline, bool doDiff)
|
||||||
{
|
{
|
||||||
uint8_t dumpMask = DUMP_MASTER;
|
uint8_t dumpMask = DUMP_MASTER;
|
||||||
|
@ -3909,13 +3950,7 @@ static void printConfig(char *cmdline, bool doDiff)
|
||||||
dumpMask = dumpMask | DO_DIFF;
|
dumpMask = dumpMask | DO_DIFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
backupConfigs();
|
backupAndResetConfigs();
|
||||||
// reset all configs to defaults to do differencing
|
|
||||||
resetConfigs();
|
|
||||||
|
|
||||||
#if defined(USE_TARGET_CONFIG)
|
|
||||||
targetConfiguration();
|
|
||||||
#endif
|
|
||||||
if (checkCommand(options, "defaults")) {
|
if (checkCommand(options, "defaults")) {
|
||||||
dumpMask = dumpMask | SHOW_DEFAULTS; // add default values as comments for changed values
|
dumpMask = dumpMask | SHOW_DEFAULTS; // add default values as comments for changed values
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue