mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-15 12:25:20 +03:00
Added support for resetting to custom defaults to MSP.
This commit is contained in:
parent
e38d460acf
commit
772b249a3f
7 changed files with 115 additions and 30 deletions
|
@ -667,6 +667,10 @@ static bool isWritingConfigToCopy()
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(USE_CUSTOM_DEFAULTS)
|
||||||
|
bool cliProcessCustomDefaults(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
static void backupAndResetConfigs(const bool useCustomDefaults)
|
static void backupAndResetConfigs(const bool useCustomDefaults)
|
||||||
{
|
{
|
||||||
backupConfigs();
|
backupConfigs();
|
||||||
|
@ -4132,26 +4136,20 @@ static void cliBatch(char *cmdline)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void cliSave(char *cmdline)
|
static bool doSave(void)
|
||||||
{
|
{
|
||||||
UNUSED(cmdline);
|
|
||||||
|
|
||||||
#if defined(USE_CUSTOM_DEFAULTS)
|
#if defined(USE_CUSTOM_DEFAULTS)
|
||||||
if (processingCustomDefaults) {
|
if (processingCustomDefaults) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_CLI_BATCH
|
#ifdef USE_CLI_BATCH
|
||||||
if (commandBatchActive && commandBatchError) {
|
if (commandBatchActive && commandBatchError) {
|
||||||
cliPrintCommandBatchWarning("PLEASE FIX ERRORS THEN 'SAVE'");
|
return false;
|
||||||
resetCommandBatch();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
cliPrintHashLine("saving");
|
|
||||||
|
|
||||||
#if defined(USE_BOARD_INFO)
|
#if defined(USE_BOARD_INFO)
|
||||||
if (boardInformationUpdated) {
|
if (boardInformationUpdated) {
|
||||||
persistBoardInformation();
|
persistBoardInformation();
|
||||||
|
@ -4169,14 +4167,54 @@ static void cliSave(char *cmdline)
|
||||||
writeEEPROM();
|
writeEEPROM();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cliSave(char *cmdline)
|
||||||
|
{
|
||||||
|
UNUSED(cmdline);
|
||||||
|
|
||||||
|
if (!doSave()) {
|
||||||
|
cliPrintCommandBatchWarning("PLEASE FIX ERRORS THEN 'SAVE'");
|
||||||
|
resetCommandBatch();
|
||||||
|
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
cliPrintHashLine("saving");
|
||||||
|
}
|
||||||
|
|
||||||
cliReboot();
|
cliReboot();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool cliResetConfig(bool useCustomDefaults)
|
||||||
|
{
|
||||||
|
resetConfigs();
|
||||||
|
|
||||||
|
#ifdef USE_CLI_BATCH
|
||||||
|
commandBatchError = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(USE_CUSTOM_DEFAULTS)
|
#if defined(USE_CUSTOM_DEFAULTS)
|
||||||
static bool isDefaults(char *ptr)
|
if (useCustomDefaults) {
|
||||||
|
cliProcessCustomDefaults();
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
UNUSED(useCustomDefaults);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return doSave();
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(USE_CUSTOM_DEFAULTS)
|
||||||
|
static bool isCustomDefaults(char *ptr)
|
||||||
{
|
{
|
||||||
return strncmp(ptr, "# " FC_FIRMWARE_NAME, 12) == 0;
|
return strncmp(ptr, "# " FC_FIRMWARE_NAME, 12) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool hasCustomDefaults(void)
|
||||||
|
{
|
||||||
|
return isCustomDefaults(customDefaultsStart);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void cliDefaults(char *cmdline)
|
static void cliDefaults(char *cmdline)
|
||||||
|
@ -4199,7 +4237,7 @@ static void cliDefaults(char *cmdline)
|
||||||
useCustomDefaults = false;
|
useCustomDefaults = false;
|
||||||
} else if (strncasecmp(cmdline, "show", 4) == 0) {
|
} else if (strncasecmp(cmdline, "show", 4) == 0) {
|
||||||
char *customDefaultsPtr = customDefaultsStart;
|
char *customDefaultsPtr = customDefaultsStart;
|
||||||
if (isDefaults(customDefaultsPtr)) {
|
if (isCustomDefaults(customDefaultsPtr)) {
|
||||||
while (*customDefaultsPtr && *customDefaultsPtr != 0xFF && customDefaultsPtr < customDefaultsEnd) {
|
while (*customDefaultsPtr && *customDefaultsPtr != 0xFF && customDefaultsPtr < customDefaultsEnd) {
|
||||||
if (*customDefaultsPtr != '\n') {
|
if (*customDefaultsPtr != '\n') {
|
||||||
cliPrintf("%c", *customDefaultsPtr++);
|
cliPrintf("%c", *customDefaultsPtr++);
|
||||||
|
@ -6468,7 +6506,7 @@ void cliProcess(void)
|
||||||
bool cliProcessCustomDefaults(void)
|
bool cliProcessCustomDefaults(void)
|
||||||
{
|
{
|
||||||
char *customDefaultsPtr = customDefaultsStart;
|
char *customDefaultsPtr = customDefaultsStart;
|
||||||
if (processingCustomDefaults || !isDefaults(customDefaultsPtr)) {
|
if (processingCustomDefaults || !isCustomDefaults(customDefaultsPtr)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
extern bool cliMode;
|
extern bool cliMode;
|
||||||
|
|
||||||
void cliProcess(void);
|
void cliProcess(void);
|
||||||
bool cliProcessCustomDefaults(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);
|
||||||
|
|
|
@ -30,6 +30,8 @@
|
||||||
|
|
||||||
#include "build/debug.h"
|
#include "build/debug.h"
|
||||||
|
|
||||||
|
#include "cli/cli.h"
|
||||||
|
|
||||||
#include "config/config_eeprom.h"
|
#include "config/config_eeprom.h"
|
||||||
#include "config/feature.h"
|
#include "config/feature.h"
|
||||||
|
|
||||||
|
@ -727,13 +729,15 @@ void writeEEPROMWithFeatures(uint32_t features)
|
||||||
ValidateAndWriteConfigToEEPROM(true);
|
ValidateAndWriteConfigToEEPROM(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void resetEEPROM(void)
|
bool resetEEPROM(bool useCustomDefaults)
|
||||||
{
|
{
|
||||||
resetConfigs();
|
if (cliResetConfig(useCustomDefaults)) {
|
||||||
|
|
||||||
ValidateAndWriteConfigToEEPROM(false);
|
|
||||||
|
|
||||||
activateConfig();
|
activateConfig();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ensureEEPROMStructureIsValid(void)
|
void ensureEEPROMStructureIsValid(void)
|
||||||
|
@ -741,7 +745,7 @@ void ensureEEPROMStructureIsValid(void)
|
||||||
if (isEEPROMStructureValid()) {
|
if (isEEPROMStructureValid()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
resetEEPROM();
|
resetEEPROM(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveConfigAndNotify(void)
|
void saveConfigAndNotify(void)
|
||||||
|
|
|
@ -57,7 +57,7 @@ extern struct pidProfile_s *currentPidProfile;
|
||||||
|
|
||||||
|
|
||||||
void initEEPROM(void);
|
void initEEPROM(void);
|
||||||
void resetEEPROM(void);
|
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);
|
||||||
|
|
|
@ -391,7 +391,7 @@ void init(void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
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(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
systemState |= SYSTEM_STATE_CONFIG_LOADED;
|
systemState |= SYSTEM_STATE_CONFIG_LOADED;
|
||||||
|
@ -442,7 +442,7 @@ void init(void)
|
||||||
bothButtonsHeld = buttonAPressed() && buttonBPressed();
|
bothButtonsHeld = buttonAPressed() && buttonBPressed();
|
||||||
if (bothButtonsHeld) {
|
if (bothButtonsHeld) {
|
||||||
if (--secondsRemaining == 0) {
|
if (--secondsRemaining == 0) {
|
||||||
resetEEPROM();
|
resetEEPROM(false);
|
||||||
#ifdef USE_PERSISTENT_OBJECTS
|
#ifdef USE_PERSISTENT_OBJECTS
|
||||||
persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON, RESET_NONE);
|
persistentObjectWrite(PERSISTENT_OBJECT_RESET_REASON, RESET_NONE);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -34,6 +34,8 @@
|
||||||
#include "build/debug.h"
|
#include "build/debug.h"
|
||||||
#include "build/version.h"
|
#include "build/version.h"
|
||||||
|
|
||||||
|
#include "cli/cli.h"
|
||||||
|
|
||||||
#include "common/axis.h"
|
#include "common/axis.h"
|
||||||
#include "common/bitarray.h"
|
#include "common/bitarray.h"
|
||||||
#include "common/color.h"
|
#include "common/color.h"
|
||||||
|
@ -173,6 +175,11 @@ typedef enum {
|
||||||
|
|
||||||
#define RTC_NOT_SUPPORTED 0xff
|
#define RTC_NOT_SUPPORTED 0xff
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
DEFAULTS_TYPE_BASE = 0,
|
||||||
|
DEFAULTS_TYPE_CUSTOM,
|
||||||
|
} defaultsType_e;
|
||||||
|
|
||||||
#ifdef USE_VTX_TABLE
|
#ifdef USE_VTX_TABLE
|
||||||
static bool vtxTableNeedsInit = false;
|
static bool vtxTableNeedsInit = false;
|
||||||
#endif
|
#endif
|
||||||
|
@ -524,6 +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_HAS_CUSTOM_DEFAULTS 5
|
||||||
|
|
||||||
uint8_t targetCapabilities = 0;
|
uint8_t targetCapabilities = 0;
|
||||||
#ifdef USE_VCP
|
#ifdef USE_VCP
|
||||||
|
@ -538,6 +547,13 @@ static bool mspCommonProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProce
|
||||||
#if defined(USE_FLASH_BOOT_LOADER)
|
#if defined(USE_FLASH_BOOT_LOADER)
|
||||||
targetCapabilities |= 1 << TARGET_HAS_FLASH_BOOTLOADER_BIT;
|
targetCapabilities |= 1 << TARGET_HAS_FLASH_BOOTLOADER_BIT;
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(USE_CUSTOM_DEFAULTS)
|
||||||
|
targetCapabilities |= 1 << TARGET_SUPPORTS_CUSTOM_DEFAULTS;
|
||||||
|
if (hasCustomDefaults()) {
|
||||||
|
targetCapabilities |= 1 << TARGET_HAS_CUSTOM_DEFAULTS;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
sbufWriteU8(dst, targetCapabilities);
|
sbufWriteU8(dst, targetCapabilities);
|
||||||
|
|
||||||
// Target name with explicit length
|
// Target name with explicit length
|
||||||
|
@ -1843,6 +1859,39 @@ static mspResult_e mspFcProcessOutCommandWithArg(uint8_t cmdMSP, sbuf_t *src, sb
|
||||||
break;
|
break;
|
||||||
#endif // USE_VTX_TABLE
|
#endif // USE_VTX_TABLE
|
||||||
|
|
||||||
|
case MSP_RESET_CONF:
|
||||||
|
{
|
||||||
|
#if defined(USE_CUSTOM_DEFAULTS)
|
||||||
|
defaultsType_e defaultsType = DEFAULTS_TYPE_CUSTOM;
|
||||||
|
#endif
|
||||||
|
if (sbufBytesRemaining(src) >= 1) {
|
||||||
|
// Added in MSP API 1.42
|
||||||
|
#if defined(USE_CUSTOM_DEFAULTS)
|
||||||
|
defaultsType = sbufReadU8(src);
|
||||||
|
#else
|
||||||
|
sbufReadU8(src);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
bool success = false;
|
||||||
|
if (!ARMING_FLAG(ARMED)) {
|
||||||
|
#if defined(USE_CUSTOM_DEFAULTS)
|
||||||
|
success = resetEEPROM(defaultsType == DEFAULTS_TYPE_CUSTOM);
|
||||||
|
#else
|
||||||
|
success = resetEEPROM(false);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (success && mspPostProcessFn) {
|
||||||
|
rebootMode = MSP_REBOOT_FIRMWARE;
|
||||||
|
*mspPostProcessFn = mspRebootFn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Added in API version 1.42
|
||||||
|
sbufWriteU8(dst, success);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return MSP_RESULT_CMD_UNKNOWN;
|
return MSP_RESULT_CMD_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
@ -2415,13 +2464,6 @@ static mspResult_e mspProcessInCommand(uint8_t cmdMSP, sbuf_t *src)
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSP_RESET_CONF:
|
|
||||||
if (!ARMING_FLAG(ARMED)) {
|
|
||||||
resetEEPROM();
|
|
||||||
readEEPROM();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
#ifdef USE_ACC
|
#ifdef USE_ACC
|
||||||
case MSP_ACC_CALIBRATION:
|
case MSP_ACC_CALIBRATION:
|
||||||
if (!ARMING_FLAG(ARMED))
|
if (!ARMING_FLAG(ARMED))
|
||||||
|
|
|
@ -265,7 +265,7 @@ void beeperOffSet(uint32_t) {}
|
||||||
void beeperOffClear(uint32_t) {}
|
void beeperOffClear(uint32_t) {}
|
||||||
void beeperOffClearAll(void) {}
|
void beeperOffClearAll(void) {}
|
||||||
bool parseColor(int, const char *) {return false; }
|
bool parseColor(int, const char *) {return false; }
|
||||||
void resetEEPROM(void) {}
|
void resetEEPROM(bool) {}
|
||||||
void bufWriterFlush(bufWriter_t *) {}
|
void bufWriterFlush(bufWriter_t *) {}
|
||||||
void mixerResetDisarmedMotors(void) {}
|
void mixerResetDisarmedMotors(void) {}
|
||||||
void gpsEnablePassthrough(struct serialPort_s *) {}
|
void gpsEnablePassthrough(struct serialPort_s *) {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue