Skip to content

Commit 9247691

Browse files
authored
Merge pull request #3443 from iNavFlight/agh_rc_adjustments_disable_on_norange
Disable RC adjustments when the trigger channel goes out of the range
2 parents 642fd45 + a403c6c commit 9247691

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

src/main/fc/fc_core.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,9 +483,10 @@ void processRx(timeUs_t currentTimeUs)
483483

484484
updateActivatedModes();
485485

486-
if ((!cliMode) && (!FLIGHT_MODE(FAILSAFE_MODE))) {
487-
updateAdjustmentStates();
488-
processRcAdjustments(CONST_CAST(controlRateConfig_t*, currentControlRateProfile));
486+
if (!cliMode) {
487+
bool canUseRxData = rxIsReceivingSignal() && !FLIGHT_MODE(FAILSAFE_MODE);
488+
updateAdjustmentStates(canUseRxData);
489+
processRcAdjustments(CONST_CAST(controlRateConfig_t*, currentControlRateProfile), canUseRxData);
489490
}
490491

491492
bool canUseHorizonMode = true;

src/main/fc/rc_adjustments.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -570,12 +570,10 @@ static void applySelectAdjustment(uint8_t adjustmentFunction, uint8_t position)
570570

571571
#define RESET_FREQUENCY_2HZ (1000 / 2)
572572

573-
void processRcAdjustments(controlRateConfig_t *controlRateConfig)
573+
void processRcAdjustments(controlRateConfig_t *controlRateConfig, bool canUseRxData)
574574
{
575575
const uint32_t now = millis();
576576

577-
const bool canUseRxData = rxIsReceivingSignal();
578-
579577
for (int adjustmentIndex = 0; adjustmentIndex < MAX_SIMULTANEOUS_ADJUSTMENT_COUNT; adjustmentIndex++) {
580578
adjustmentState_t * const adjustmentState = &adjustmentStates[adjustmentIndex];
581579

@@ -636,23 +634,26 @@ void resetAdjustmentStates(void)
636634
memset(adjustmentStates, 0, sizeof(adjustmentStates));
637635
}
638636

639-
void updateAdjustmentStates(void)
637+
void updateAdjustmentStates(bool canUseRxData)
640638
{
641639
for (int index = 0; index < MAX_ADJUSTMENT_RANGE_COUNT; index++) {
642640
const adjustmentRange_t * const adjustmentRange = adjustmentRanges(index);
641+
const adjustmentConfig_t *adjustmentConfig = &defaultAdjustmentConfigs[adjustmentRange->adjustmentFunction - ADJUSTMENT_FUNCTION_CONFIG_INDEX_OFFSET];
643642

644-
if (isRangeActive(adjustmentRange->auxChannelIndex, &adjustmentRange->range)) {
645-
646-
const adjustmentConfig_t *adjustmentConfig = &defaultAdjustmentConfigs[adjustmentRange->adjustmentFunction - ADJUSTMENT_FUNCTION_CONFIG_INDEX_OFFSET];
647-
643+
if (canUseRxData && isRangeActive(adjustmentRange->auxChannelIndex, &adjustmentRange->range)) {
648644
configureAdjustment(adjustmentRange->adjustmentIndex, adjustmentRange->auxSwitchChannelIndex, adjustmentConfig);
645+
} else {
646+
adjustmentState_t * const adjustmentState = &adjustmentStates[index];
647+
if (adjustmentState->config == adjustmentConfig) {
648+
adjustmentState->config = NULL;
649+
}
649650
}
650651
}
651652
}
652653

653654
bool isAdjustmentFunctionSelected(uint8_t adjustmentFunction) {
654655
for (uint8_t index = 0; index < MAX_SIMULTANEOUS_ADJUSTMENT_COUNT; ++index) {
655-
if (adjustmentStates[index].config->adjustmentFunction == adjustmentFunction) {
656+
if (adjustmentStates[index].config && adjustmentStates[index].config->adjustmentFunction == adjustmentFunction) {
656657
return true;
657658
}
658659
}

src/main/fc/rc_adjustments.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ typedef struct adjustmentState_s {
135135
PG_DECLARE_ARRAY(adjustmentRange_t, MAX_ADJUSTMENT_RANGE_COUNT, adjustmentRanges);
136136

137137
void resetAdjustmentStates(void);
138-
void updateAdjustmentStates(void);
138+
void updateAdjustmentStates(bool canUseRxData);
139139
struct controlRateConfig_s;
140-
void processRcAdjustments(struct controlRateConfig_s *controlRateConfig);
140+
void processRcAdjustments(struct controlRateConfig_s *controlRateConfig, bool canUseRxData);
141141
bool isAdjustmentFunctionSelected(uint8_t adjustmentFunction);

0 commit comments

Comments
 (0)