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