diff --git a/src/main/fc/config.c b/src/main/fc/config.c index 3ca6e67886..f47ab28037 100644 --- a/src/main/fc/config.c +++ b/src/main/fc/config.c @@ -338,6 +338,16 @@ static void validateAndFixConfig(void) } #endif + for (int i = 0; i < MAX_MODE_ACTIVATION_CONDITION_COUNT; i++) { + const modeActivationCondition_t *mac = modeActivationConditions(i); + + if (mac->linkedTo) { + if (mac->modeId == BOXARM || isModeActivationConditionLinked(mac->linkedTo)) { + removeModeActivationCondition(mac->modeId); + } + } + } + // clear features that are not supported. // I have kept them all here in one place, some could be moved to sections of code above. diff --git a/src/main/fc/rc_modes.c b/src/main/fc/rc_modes.c index 3d8878e1f6..bd95134b6d 100644 --- a/src/main/fc/rc_modes.c +++ b/src/main/fc/rc_modes.c @@ -82,10 +82,12 @@ void updateMasksForMac(const modeActivationCondition_t *mac, boxBitmask_t *andMa { bool bAnd = (mac->modeLogic == MODELOGIC_AND) || bitArrayGet(andMask, mac->modeId); bool bAct = isRangeActive(mac->auxChannelIndex, &mac->range); - if (bAnd) + if (bAnd) { bitArraySet(andMask, mac->modeId); - if (bAnd != bAct) + } + if (bAnd != bAct) { bitArraySet(newMask, mac->modeId); + } } void updateMasksForStickyModes(const modeActivationCondition_t *mac, boxBitmask_t *andMask, boxBitmask_t *newMask) @@ -104,6 +106,18 @@ void updateMasksForStickyModes(const modeActivationCondition_t *mac, boxBitmask_ } } +void updateMasksForLinkedMac(const modeActivationCondition_t *mac, boxBitmask_t *andMask, boxBitmask_t *newMask) +{ + bool bAnd = (mac->modeLogic == MODELOGIC_AND) || bitArrayGet(andMask, mac->modeId); + bool bAct = bitArrayGet(andMask, mac->linkedTo) != bitArrayGet(newMask, mac->linkedTo); + if (bAnd) { + bitArraySet(andMask, mac->modeId); + } + if (bAnd != bAct) { + bitArraySet(newMask, mac->modeId); + } +} + void updateActivatedModes(void) { boxBitmask_t newMask, andMask, stickyModes; @@ -123,15 +137,15 @@ void updateActivatedModes(void) } } - bitArrayXor(&newMask, sizeof(&newMask), &newMask, &andMask); - // Update linked modes for (int i = 0; i < activeLinkedMacCount; i++) { const modeActivationCondition_t *mac = modeActivationConditions(activeLinkedMacArray[i]); - bitArrayCopy(&newMask, mac->linkedTo, mac->modeId); + updateMasksForLinkedMac(mac, &andMask, &newMask); } + bitArrayXor(&newMask, sizeof(&newMask), &newMask, &andMask); + rcModeUpdate(&newMask); airmodeEnabled = featureIsEnabled(FEATURE_AIRMODE) || IS_RC_MODE_ACTIVE(BOXAIRMODE); @@ -150,6 +164,19 @@ bool isModeActivationConditionPresent(boxId_e modeId) return false; } +bool isModeActivationConditionLinked(boxId_e modeId) +{ + for (int i = 0; i < MAX_MODE_ACTIVATION_CONDITION_COUNT; i++) { + const modeActivationCondition_t *mac = modeActivationConditions(i); + + if (mac->modeId == modeId && mac->linkedTo != 0) { + return true; + } + } + + return false; +} + void removeModeActivationCondition(const boxId_e modeId) { unsigned offset = 0; diff --git a/src/main/fc/rc_modes.h b/src/main/fc/rc_modes.h index 65044e5393..86f6da25d8 100644 --- a/src/main/fc/rc_modes.h +++ b/src/main/fc/rc_modes.h @@ -129,6 +129,7 @@ bool airmodeIsEnabled(void); bool isRangeActive(uint8_t auxChannelIndex, const channelRange_t *range); void updateActivatedModes(void); bool isModeActivationConditionPresent(boxId_e modeId); +bool isModeActivationConditionLinked(boxId_e modeId); void removeModeActivationCondition(boxId_e modeId); bool isModeActivationConditionConfigured(const modeActivationCondition_t *mac, const modeActivationCondition_t *emptyMac); void analyzeModeActivationConditions(void);