1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-17 13:25:30 +03:00

Use adjustment index rather than function to track state.

This commit is contained in:
Dominic Clifton 2014-10-24 15:10:28 +01:00
parent e21f0667c5
commit 45d9678a39
2 changed files with 23 additions and 23 deletions

View file

@ -250,12 +250,12 @@ void updateActivatedModes(modeActivationCondition_t *modeActivationConditions)
} }
} }
uint32_t adjustmentFunctionStateMask = 0; uint8_t adjustmentStateMask = 0;
#define MARK_ADJUSTMENT_FUNCTION_AS_BUSY(adjustmentFunction) adjustmentFunctionStateMask |= (1 << (adjustmentFunction - ADJUSTMENT_INDEX_OFFSET)) #define MARK_ADJUSTMENT_FUNCTION_AS_BUSY(adjustmentIndex) adjustmentStateMask |= (1 << adjustmentIndex)
#define MARK_ADJUSTMENT_FUNCTION_AS_READY(adjustmentFunction) adjustmentFunctionStateMask &= ~(1 << (adjustmentFunction - ADJUSTMENT_INDEX_OFFSET)) #define MARK_ADJUSTMENT_FUNCTION_AS_READY(adjustmentIndex) adjustmentStateMask &= ~(1 << adjustmentIndex)
#define IS_ADJUSTMENT_FUNCTION_BUSY(adjustmentFunction) (adjustmentFunctionStateMask & (1 << (adjustmentFunction - ADJUSTMENT_INDEX_OFFSET))) #define IS_ADJUSTMENT_FUNCTION_BUSY(adjustmentIndex) (adjustmentStateMask & (1 << adjustmentIndex))
typedef struct adjustmentConfig_s { typedef struct adjustmentConfig_s {
uint8_t auxChannelIndex; uint8_t auxChannelIndex;
@ -308,7 +308,7 @@ void processRcAdjustments(controlRateConfig_t *controlRateConfig, rxConfig_t *rx
if (canResetReadyStates) { if (canResetReadyStates) {
adjustmentConfig->timeoutAt = now + RESET_FREQUENCY_2HZ; adjustmentConfig->timeoutAt = now + RESET_FREQUENCY_2HZ;
MARK_ADJUSTMENT_FUNCTION_AS_READY(adjustmentFunction); MARK_ADJUSTMENT_FUNCTION_AS_READY(adjustmentIndex);
} }
@ -321,16 +321,16 @@ void processRcAdjustments(controlRateConfig_t *controlRateConfig, rxConfig_t *rx
step = 0 - adjustmentConfig->step; step = 0 - adjustmentConfig->step;
} else { } else {
// returning the switch to the middle immediately resets the ready state // returning the switch to the middle immediately resets the ready state
MARK_ADJUSTMENT_FUNCTION_AS_READY(adjustmentFunction); MARK_ADJUSTMENT_FUNCTION_AS_READY(adjustmentIndex);
adjustmentConfig->timeoutAt = now + RESET_FREQUENCY_2HZ; adjustmentConfig->timeoutAt = now + RESET_FREQUENCY_2HZ;
continue; continue;
} }
if (IS_ADJUSTMENT_FUNCTION_BUSY(adjustmentFunction)) { if (IS_ADJUSTMENT_FUNCTION_BUSY(adjustmentIndex)) {
continue; continue;
} }
MARK_ADJUSTMENT_FUNCTION_AS_BUSY(adjustmentFunction); MARK_ADJUSTMENT_FUNCTION_AS_BUSY(adjustmentIndex);
applyAdjustment(controlRateConfig, adjustmentFunction, step); applyAdjustment(controlRateConfig, adjustmentFunction, step);
} }
} }

View file

@ -185,7 +185,7 @@ uint32_t millis(void) {
rxConfig_t rxConfig; rxConfig_t rxConfig;
extern uint32_t adjustmentFunctionStateMask; extern uint8_t adjustmentStateMask;
TEST(RcControlsTest, processRcAdjustmentsSticksInMiddle) TEST(RcControlsTest, processRcAdjustmentsSticksInMiddle)
{ {
@ -220,7 +220,7 @@ TEST(RcControlsTest, processRcAdjustmentsSticksInMiddle)
// then // then
EXPECT_EQ(controlRateConfig.rcRate8, 90); EXPECT_EQ(controlRateConfig.rcRate8, 90);
EXPECT_EQ(CALL_COUNTER(COUNTER_GENERATE_PITCH_ROLL_CURVE), 0); EXPECT_EQ(CALL_COUNTER(COUNTER_GENERATE_PITCH_ROLL_CURVE), 0);
EXPECT_EQ(adjustmentFunctionStateMask, 0); EXPECT_EQ(adjustmentStateMask, 0);
} }
TEST(RcControlsTest, processRcAdjustmentsWithRcRateFunctionSwitchUp) TEST(RcControlsTest, processRcAdjustmentsWithRcRateFunctionSwitchUp)
@ -254,8 +254,8 @@ TEST(RcControlsTest, processRcAdjustmentsWithRcRateFunctionSwitchUp)
rcData[AUX3] = PWM_RANGE_MAX; rcData[AUX3] = PWM_RANGE_MAX;
// and // and
uint32_t expectedAdjustmentFunctionStateMask = uint8_t expectedAdjustmentStateMask =
(1 << (ADJUSTMENT_RC_RATE - ADJUSTMENT_INDEX_OFFSET)); (1 << 0);
// and // and
fixedMillis = 496; fixedMillis = 496;
@ -266,7 +266,7 @@ TEST(RcControlsTest, processRcAdjustmentsWithRcRateFunctionSwitchUp)
// then // then
EXPECT_EQ(controlRateConfig.rcRate8, 91); EXPECT_EQ(controlRateConfig.rcRate8, 91);
EXPECT_EQ(CALL_COUNTER(COUNTER_GENERATE_PITCH_ROLL_CURVE), 1); EXPECT_EQ(CALL_COUNTER(COUNTER_GENERATE_PITCH_ROLL_CURVE), 1);
EXPECT_EQ(adjustmentFunctionStateMask, expectedAdjustmentFunctionStateMask); EXPECT_EQ(adjustmentStateMask, expectedAdjustmentStateMask);
// //
@ -280,7 +280,7 @@ TEST(RcControlsTest, processRcAdjustmentsWithRcRateFunctionSwitchUp)
processRcAdjustments(&controlRateConfig, &rxConfig); processRcAdjustments(&controlRateConfig, &rxConfig);
EXPECT_EQ(controlRateConfig.rcRate8, 91); EXPECT_EQ(controlRateConfig.rcRate8, 91);
EXPECT_EQ(adjustmentFunctionStateMask, expectedAdjustmentFunctionStateMask); EXPECT_EQ(adjustmentStateMask, expectedAdjustmentStateMask);
// //
@ -295,14 +295,14 @@ TEST(RcControlsTest, processRcAdjustmentsWithRcRateFunctionSwitchUp)
fixedMillis = 498; fixedMillis = 498;
// and // and
expectedAdjustmentFunctionStateMask = adjustmentFunctionStateMask & expectedAdjustmentStateMask = adjustmentStateMask &
~(1 << (ADJUSTMENT_RC_RATE - ADJUSTMENT_INDEX_OFFSET)); ~(1 << 0);
// when // when
processRcAdjustments(&controlRateConfig, &rxConfig); processRcAdjustments(&controlRateConfig, &rxConfig);
EXPECT_EQ(controlRateConfig.rcRate8, 91); EXPECT_EQ(controlRateConfig.rcRate8, 91);
EXPECT_EQ(adjustmentFunctionStateMask, expectedAdjustmentFunctionStateMask); EXPECT_EQ(adjustmentStateMask, expectedAdjustmentStateMask);
// //
@ -312,8 +312,8 @@ TEST(RcControlsTest, processRcAdjustmentsWithRcRateFunctionSwitchUp)
rcData[AUX3] = PWM_RANGE_MAX; rcData[AUX3] = PWM_RANGE_MAX;
// and // and
expectedAdjustmentFunctionStateMask = expectedAdjustmentStateMask =
(1 << (ADJUSTMENT_RC_RATE - ADJUSTMENT_INDEX_OFFSET)); (1 << 0);
// and // and
fixedMillis = 499; fixedMillis = 499;
@ -324,7 +324,7 @@ TEST(RcControlsTest, processRcAdjustmentsWithRcRateFunctionSwitchUp)
// then // then
EXPECT_EQ(controlRateConfig.rcRate8, 92); EXPECT_EQ(controlRateConfig.rcRate8, 92);
EXPECT_EQ(CALL_COUNTER(COUNTER_GENERATE_PITCH_ROLL_CURVE), 2); EXPECT_EQ(CALL_COUNTER(COUNTER_GENERATE_PITCH_ROLL_CURVE), 2);
EXPECT_EQ(adjustmentFunctionStateMask, expectedAdjustmentFunctionStateMask); EXPECT_EQ(adjustmentStateMask, expectedAdjustmentStateMask);
// //
// leaving the switch up, after the original timer would have reset the state should now NOT cause // leaving the switch up, after the original timer would have reset the state should now NOT cause
@ -339,7 +339,7 @@ TEST(RcControlsTest, processRcAdjustmentsWithRcRateFunctionSwitchUp)
// then // then
EXPECT_EQ(controlRateConfig.rcRate8, 92); EXPECT_EQ(controlRateConfig.rcRate8, 92);
EXPECT_EQ(adjustmentFunctionStateMask, expectedAdjustmentFunctionStateMask); EXPECT_EQ(adjustmentStateMask, expectedAdjustmentStateMask);
// //
// should still not be able to be increased // should still not be able to be increased
@ -353,7 +353,7 @@ TEST(RcControlsTest, processRcAdjustmentsWithRcRateFunctionSwitchUp)
// then // then
EXPECT_EQ(controlRateConfig.rcRate8, 92); EXPECT_EQ(controlRateConfig.rcRate8, 92);
EXPECT_EQ(adjustmentFunctionStateMask, expectedAdjustmentFunctionStateMask); EXPECT_EQ(adjustmentStateMask, expectedAdjustmentStateMask);
// //
// 500ms has now passed since the switch was returned to the middle, now that // 500ms has now passed since the switch was returned to the middle, now that
@ -370,7 +370,7 @@ TEST(RcControlsTest, processRcAdjustmentsWithRcRateFunctionSwitchUp)
// then // then
EXPECT_EQ(controlRateConfig.rcRate8, 93); EXPECT_EQ(controlRateConfig.rcRate8, 93);
EXPECT_EQ(CALL_COUNTER(COUNTER_GENERATE_PITCH_ROLL_CURVE), 3); EXPECT_EQ(CALL_COUNTER(COUNTER_GENERATE_PITCH_ROLL_CURVE), 3);
EXPECT_EQ(adjustmentFunctionStateMask, expectedAdjustmentFunctionStateMask); EXPECT_EQ(adjustmentStateMask, expectedAdjustmentStateMask);
} }