mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-26 01:35:41 +03:00
Added shadow copies for CLI and MSP.
This commit is contained in:
parent
985a9208d5
commit
6de1c32d9d
56 changed files with 277 additions and 222 deletions
|
@ -179,6 +179,9 @@ static bool configIsInCopy = false;
|
|||
static int8_t pidProfileIndexToUse = CURRENT_PROFILE_INDEX;
|
||||
static int8_t rateProfileIndexToUse = CURRENT_PROFILE_INDEX;
|
||||
|
||||
static bool featureMaskIsCopied = false;
|
||||
static uint32_t featureMaskCopy;
|
||||
|
||||
#if defined(USE_BOARD_INFO)
|
||||
static bool boardInformationUpdated = false;
|
||||
#if defined(USE_SIGNATURE)
|
||||
|
@ -2345,9 +2348,18 @@ static void cliMcuId(char *cmdline)
|
|||
cliPrintLinef("mcu_id %08x%08x%08x", U_ID_0, U_ID_1, U_ID_2);
|
||||
}
|
||||
|
||||
static uint32_t getFeatureMask(const uint32_t featureMask)
|
||||
{
|
||||
if (featureMaskIsCopied) {
|
||||
return featureMaskCopy;
|
||||
} else {
|
||||
return featureMask;
|
||||
}
|
||||
}
|
||||
|
||||
static void printFeature(uint8_t dumpMask, const featureConfig_t *featureConfig, const featureConfig_t *featureConfigDefault)
|
||||
{
|
||||
const uint32_t mask = featureConfig->enabledFeatures;
|
||||
const uint32_t mask = getFeatureMask(featureConfig->enabledFeatures);
|
||||
const uint32_t defaultMask = featureConfigDefault->enabledFeatures;
|
||||
for (uint32_t i = 0; featureNames[i]; i++) { // disabled features first
|
||||
if (strcmp(featureNames[i], emptyString) != 0) { //Skip unused
|
||||
|
@ -2372,15 +2384,16 @@ static void printFeature(uint8_t dumpMask, const featureConfig_t *featureConfig,
|
|||
static void cliFeature(char *cmdline)
|
||||
{
|
||||
uint32_t len = strlen(cmdline);
|
||||
uint32_t mask = featureMask();
|
||||
|
||||
const uint32_t mask = getFeatureMask(featureMask());
|
||||
if (len == 0) {
|
||||
cliPrint("Enabled: ");
|
||||
for (uint32_t i = 0; ; i++) {
|
||||
if (featureNames[i] == NULL)
|
||||
if (featureNames[i] == NULL) {
|
||||
break;
|
||||
if (mask & (1 << i))
|
||||
}
|
||||
if (mask & (1 << i)) {
|
||||
cliPrintf("%s ", featureNames[i]);
|
||||
}
|
||||
}
|
||||
cliPrintLinefeed();
|
||||
} else if (strncasecmp(cmdline, "list", len) == 0) {
|
||||
|
@ -2394,6 +2407,12 @@ static void cliFeature(char *cmdline)
|
|||
cliPrintLinefeed();
|
||||
return;
|
||||
} else {
|
||||
if (!featureMaskIsCopied) {
|
||||
featureMaskCopy = featureMask();
|
||||
featureMaskIsCopied = true;
|
||||
}
|
||||
uint32_t feature;
|
||||
|
||||
bool remove = false;
|
||||
if (cmdline[0] == '-') {
|
||||
// remove feature
|
||||
|
@ -2409,25 +2428,24 @@ static void cliFeature(char *cmdline)
|
|||
}
|
||||
|
||||
if (strncasecmp(cmdline, featureNames[i], len) == 0) {
|
||||
|
||||
mask = 1 << i;
|
||||
feature = 1 << i;
|
||||
#ifndef USE_GPS
|
||||
if (mask & FEATURE_GPS) {
|
||||
if (feature & FEATURE_GPS) {
|
||||
cliPrintLine("unavailable");
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#ifndef USE_RANGEFINDER
|
||||
if (mask & FEATURE_RANGEFINDER) {
|
||||
if (feature & FEATURE_RANGEFINDER) {
|
||||
cliPrintLine("unavailable");
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
if (remove) {
|
||||
featureClear(mask);
|
||||
featureClear(feature, &featureMaskCopy);
|
||||
cliPrint("Disabled");
|
||||
} else {
|
||||
featureSet(mask);
|
||||
featureSet(feature, &featureMaskCopy);
|
||||
cliPrint("Enabled");
|
||||
}
|
||||
cliPrintLinef(" %s", featureNames[i]);
|
||||
|
@ -2946,7 +2964,7 @@ static void cliDshotProg(char *cmdline)
|
|||
pwmWriteDshotCommand(escIndex, getMotorCount(), command, true);
|
||||
} else {
|
||||
#if defined(USE_ESC_SENSOR) && defined(USE_ESC_SENSOR_INFO)
|
||||
if (featureConfigured(FEATURE_ESC_SENSOR)) {
|
||||
if (featureIsEnabled(FEATURE_ESC_SENSOR)) {
|
||||
if (escIndex != ALL_MOTORS) {
|
||||
executeEscInfoCommand(escIndex);
|
||||
} else {
|
||||
|
@ -3238,7 +3256,11 @@ static void cliSave(char *cmdline)
|
|||
#endif
|
||||
#endif // USE_BOARD_INFO
|
||||
|
||||
writeEEPROM();
|
||||
if (featureMaskIsCopied) {
|
||||
writeEEPROMWithFeatures(featureMaskCopy);
|
||||
} else {
|
||||
writeEEPROM();
|
||||
}
|
||||
|
||||
cliReboot();
|
||||
}
|
||||
|
@ -4642,9 +4664,9 @@ void cliEnter(serialPort_t *serialPort)
|
|||
#else
|
||||
cliPrintLine("\r\nCLI");
|
||||
#endif
|
||||
cliPrompt();
|
||||
|
||||
setArmingDisabled(ARMING_DISABLED_CLI);
|
||||
|
||||
cliPrompt();
|
||||
}
|
||||
|
||||
void cliInit(const serialConfig_t *serialConfig)
|
||||
|
|
|
@ -165,6 +165,18 @@ typedef enum {
|
|||
|
||||
#define RTC_NOT_SUPPORTED 0xff
|
||||
|
||||
static bool featureMaskIsCopied = false;
|
||||
static uint32_t featureMaskCopy;
|
||||
|
||||
static uint32_t getFeatureMask(void)
|
||||
{
|
||||
if (featureMaskIsCopied) {
|
||||
return featureMaskCopy;
|
||||
} else {
|
||||
return featureMask();
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_SERIAL_4WAY_BLHELI_INTERFACE
|
||||
#define ESC_4WAY 0xff
|
||||
|
||||
|
@ -531,7 +543,7 @@ static bool mspCommonProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProce
|
|||
break;
|
||||
|
||||
case MSP_FEATURE_CONFIG:
|
||||
sbufWriteU32(dst, featureMask());
|
||||
sbufWriteU32(dst, getFeatureMask());
|
||||
break;
|
||||
|
||||
#ifdef USE_BEEPER
|
||||
|
@ -1018,7 +1030,7 @@ static bool mspProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst)
|
|||
|
||||
#if defined(USE_ESC_SENSOR)
|
||||
case MSP_ESC_SENSOR_DATA:
|
||||
if (featureConfigured(FEATURE_ESC_SENSOR)) {
|
||||
if (featureIsEnabled(FEATURE_ESC_SENSOR)) {
|
||||
sbufWriteU8(dst, getMotorCount());
|
||||
for (int i = 0; i < getMotorCount(); i++) {
|
||||
const escSensorData_t *escData = getEscSensorData(i);
|
||||
|
@ -1552,7 +1564,11 @@ static mspResult_e mspProcessInCommand(uint8_t cmdMSP, sbuf_t *src)
|
|||
readEEPROM();
|
||||
break;
|
||||
case MSP_EEPROM_WRITE:
|
||||
writeEEPROM();
|
||||
if (featureMaskIsCopied) {
|
||||
writeEEPROMWithFeatures(featureMaskCopy);
|
||||
} else {
|
||||
writeEEPROM();
|
||||
}
|
||||
readEEPROM();
|
||||
break;
|
||||
default:
|
||||
|
@ -1999,7 +2015,12 @@ static mspResult_e mspProcessInCommand(uint8_t cmdMSP, sbuf_t *src)
|
|||
if (ARMING_FLAG(ARMED)) {
|
||||
return MSP_RESULT_ERROR;
|
||||
}
|
||||
writeEEPROM();
|
||||
|
||||
if (featureMaskIsCopied) {
|
||||
writeEEPROMWithFeatures(featureMaskCopy);
|
||||
} else {
|
||||
writeEEPROM();
|
||||
}
|
||||
readEEPROM();
|
||||
break;
|
||||
|
||||
|
@ -2124,8 +2145,11 @@ static mspResult_e mspProcessInCommand(uint8_t cmdMSP, sbuf_t *src)
|
|||
break;
|
||||
#endif // USE_GPS
|
||||
case MSP_SET_FEATURE_CONFIG:
|
||||
featureClearAll();
|
||||
featureSet(sbufReadU32(src)); // features bitmap
|
||||
featureMaskCopy = sbufReadU32(src);
|
||||
if (!featureMaskIsCopied) {
|
||||
featureMaskIsCopied = true;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
#ifdef USE_BEEPER
|
||||
|
|
|
@ -166,11 +166,11 @@ void initActiveBoxIds(void)
|
|||
#define BME(boxId) do { bitArraySet(&ena, boxId); } while (0)
|
||||
BME(BOXARM);
|
||||
BME(BOXPREARM);
|
||||
if (!featureConfigured(FEATURE_AIRMODE)) {
|
||||
if (!featureIsEnabled(FEATURE_AIRMODE)) {
|
||||
BME(BOXAIRMODE);
|
||||
}
|
||||
|
||||
if (!featureConfigured(FEATURE_ANTI_GRAVITY)) {
|
||||
if (!featureIsEnabled(FEATURE_ANTI_GRAVITY)) {
|
||||
BME(BOXANTIGRAVITY);
|
||||
}
|
||||
|
||||
|
@ -188,9 +188,9 @@ void initActiveBoxIds(void)
|
|||
#endif
|
||||
|
||||
#ifdef USE_GPS
|
||||
if (featureConfigured(FEATURE_GPS)) {
|
||||
if (featureIsEnabled(FEATURE_GPS)) {
|
||||
#ifdef USE_GPS_RESCUE
|
||||
if (!featureConfigured(FEATURE_3D)) {
|
||||
if (!featureIsEnabled(FEATURE_3D)) {
|
||||
BME(BOXGPSRESCUE);
|
||||
}
|
||||
#endif
|
||||
|
@ -207,7 +207,7 @@ void initActiveBoxIds(void)
|
|||
BME(BOXBEEPERON);
|
||||
|
||||
#ifdef USE_LED_STRIP
|
||||
if (featureConfigured(FEATURE_LED_STRIP)) {
|
||||
if (featureIsEnabled(FEATURE_LED_STRIP)) {
|
||||
BME(BOXLEDLOW);
|
||||
}
|
||||
#endif
|
||||
|
@ -221,7 +221,7 @@ void initActiveBoxIds(void)
|
|||
|
||||
BME(BOXFPVANGLEMIX);
|
||||
|
||||
if (featureConfigured(FEATURE_3D)) {
|
||||
if (featureIsEnabled(FEATURE_3D)) {
|
||||
BME(BOX3D);
|
||||
}
|
||||
|
||||
|
@ -229,18 +229,18 @@ void initActiveBoxIds(void)
|
|||
BME(BOXFLIPOVERAFTERCRASH);
|
||||
}
|
||||
|
||||
if (featureConfigured(FEATURE_SERVO_TILT)) {
|
||||
if (featureIsEnabled(FEATURE_SERVO_TILT)) {
|
||||
BME(BOXCAMSTAB);
|
||||
}
|
||||
|
||||
if (featureConfigured(FEATURE_INFLIGHT_ACC_CAL)) {
|
||||
if (featureIsEnabled(FEATURE_INFLIGHT_ACC_CAL)) {
|
||||
BME(BOXCALIB);
|
||||
}
|
||||
|
||||
BME(BOXOSD);
|
||||
|
||||
#ifdef USE_TELEMETRY
|
||||
if (featureConfigured(FEATURE_TELEMETRY)) {
|
||||
if (featureIsEnabled(FEATURE_TELEMETRY)) {
|
||||
BME(BOXTELEMETRY);
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue