mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-14 11:59:58 +03:00
Extended configuration status to accommodate custom defaults.
This commit is contained in:
parent
227f6f76a2
commit
1c8cfbd241
8 changed files with 85 additions and 69 deletions
|
@ -676,7 +676,7 @@ static void backupAndResetConfigs(const bool useCustomDefaults)
|
||||||
backupConfigs();
|
backupConfigs();
|
||||||
|
|
||||||
// reset all configs to defaults to do differencing
|
// reset all configs to defaults to do differencing
|
||||||
resetConfigs();
|
resetConfig();
|
||||||
|
|
||||||
#if defined(USE_CUSTOM_DEFAULTS)
|
#if defined(USE_CUSTOM_DEFAULTS)
|
||||||
if (useCustomDefaults) {
|
if (useCustomDefaults) {
|
||||||
|
@ -4136,7 +4136,7 @@ static void cliBatch(char *cmdline)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static bool doSave(void)
|
static bool prepareSave(void)
|
||||||
{
|
{
|
||||||
#if defined(USE_CUSTOM_DEFAULTS)
|
#if defined(USE_CUSTOM_DEFAULTS)
|
||||||
if (processingCustomDefaults) {
|
if (processingCustomDefaults) {
|
||||||
|
@ -4162,53 +4162,56 @@ static bool doSave(void)
|
||||||
#endif // USE_BOARD_INFO
|
#endif // USE_BOARD_INFO
|
||||||
|
|
||||||
if (featureMaskIsCopied) {
|
if (featureMaskIsCopied) {
|
||||||
writeEEPROMWithFeatures(featureMaskCopy);
|
featureDisableAll();
|
||||||
} else {
|
featureEnable(featureMaskCopy);
|
||||||
writeEEPROM();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool tryPrepareSave(void)
|
||||||
|
{
|
||||||
|
bool success = prepareSave();
|
||||||
|
#if defined(USE_CLI_BATCH)
|
||||||
|
if (!success) {
|
||||||
|
cliPrintCommandBatchWarning("PLEASE FIX ERRORS THEN 'SAVE'");
|
||||||
|
resetCommandBatch();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
UNUSED(success);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static void cliSave(char *cmdline)
|
static void cliSave(char *cmdline)
|
||||||
{
|
{
|
||||||
UNUSED(cmdline);
|
UNUSED(cmdline);
|
||||||
|
|
||||||
#if defined(USE_CLI_BATCH)
|
if (tryPrepareSave()) {
|
||||||
if (!doSave()) {
|
writeEEPROM();
|
||||||
cliPrintCommandBatchWarning("PLEASE FIX ERRORS THEN 'SAVE'");
|
|
||||||
resetCommandBatch();
|
|
||||||
|
|
||||||
return;
|
|
||||||
} else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
cliPrintHashLine("saving");
|
cliPrintHashLine("saving");
|
||||||
}
|
|
||||||
|
|
||||||
cliReboot();
|
cliReboot();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cliResetConfig(bool useCustomDefaults)
|
#if defined(USE_CUSTOM_DEFAULTS)
|
||||||
|
bool resetConfigToCustomDefaults(void)
|
||||||
{
|
{
|
||||||
resetConfigs();
|
resetConfig();
|
||||||
|
|
||||||
#ifdef USE_CLI_BATCH
|
#ifdef USE_CLI_BATCH
|
||||||
commandBatchError = false;
|
commandBatchError = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USE_CUSTOM_DEFAULTS)
|
cliProcessCustomDefaults();
|
||||||
if (useCustomDefaults) {
|
|
||||||
cliProcessCustomDefaults();
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
UNUSED(useCustomDefaults);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return doSave();
|
return prepareSave();
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(USE_CUSTOM_DEFAULTS)
|
|
||||||
static bool isCustomDefaults(char *ptr)
|
static bool isCustomDefaults(char *ptr)
|
||||||
{
|
{
|
||||||
return strncmp(ptr, "# " FC_FIRMWARE_NAME, 12) == 0;
|
return strncmp(ptr, "# " FC_FIRMWARE_NAME, 12) == 0;
|
||||||
|
@ -4263,7 +4266,7 @@ static void cliDefaults(char *cmdline)
|
||||||
|
|
||||||
cliPrintHashLine("resetting to defaults");
|
cliPrintHashLine("resetting to defaults");
|
||||||
|
|
||||||
resetConfigs();
|
resetConfig();
|
||||||
|
|
||||||
#ifdef USE_CLI_BATCH
|
#ifdef USE_CLI_BATCH
|
||||||
// Reset only the error state and allow the batch active state to remain.
|
// Reset only the error state and allow the batch active state to remain.
|
||||||
|
@ -4279,8 +4282,10 @@ static void cliDefaults(char *cmdline)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (saveConfigs) {
|
if (saveConfigs && tryPrepareSave()) {
|
||||||
cliSave(NULL);
|
writeUnmodifiedConfigToEEPROM();
|
||||||
|
|
||||||
|
cliReboot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6533,6 +6538,8 @@ bool cliProcessCustomDefaults(void)
|
||||||
memcpy(cliBuffer, cliBufferTemp, sizeof(cliBuffer));
|
memcpy(cliBuffer, cliBufferTemp, sizeof(cliBuffer));
|
||||||
bufferIndex = bufferIndexTemp;
|
bufferIndex = bufferIndexTemp;
|
||||||
|
|
||||||
|
systemConfigMutable()->configurationState = CONFIGURATION_STATE_DEFAULTS_CUSTOM;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -28,4 +28,4 @@ void cliProcess(void);
|
||||||
bool hasCustomDefaults(void);
|
bool hasCustomDefaults(void);
|
||||||
struct serialPort_s;
|
struct serialPort_s;
|
||||||
void cliEnter(struct serialPort_s *serialPort);
|
void cliEnter(struct serialPort_s *serialPort);
|
||||||
bool cliResetConfig(bool useCustomDefaults);
|
bool resetConfigToCustomDefaults(void);
|
||||||
|
|
|
@ -112,7 +112,7 @@ PG_RESET_TEMPLATE(systemConfig_t, systemConfig,
|
||||||
.powerOnArmingGraceTime = 5,
|
.powerOnArmingGraceTime = 5,
|
||||||
.boardIdentifier = TARGET_BOARD_IDENTIFIER,
|
.boardIdentifier = TARGET_BOARD_IDENTIFIER,
|
||||||
.hseMhz = SYSTEM_HSE_VALUE, // Not used for non-F4 targets
|
.hseMhz = SYSTEM_HSE_VALUE, // Not used for non-F4 targets
|
||||||
.configured = false,
|
.configurationState = CONFIGURATION_STATE_DEFAULTS_BARE,
|
||||||
.schedulerOptimizeRate = true,
|
.schedulerOptimizeRate = true,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ uint16_t getCurrentMinthrottle(void)
|
||||||
return motorConfig()->minthrottle;
|
return motorConfig()->minthrottle;
|
||||||
}
|
}
|
||||||
|
|
||||||
void resetConfigs(void)
|
void resetConfig(void)
|
||||||
{
|
{
|
||||||
pgResetAll();
|
pgResetAll();
|
||||||
|
|
||||||
|
@ -688,20 +688,12 @@ bool readEEPROM(void)
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ValidateAndWriteConfigToEEPROM(bool setConfigured)
|
void writeUnmodifiedConfigToEEPROM(void)
|
||||||
{
|
{
|
||||||
validateAndFixConfig();
|
validateAndFixConfig();
|
||||||
|
|
||||||
suspendRxPwmPpmSignal();
|
suspendRxPwmPpmSignal();
|
||||||
|
|
||||||
#ifdef USE_CONFIGURATION_STATE
|
|
||||||
if (setConfigured) {
|
|
||||||
systemConfigMutable()->configured = true;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
UNUSED(setConfigured);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
writeConfigToEEPROM();
|
writeConfigToEEPROM();
|
||||||
|
|
||||||
resumeRxPwmPpmSignal();
|
resumeRxPwmPpmSignal();
|
||||||
|
@ -710,7 +702,9 @@ static void ValidateAndWriteConfigToEEPROM(bool setConfigured)
|
||||||
|
|
||||||
void writeEEPROM(void)
|
void writeEEPROM(void)
|
||||||
{
|
{
|
||||||
ValidateAndWriteConfigToEEPROM(true);
|
systemConfigMutable()->configurationState = CONFIGURATION_STATE_CONFIGURED;
|
||||||
|
|
||||||
|
writeUnmodifiedConfigToEEPROM();
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeEEPROMWithFeatures(uint32_t features)
|
void writeEEPROMWithFeatures(uint32_t features)
|
||||||
|
@ -718,18 +712,27 @@ void writeEEPROMWithFeatures(uint32_t features)
|
||||||
featureDisableAll();
|
featureDisableAll();
|
||||||
featureEnable(features);
|
featureEnable(features);
|
||||||
|
|
||||||
ValidateAndWriteConfigToEEPROM(true);
|
writeEEPROM();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool resetEEPROM(bool useCustomDefaults)
|
bool resetEEPROM(bool useCustomDefaults)
|
||||||
{
|
{
|
||||||
if (cliResetConfig(useCustomDefaults)) {
|
#if !defined(USE_CUSTOM_DEFAULTS)
|
||||||
activateConfig();
|
UNUSED(useCustomDefaults);
|
||||||
|
#else
|
||||||
return true;
|
if (useCustomDefaults) {
|
||||||
|
if (!resetConfigToCustomDefaults()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
resetConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
writeUnmodifiedConfigToEEPROM();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ensureEEPROMStructureIsValid(void)
|
void ensureEEPROMStructureIsValid(void)
|
||||||
|
@ -742,7 +745,7 @@ void ensureEEPROMStructureIsValid(void)
|
||||||
|
|
||||||
void saveConfigAndNotify(void)
|
void saveConfigAndNotify(void)
|
||||||
{
|
{
|
||||||
ValidateAndWriteConfigToEEPROM(true);
|
writeEEPROM();
|
||||||
readEEPROM();
|
readEEPROM();
|
||||||
beeperConfirmationBeeps(1);
|
beeperConfirmationBeeps(1);
|
||||||
}
|
}
|
||||||
|
@ -797,11 +800,7 @@ void changePidProfile(uint8_t pidProfileIndex)
|
||||||
|
|
||||||
bool isSystemConfigured(void)
|
bool isSystemConfigured(void)
|
||||||
{
|
{
|
||||||
#ifdef USE_CONFIGURATION_STATE
|
return systemConfig()->configurationState == CONFIGURATION_STATE_CONFIGURED;
|
||||||
return systemConfig()->configured;
|
|
||||||
#else
|
|
||||||
return true;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setRebootRequired(void)
|
void setRebootRequired(void)
|
||||||
|
|
|
@ -29,6 +29,12 @@
|
||||||
|
|
||||||
#define MAX_PROFILE_NAME_LENGTH 8u
|
#define MAX_PROFILE_NAME_LENGTH 8u
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
CONFIGURATION_STATE_DEFAULTS_BARE = 0,
|
||||||
|
CONFIGURATION_STATE_DEFAULTS_CUSTOM,
|
||||||
|
CONFIGURATION_STATE_CONFIGURED,
|
||||||
|
} configurationState_e;
|
||||||
|
|
||||||
typedef struct pilotConfig_s {
|
typedef struct pilotConfig_s {
|
||||||
char name[MAX_NAME_LENGTH + 1];
|
char name[MAX_NAME_LENGTH + 1];
|
||||||
char displayName[MAX_NAME_LENGTH + 1];
|
char displayName[MAX_NAME_LENGTH + 1];
|
||||||
|
@ -46,7 +52,7 @@ typedef struct systemConfig_s {
|
||||||
uint8_t powerOnArmingGraceTime; // in seconds
|
uint8_t powerOnArmingGraceTime; // in seconds
|
||||||
char boardIdentifier[sizeof(TARGET_BOARD_IDENTIFIER) + 1];
|
char boardIdentifier[sizeof(TARGET_BOARD_IDENTIFIER) + 1];
|
||||||
uint8_t hseMhz; // Not used for non-F4 targets
|
uint8_t hseMhz; // Not used for non-F4 targets
|
||||||
uint8_t configured;
|
uint8_t configurationState; // The state of the configuration (defaults / configured)
|
||||||
uint8_t schedulerOptimizeRate;
|
uint8_t schedulerOptimizeRate;
|
||||||
} systemConfig_t;
|
} systemConfig_t;
|
||||||
|
|
||||||
|
@ -55,12 +61,12 @@ PG_DECLARE(systemConfig_t, systemConfig);
|
||||||
struct pidProfile_s;
|
struct pidProfile_s;
|
||||||
extern struct pidProfile_s *currentPidProfile;
|
extern struct pidProfile_s *currentPidProfile;
|
||||||
|
|
||||||
|
|
||||||
void initEEPROM(void);
|
void initEEPROM(void);
|
||||||
bool resetEEPROM(bool useCustomDefaults);
|
bool resetEEPROM(bool useCustomDefaults);
|
||||||
bool readEEPROM(void);
|
bool readEEPROM(void);
|
||||||
void writeEEPROM(void);
|
void writeEEPROM(void);
|
||||||
void writeEEPROMWithFeatures(uint32_t features);
|
void writeEEPROMWithFeatures(uint32_t features);
|
||||||
|
void writeUnmodifiedConfigToEEPROM(void);
|
||||||
void ensureEEPROMStructureIsValid(void);
|
void ensureEEPROMStructureIsValid(void);
|
||||||
|
|
||||||
void saveConfigAndNotify(void);
|
void saveConfigAndNotify(void);
|
||||||
|
@ -82,7 +88,7 @@ bool canSoftwareSerialBeUsed(void);
|
||||||
|
|
||||||
uint16_t getCurrentMinthrottle(void);
|
uint16_t getCurrentMinthrottle(void);
|
||||||
|
|
||||||
void resetConfigs(void);
|
void resetConfig(void);
|
||||||
void targetConfiguration(void);
|
void targetConfiguration(void);
|
||||||
void targetValidateConfiguration(void);
|
void targetValidateConfiguration(void);
|
||||||
|
|
||||||
|
|
|
@ -662,7 +662,11 @@ void init(void)
|
||||||
|
|
||||||
if (!sensorsAutodetect()) {
|
if (!sensorsAutodetect()) {
|
||||||
// if gyro was not detected due to whatever reason, notify and don't arm.
|
// if gyro was not detected due to whatever reason, notify and don't arm.
|
||||||
if (isSystemConfigured()) {
|
if (true
|
||||||
|
#if defined(USE_UNIFIED_TARGET)
|
||||||
|
&& isSystemConfigured()
|
||||||
|
#endif
|
||||||
|
) {
|
||||||
indicateFailure(FAILURE_MISSING_ACC, 2);
|
indicateFailure(FAILURE_MISSING_ACC, 2);
|
||||||
}
|
}
|
||||||
setArmingDisabled(ARMING_DISABLED_NO_GYRO);
|
setArmingDisabled(ARMING_DISABLED_NO_GYRO);
|
||||||
|
|
|
@ -531,8 +531,8 @@ static bool mspCommonProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProce
|
||||||
#define TARGET_HAS_SOFTSERIAL_BIT 1
|
#define TARGET_HAS_SOFTSERIAL_BIT 1
|
||||||
#define TARGET_IS_UNIFIED_BIT 2
|
#define TARGET_IS_UNIFIED_BIT 2
|
||||||
#define TARGET_HAS_FLASH_BOOTLOADER_BIT 3
|
#define TARGET_HAS_FLASH_BOOTLOADER_BIT 3
|
||||||
#define TARGET_SUPPORTS_CUSTOM_DEFAULTS 4
|
#define TARGET_SUPPORTS_CUSTOM_DEFAULTS_BIT 4
|
||||||
#define TARGET_HAS_CUSTOM_DEFAULTS 5
|
#define TARGET_HAS_CUSTOM_DEFAULTS_BIT 5
|
||||||
|
|
||||||
uint8_t targetCapabilities = 0;
|
uint8_t targetCapabilities = 0;
|
||||||
#ifdef USE_VCP
|
#ifdef USE_VCP
|
||||||
|
@ -548,9 +548,9 @@ static bool mspCommonProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProce
|
||||||
targetCapabilities |= 1 << TARGET_HAS_FLASH_BOOTLOADER_BIT;
|
targetCapabilities |= 1 << TARGET_HAS_FLASH_BOOTLOADER_BIT;
|
||||||
#endif
|
#endif
|
||||||
#if defined(USE_CUSTOM_DEFAULTS)
|
#if defined(USE_CUSTOM_DEFAULTS)
|
||||||
targetCapabilities |= 1 << TARGET_SUPPORTS_CUSTOM_DEFAULTS;
|
targetCapabilities |= 1 << TARGET_SUPPORTS_CUSTOM_DEFAULTS_BIT;
|
||||||
if (hasCustomDefaults()) {
|
if (hasCustomDefaults()) {
|
||||||
targetCapabilities |= 1 << TARGET_HAS_CUSTOM_DEFAULTS;
|
targetCapabilities |= 1 << TARGET_HAS_CUSTOM_DEFAULTS_BIT;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -586,6 +586,9 @@ static bool mspCommonProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProce
|
||||||
|
|
||||||
sbufWriteU8(dst, MCU_TYPE_ID);
|
sbufWriteU8(dst, MCU_TYPE_ID);
|
||||||
|
|
||||||
|
// Added in API version 1.42
|
||||||
|
sbufWriteU8(dst, systemConfig()->configurationState);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -226,10 +226,6 @@
|
||||||
#define USE_RX_XN297
|
#define USE_RX_XN297
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_UNIFIED_TARGET
|
|
||||||
#define USE_CONFIGURATION_STATE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Setup crystal frequency on F4 for backward compatibility
|
// Setup crystal frequency on F4 for backward compatibility
|
||||||
// Should be set to zero for generic targets to ensure USB is working
|
// Should be set to zero for generic targets to ensure USB is working
|
||||||
// when unconfigured for targets with non-standard crystal.
|
// when unconfigured for targets with non-standard crystal.
|
||||||
|
|
|
@ -331,8 +331,9 @@ void setArmingDisabled(armingDisableFlags_e) {}
|
||||||
|
|
||||||
void waitForSerialPortToFinishTransmitting(serialPort_t *) {}
|
void waitForSerialPortToFinishTransmitting(serialPort_t *) {}
|
||||||
void systemResetToBootloader(void) {}
|
void systemResetToBootloader(void) {}
|
||||||
void resetConfigs(void) {}
|
void resetConfig(void) {}
|
||||||
void systemReset(void) {}
|
void systemReset(void) {}
|
||||||
|
void writeUnmodifiedConfigToEEPROM(void) {}
|
||||||
|
|
||||||
void changePidProfile(uint8_t) {}
|
void changePidProfile(uint8_t) {}
|
||||||
bool serialIsPortAvailable(serialPortIdentifier_e) { return false; }
|
bool serialIsPortAvailable(serialPortIdentifier_e) { return false; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue