mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-14 20:10:18 +03:00
Fixed dumping of profile values in CLI.
This commit is contained in:
parent
c0d25b1296
commit
532e8afe61
6 changed files with 78 additions and 48 deletions
|
@ -93,17 +93,14 @@ uint8_t getCurrentPidProfileIndex(void)
|
||||||
return systemConfig()->pidProfileIndex;
|
return systemConfig()->pidProfileIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setPidProfile(uint8_t pidProfileIndex)
|
static void loadPidProfile(void)
|
||||||
{
|
{
|
||||||
if (pidProfileIndex < MAX_PROFILE_COUNT) {
|
currentPidProfile = pidProfilesMutable(systemConfig()->pidProfileIndex);
|
||||||
systemConfigMutable()->pidProfileIndex = pidProfileIndex;
|
|
||||||
currentPidProfile = pidProfilesMutable(pidProfileIndex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t getCurrentControlRateProfileIndex(void)
|
uint8_t getCurrentControlRateProfileIndex(void)
|
||||||
{
|
{
|
||||||
return systemConfigMutable()->activeRateProfile;
|
return systemConfig()->activeRateProfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t getCurrentMinthrottle(void)
|
uint16_t getCurrentMinthrottle(void)
|
||||||
|
@ -119,20 +116,14 @@ void resetConfigs(void)
|
||||||
#if defined(USE_TARGET_CONFIG)
|
#if defined(USE_TARGET_CONFIG)
|
||||||
targetConfiguration();
|
targetConfiguration();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef USE_OSD_SLAVE
|
|
||||||
setPidProfile(0);
|
|
||||||
setControlRateProfile(0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef USE_LED_STRIP
|
|
||||||
reevaluateLedConfig();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void activateConfig(void)
|
static void activateConfig(void)
|
||||||
{
|
{
|
||||||
#ifndef USE_OSD_SLAVE
|
#ifndef USE_OSD_SLAVE
|
||||||
|
loadPidProfile();
|
||||||
|
loadControlRateProfile();
|
||||||
|
|
||||||
initRcProcessing();
|
initRcProcessing();
|
||||||
|
|
||||||
resetAdjustmentStates();
|
resetAdjustmentStates();
|
||||||
|
@ -147,6 +138,10 @@ void activateConfig(void)
|
||||||
|
|
||||||
imuConfigure(throttleCorrectionConfig()->throttle_correction_angle);
|
imuConfigure(throttleCorrectionConfig()->throttle_correction_angle);
|
||||||
#endif // USE_OSD_SLAVE
|
#endif // USE_OSD_SLAVE
|
||||||
|
|
||||||
|
#ifdef USE_LED_STRIP
|
||||||
|
reevaluateLedConfig();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void validateAndFixConfig(void)
|
static void validateAndFixConfig(void)
|
||||||
|
@ -172,12 +167,12 @@ static void validateAndFixConfig(void)
|
||||||
if (systemConfig()->activeRateProfile >= CONTROL_RATE_PROFILE_COUNT) {
|
if (systemConfig()->activeRateProfile >= CONTROL_RATE_PROFILE_COUNT) {
|
||||||
systemConfigMutable()->activeRateProfile = 0;
|
systemConfigMutable()->activeRateProfile = 0;
|
||||||
}
|
}
|
||||||
setControlRateProfile(systemConfig()->activeRateProfile);
|
loadControlRateProfile();
|
||||||
|
|
||||||
if (systemConfig()->pidProfileIndex >= MAX_PROFILE_COUNT) {
|
if (systemConfig()->pidProfileIndex >= MAX_PROFILE_COUNT) {
|
||||||
systemConfigMutable()->pidProfileIndex = 0;
|
systemConfigMutable()->pidProfileIndex = 0;
|
||||||
}
|
}
|
||||||
setPidProfile(systemConfig()->pidProfileIndex);
|
loadPidProfile();
|
||||||
|
|
||||||
// Prevent invalid notch cutoff
|
// Prevent invalid notch cutoff
|
||||||
if (currentPidProfile->dterm_notch_cutoff >= currentPidProfile->dterm_notch_hz) {
|
if (currentPidProfile->dterm_notch_cutoff >= currentPidProfile->dterm_notch_hz) {
|
||||||
|
@ -479,6 +474,7 @@ bool readEEPROM(void)
|
||||||
bool success = loadEEPROM();
|
bool success = loadEEPROM();
|
||||||
|
|
||||||
validateAndFixConfig();
|
validateAndFixConfig();
|
||||||
|
|
||||||
activateConfig();
|
activateConfig();
|
||||||
|
|
||||||
#ifndef USE_OSD_SLAVE
|
#ifndef USE_OSD_SLAVE
|
||||||
|
@ -490,6 +486,8 @@ bool readEEPROM(void)
|
||||||
|
|
||||||
void writeEEPROM(void)
|
void writeEEPROM(void)
|
||||||
{
|
{
|
||||||
|
validateAndFixConfig();
|
||||||
|
|
||||||
#ifndef USE_OSD_SLAVE
|
#ifndef USE_OSD_SLAVE
|
||||||
suspendRxSignal();
|
suspendRxSignal();
|
||||||
#endif
|
#endif
|
||||||
|
@ -505,10 +503,9 @@ void resetEEPROM(void)
|
||||||
{
|
{
|
||||||
resetConfigs();
|
resetConfigs();
|
||||||
|
|
||||||
validateAndFixConfig();
|
|
||||||
activateConfig();
|
|
||||||
|
|
||||||
writeEEPROM();
|
writeEEPROM();
|
||||||
|
|
||||||
|
activateConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ensureEEPROMStructureIsValid(void)
|
void ensureEEPROMStructureIsValid(void)
|
||||||
|
@ -529,11 +526,11 @@ void saveConfigAndNotify(void)
|
||||||
#ifndef USE_OSD_SLAVE
|
#ifndef USE_OSD_SLAVE
|
||||||
void changePidProfile(uint8_t pidProfileIndex)
|
void changePidProfile(uint8_t pidProfileIndex)
|
||||||
{
|
{
|
||||||
if (pidProfileIndex >= MAX_PROFILE_COUNT) {
|
if (pidProfileIndex < MAX_PROFILE_COUNT) {
|
||||||
pidProfileIndex = MAX_PROFILE_COUNT - 1;
|
systemConfigMutable()->pidProfileIndex = pidProfileIndex;
|
||||||
|
loadPidProfile();
|
||||||
}
|
}
|
||||||
systemConfigMutable()->pidProfileIndex = pidProfileIndex;
|
|
||||||
currentPidProfile = pidProfilesMutable(pidProfileIndex);
|
|
||||||
beeperConfirmationBeeps(pidProfileIndex + 1);
|
beeperConfirmationBeeps(pidProfileIndex + 1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -57,7 +57,6 @@ void ensureEEPROMStructureIsValid(void);
|
||||||
|
|
||||||
void saveConfigAndNotify(void);
|
void saveConfigAndNotify(void);
|
||||||
void validateAndFixGyroConfig(void);
|
void validateAndFixGyroConfig(void);
|
||||||
void activateConfig(void);
|
|
||||||
|
|
||||||
uint8_t getCurrentPidProfileIndex(void);
|
uint8_t getCurrentPidProfileIndex(void);
|
||||||
void changePidProfile(uint8_t pidProfileIndex);
|
void changePidProfile(uint8_t pidProfileIndex);
|
||||||
|
|
|
@ -62,20 +62,18 @@ void pgResetFn_controlRateProfiles(controlRateConfig_t *controlRateConfig)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setControlRateProfile(uint8_t controlRateProfileIndex)
|
void loadControlRateProfile(void)
|
||||||
{
|
{
|
||||||
if (controlRateProfileIndex < CONTROL_RATE_PROFILE_COUNT) {
|
currentControlRateProfile = controlRateProfilesMutable(systemConfig()->activeRateProfile);
|
||||||
systemConfigMutable()->activeRateProfile = controlRateProfileIndex;
|
|
||||||
currentControlRateProfile = controlRateProfilesMutable(controlRateProfileIndex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void changeControlRateProfile(uint8_t controlRateProfileIndex)
|
void changeControlRateProfile(uint8_t controlRateProfileIndex)
|
||||||
{
|
{
|
||||||
if (controlRateProfileIndex >= CONTROL_RATE_PROFILE_COUNT) {
|
if (controlRateProfileIndex < CONTROL_RATE_PROFILE_COUNT) {
|
||||||
controlRateProfileIndex = CONTROL_RATE_PROFILE_COUNT - 1;
|
systemConfigMutable()->activeRateProfile = controlRateProfileIndex;
|
||||||
}
|
}
|
||||||
setControlRateProfile(controlRateProfileIndex);
|
|
||||||
|
loadControlRateProfile();
|
||||||
initRcProcessing();
|
initRcProcessing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ PG_DECLARE_ARRAY(controlRateConfig_t, CONTROL_RATE_PROFILE_COUNT, controlRatePro
|
||||||
|
|
||||||
extern controlRateConfig_t *currentControlRateProfile;
|
extern controlRateConfig_t *currentControlRateProfile;
|
||||||
|
|
||||||
void setControlRateProfile(uint8_t controlRateProfileIndex);
|
void loadControlRateProfile(void);
|
||||||
void changeControlRateProfile(uint8_t controlRateProfileIndex);
|
void changeControlRateProfile(uint8_t controlRateProfileIndex);
|
||||||
|
|
||||||
void copyControlRateProfile(const uint8_t dstControlRateProfileIndex, const uint8_t srcControlRateProfileIndex);
|
void copyControlRateProfile(const uint8_t dstControlRateProfileIndex, const uint8_t srcControlRateProfileIndex);
|
||||||
|
|
|
@ -250,8 +250,6 @@ void init(void)
|
||||||
|
|
||||||
if (!readSuccess || !isEEPROMVersionValid() || strncasecmp(systemConfig()->boardIdentifier, TARGET_BOARD_IDENTIFIER, sizeof(TARGET_BOARD_IDENTIFIER))) {
|
if (!readSuccess || !isEEPROMVersionValid() || strncasecmp(systemConfig()->boardIdentifier, TARGET_BOARD_IDENTIFIER, sizeof(TARGET_BOARD_IDENTIFIER))) {
|
||||||
resetEEPROM();
|
resetEEPROM();
|
||||||
|
|
||||||
activateConfig();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
systemState |= SYSTEM_STATE_CONFIG_LOADED;
|
systemState |= SYSTEM_STATE_CONFIG_LOADED;
|
||||||
|
|
|
@ -174,6 +174,10 @@ static uint32_t bufferIndex = 0;
|
||||||
|
|
||||||
static bool configIsInCopy = false;
|
static bool configIsInCopy = false;
|
||||||
|
|
||||||
|
#define CURRENT_PROFILE_INDEX -1
|
||||||
|
static int8_t pidProfileIndexToUse = CURRENT_PROFILE_INDEX;
|
||||||
|
static int8_t rateProfileIndexToUse = CURRENT_PROFILE_INDEX;
|
||||||
|
|
||||||
#if defined(USE_BOARD_INFO)
|
#if defined(USE_BOARD_INFO)
|
||||||
static bool boardInformationUpdated = false;
|
static bool boardInformationUpdated = false;
|
||||||
#if defined(USE_SIGNATURE)
|
#if defined(USE_SIGNATURE)
|
||||||
|
@ -487,15 +491,26 @@ static bool valuePtrEqualsDefault(const clivalue_t *var, const void *ptr, const
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint8_t getPidProfileIndexToUse()
|
||||||
|
{
|
||||||
|
return pidProfileIndexToUse == CURRENT_PROFILE_INDEX ? getCurrentPidProfileIndex() : pidProfileIndexToUse;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint8_t getRateProfileIndexToUse()
|
||||||
|
{
|
||||||
|
return rateProfileIndexToUse == CURRENT_PROFILE_INDEX ? getCurrentControlRateProfileIndex() : rateProfileIndexToUse;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static uint16_t getValueOffset(const clivalue_t *value)
|
static uint16_t getValueOffset(const clivalue_t *value)
|
||||||
{
|
{
|
||||||
switch (value->type & VALUE_SECTION_MASK) {
|
switch (value->type & VALUE_SECTION_MASK) {
|
||||||
case MASTER_VALUE:
|
case MASTER_VALUE:
|
||||||
return value->offset;
|
return value->offset;
|
||||||
case PROFILE_VALUE:
|
case PROFILE_VALUE:
|
||||||
return value->offset + sizeof(pidProfile_t) * getCurrentPidProfileIndex();
|
return value->offset + sizeof(pidProfile_t) * getPidProfileIndexToUse();
|
||||||
case PROFILE_RATE_VALUE:
|
case PROFILE_RATE_VALUE:
|
||||||
return value->offset + sizeof(controlRateConfig_t) * getCurrentControlRateProfileIndex();
|
return value->offset + sizeof(controlRateConfig_t) * getRateProfileIndexToUse();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -3157,12 +3172,12 @@ static void cliPlaySound(char *cmdline)
|
||||||
static void cliProfile(char *cmdline)
|
static void cliProfile(char *cmdline)
|
||||||
{
|
{
|
||||||
if (isEmpty(cmdline)) {
|
if (isEmpty(cmdline)) {
|
||||||
cliPrintLinef("profile %d", getCurrentPidProfileIndex());
|
cliPrintLinef("profile %d", getPidProfileIndexToUse());
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
const int i = atoi(cmdline);
|
const int i = atoi(cmdline);
|
||||||
if (i >= 0 && i < MAX_PROFILE_COUNT) {
|
if (i >= 0 && i < MAX_PROFILE_COUNT) {
|
||||||
systemConfigMutable()->pidProfileIndex = i;
|
changePidProfile(i);
|
||||||
cliProfile("");
|
cliProfile("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3171,7 +3186,7 @@ static void cliProfile(char *cmdline)
|
||||||
static void cliRateProfile(char *cmdline)
|
static void cliRateProfile(char *cmdline)
|
||||||
{
|
{
|
||||||
if (isEmpty(cmdline)) {
|
if (isEmpty(cmdline)) {
|
||||||
cliPrintLinef("rateprofile %d", getCurrentControlRateProfileIndex());
|
cliPrintLinef("rateprofile %d", getRateProfileIndexToUse());
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
const int i = atoi(cmdline);
|
const int i = atoi(cmdline);
|
||||||
|
@ -3188,11 +3203,15 @@ static void cliDumpPidProfile(uint8_t pidProfileIndex, uint8_t dumpMask)
|
||||||
// Faulty values
|
// Faulty values
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
changePidProfile(pidProfileIndex);
|
|
||||||
|
pidProfileIndexToUse = pidProfileIndex;
|
||||||
|
|
||||||
cliPrintHashLine("profile");
|
cliPrintHashLine("profile");
|
||||||
cliProfile("");
|
cliProfile("");
|
||||||
cliPrintLinefeed();
|
cliPrintLinefeed();
|
||||||
dumpAllValues(PROFILE_VALUE, dumpMask);
|
dumpAllValues(PROFILE_VALUE, dumpMask);
|
||||||
|
|
||||||
|
pidProfileIndexToUse = CURRENT_PROFILE_INDEX;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cliDumpRateProfile(uint8_t rateProfileIndex, uint8_t dumpMask)
|
static void cliDumpRateProfile(uint8_t rateProfileIndex, uint8_t dumpMask)
|
||||||
|
@ -3201,11 +3220,15 @@ static void cliDumpRateProfile(uint8_t rateProfileIndex, uint8_t dumpMask)
|
||||||
// Faulty values
|
// Faulty values
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
changeControlRateProfile(rateProfileIndex);
|
|
||||||
|
rateProfileIndexToUse = rateProfileIndex;
|
||||||
|
|
||||||
cliPrintHashLine("rateprofile");
|
cliPrintHashLine("rateprofile");
|
||||||
cliRateProfile("");
|
cliRateProfile("");
|
||||||
cliPrintLinefeed();
|
cliPrintLinefeed();
|
||||||
dumpAllValues(PROFILE_RATE_VALUE, dumpMask);
|
dumpAllValues(PROFILE_RATE_VALUE, dumpMask);
|
||||||
|
|
||||||
|
rateProfileIndexToUse = CURRENT_PROFILE_INDEX;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cliSave(char *cmdline)
|
static void cliSave(char *cmdline)
|
||||||
|
@ -3226,6 +3249,7 @@ static void cliSave(char *cmdline)
|
||||||
#endif // USE_BOARD_INFO
|
#endif // USE_BOARD_INFO
|
||||||
|
|
||||||
writeEEPROM();
|
writeEEPROM();
|
||||||
|
|
||||||
cliReboot();
|
cliReboot();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3242,7 +3266,9 @@ static void cliDefaults(char *cmdline)
|
||||||
}
|
}
|
||||||
|
|
||||||
cliPrintHashLine("resetting to defaults");
|
cliPrintHashLine("resetting to defaults");
|
||||||
|
|
||||||
resetConfigs();
|
resetConfigs();
|
||||||
|
|
||||||
if (saveConfigs) {
|
if (saveConfigs) {
|
||||||
cliSave(NULL);
|
cliSave(NULL);
|
||||||
}
|
}
|
||||||
|
@ -3268,6 +3294,9 @@ STATIC_UNIT_TESTED void cliGet(char *cmdline)
|
||||||
const clivalue_t *val;
|
const clivalue_t *val;
|
||||||
int matchedCommands = 0;
|
int matchedCommands = 0;
|
||||||
|
|
||||||
|
pidProfileIndexToUse = getCurrentPidProfileIndex();
|
||||||
|
rateProfileIndexToUse = getCurrentControlRateProfileIndex();
|
||||||
|
|
||||||
backupAndResetConfigs();
|
backupAndResetConfigs();
|
||||||
|
|
||||||
for (uint32_t i = 0; i < valueTableEntryCount; i++) {
|
for (uint32_t i = 0; i < valueTableEntryCount; i++) {
|
||||||
|
@ -3287,6 +3316,9 @@ STATIC_UNIT_TESTED void cliGet(char *cmdline)
|
||||||
|
|
||||||
restoreConfigs();
|
restoreConfigs();
|
||||||
|
|
||||||
|
pidProfileIndexToUse = CURRENT_PROFILE_INDEX;
|
||||||
|
rateProfileIndexToUse = CURRENT_PROFILE_INDEX;
|
||||||
|
|
||||||
if (matchedCommands) {
|
if (matchedCommands) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -4199,22 +4231,28 @@ static void printConfig(char *cmdline, bool doDiff)
|
||||||
dumpAllValues(MASTER_VALUE, dumpMask);
|
dumpAllValues(MASTER_VALUE, dumpMask);
|
||||||
|
|
||||||
if (dumpMask & DUMP_ALL) {
|
if (dumpMask & DUMP_ALL) {
|
||||||
const uint8_t pidProfileIndexSave = systemConfig_Copy.pidProfileIndex;
|
|
||||||
for (uint32_t pidProfileIndex = 0; pidProfileIndex < MAX_PROFILE_COUNT; pidProfileIndex++) {
|
for (uint32_t pidProfileIndex = 0; pidProfileIndex < MAX_PROFILE_COUNT; pidProfileIndex++) {
|
||||||
cliDumpPidProfile(pidProfileIndex, dumpMask);
|
cliDumpPidProfile(pidProfileIndex, dumpMask);
|
||||||
}
|
}
|
||||||
changePidProfile(pidProfileIndexSave);
|
|
||||||
cliPrintHashLine("restore original profile selection");
|
cliPrintHashLine("restore original profile selection");
|
||||||
|
|
||||||
|
pidProfileIndexToUse = systemConfig_Copy.pidProfileIndex;
|
||||||
|
|
||||||
cliProfile("");
|
cliProfile("");
|
||||||
|
|
||||||
const uint8_t controlRateProfileIndexSave = systemConfig_Copy.activeRateProfile;
|
pidProfileIndexToUse = CURRENT_PROFILE_INDEX;
|
||||||
|
|
||||||
for (uint32_t rateIndex = 0; rateIndex < CONTROL_RATE_PROFILE_COUNT; rateIndex++) {
|
for (uint32_t rateIndex = 0; rateIndex < CONTROL_RATE_PROFILE_COUNT; rateIndex++) {
|
||||||
cliDumpRateProfile(rateIndex, dumpMask);
|
cliDumpRateProfile(rateIndex, dumpMask);
|
||||||
}
|
}
|
||||||
changeControlRateProfile(controlRateProfileIndexSave);
|
|
||||||
cliPrintHashLine("restore original rateprofile selection");
|
cliPrintHashLine("restore original rateprofile selection");
|
||||||
|
|
||||||
|
rateProfileIndexToUse = systemConfig_Copy.activeRateProfile;
|
||||||
|
|
||||||
cliRateProfile("");
|
cliRateProfile("");
|
||||||
|
|
||||||
|
rateProfileIndexToUse = CURRENT_PROFILE_INDEX;
|
||||||
|
|
||||||
cliPrintHashLine("save configuration");
|
cliPrintHashLine("save configuration");
|
||||||
cliPrint("save");
|
cliPrint("save");
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue