diff --git a/src/main/io/rc_controls.c b/src/main/io/rc_controls.c index 3e5ffb4e5..a900e08da 100644 --- a/src/main/io/rc_controls.c +++ b/src/main/io/rc_controls.c @@ -244,8 +244,8 @@ void updateActivatedModes(modeActivationCondition_t *modeActivationConditions) } uint16_t channelValue = constrain(rcData[modeActivationCondition->auxChannelIndex + NON_AUX_CHANNEL_COUNT], CHANNEL_RANGE_MIN, CHANNEL_RANGE_MAX - 1); - if (channelValue >= 900 + (modeActivationCondition->rangeStartStep * 25) && - channelValue < 900 + (modeActivationCondition->rangeEndStep * 25)) { + if (channelValue >= 900 + (modeActivationCondition->range.startStep * 25) && + channelValue < 900 + (modeActivationCondition->range.endStep * 25)) { ACTIVATE_RC_MODE(modeActivationCondition->modeId); } } diff --git a/src/main/io/rc_controls.h b/src/main/io/rc_controls.h index 47272380c..2fe69866e 100644 --- a/src/main/io/rc_controls.h +++ b/src/main/io/rc_controls.h @@ -98,19 +98,22 @@ typedef enum { #define MIN_MODE_RANGE_STEP 0 #define MAX_MODE_RANGE_STEP ((CHANNEL_RANGE_MAX - CHANNEL_RANGE_MIN) / 25) +// steps are 25 apart +// a value of 0 corresponds to a channel value of 900 or less +// a value of 48 corresponds to a channel value of 2100 or more +// 48 steps between 900 and 1200 +typedef struct channelRange_s { + uint8_t startStep; + uint8_t endStep; +} channelRange_t; + typedef struct modeActivationCondition_s { boxId_e modeId; uint8_t auxChannelIndex; - - // steps are 25 apart - // a value of 0 corresponds to a channel value of 900 or less - // a value of 48 corresponds to a channel value of 2100 or more - // 48 steps between 900 and 1200 - uint8_t rangeStartStep; - uint8_t rangeEndStep; + channelRange_t range; } modeActivationCondition_t; -#define IS_MODE_RANGE_USABLE(modeActivationCondition) (modeActivationCondition->rangeStartStep < modeActivationCondition->rangeEndStep) +#define IS_MODE_RANGE_USABLE(modeActivationCondition) (modeActivationCondition->range.startStep < modeActivationCondition->range.endStep) typedef struct controlRateConfig_s { uint8_t rcRate8; diff --git a/src/main/io/serial_cli.c b/src/main/io/serial_cli.c index 8690f7b48..a929eb75e 100644 --- a/src/main/io/serial_cli.c +++ b/src/main/io/serial_cli.c @@ -418,8 +418,8 @@ static void cliAux(char *cmdline) i, mac->modeId, mac->auxChannelIndex, - MODE_STEP_TO_CHANNEL_VALUE(mac->rangeStartStep), - MODE_STEP_TO_CHANNEL_VALUE(mac->rangeEndStep) + MODE_STEP_TO_CHANNEL_VALUE(mac->range.startStep), + MODE_STEP_TO_CHANNEL_VALUE(mac->range.endStep) ); } } else { @@ -449,7 +449,7 @@ static void cliAux(char *cmdline) val = atoi(++ptr); val = CHANNEL_VALUE_TO_STEP(val); if (val >= MIN_MODE_RANGE_STEP && val <= MAX_MODE_RANGE_STEP) { - mac->rangeStartStep = val; + mac->range.startStep = val; validArgumentCount++; } } @@ -458,7 +458,7 @@ static void cliAux(char *cmdline) val = atoi(++ptr); val = CHANNEL_VALUE_TO_STEP(val); if (val >= MIN_MODE_RANGE_STEP && val <= MAX_MODE_RANGE_STEP) { - mac->rangeEndStep = val; + mac->range.endStep = val; validArgumentCount++; } } diff --git a/src/main/io/serial_msp.c b/src/main/io/serial_msp.c index 8bd7ae906..0c8851375 100755 --- a/src/main/io/serial_msp.c +++ b/src/main/io/serial_msp.c @@ -845,8 +845,8 @@ static bool processOutCommand(uint8_t cmdMSP) const box_t *box = &boxes[mac->modeId]; serialize8(box->permanentId); serialize8(mac->auxChannelIndex); - serialize8(mac->rangeStartStep); - serialize8(mac->rangeEndStep); + serialize8(mac->range.startStep); + serialize8(mac->range.endStep); } break; case MSP_BOXNAMES: @@ -1088,8 +1088,8 @@ static bool processInCommand(void) if (box) { mac->modeId = box->boxId; mac->auxChannelIndex = read8(); - mac->rangeStartStep = read8(); - mac->rangeEndStep = read8(); + mac->range.startStep = read8(); + mac->range.endStep = read8(); } else { headSerialError(0); } diff --git a/src/test/unit/rc_controls_unittest.cc b/src/test/unit/rc_controls_unittest.cc index b202d8a38..94a6492be 100644 --- a/src/test/unit/rc_controls_unittest.cc +++ b/src/test/unit/rc_controls_unittest.cc @@ -74,47 +74,47 @@ TEST(RcControlsTest, updateActivatedModesUsingValidAuxConfigurationAndRXValues) modeActivationConditions[0].modeId = (boxId_e)0; modeActivationConditions[0].auxChannelIndex = AUX1 - NON_AUX_CHANNEL_COUNT; - modeActivationConditions[0].rangeStartStep = CHANNEL_VALUE_TO_STEP(1700); - modeActivationConditions[0].rangeEndStep = CHANNEL_VALUE_TO_STEP(2100); + modeActivationConditions[0].range.startStep = CHANNEL_VALUE_TO_STEP(1700); + modeActivationConditions[0].range.endStep = CHANNEL_VALUE_TO_STEP(2100); modeActivationConditions[1].modeId = (boxId_e)1; modeActivationConditions[1].auxChannelIndex = AUX2 - NON_AUX_CHANNEL_COUNT; - modeActivationConditions[1].rangeStartStep = CHANNEL_VALUE_TO_STEP(1300); - modeActivationConditions[1].rangeEndStep = CHANNEL_VALUE_TO_STEP(1700); + modeActivationConditions[1].range.startStep = CHANNEL_VALUE_TO_STEP(1300); + modeActivationConditions[1].range.endStep = CHANNEL_VALUE_TO_STEP(1700); modeActivationConditions[2].modeId = (boxId_e)2; modeActivationConditions[2].auxChannelIndex = AUX3 - NON_AUX_CHANNEL_COUNT; - modeActivationConditions[2].rangeStartStep = CHANNEL_VALUE_TO_STEP(900); - modeActivationConditions[2].rangeEndStep = CHANNEL_VALUE_TO_STEP(1200); + modeActivationConditions[2].range.startStep = CHANNEL_VALUE_TO_STEP(900); + modeActivationConditions[2].range.endStep = CHANNEL_VALUE_TO_STEP(1200); modeActivationConditions[3].modeId = (boxId_e)3; modeActivationConditions[3].auxChannelIndex = AUX4 - NON_AUX_CHANNEL_COUNT; - modeActivationConditions[3].rangeStartStep = CHANNEL_VALUE_TO_STEP(900); - modeActivationConditions[3].rangeEndStep = CHANNEL_VALUE_TO_STEP(2100); + modeActivationConditions[3].range.startStep = CHANNEL_VALUE_TO_STEP(900); + modeActivationConditions[3].range.endStep = CHANNEL_VALUE_TO_STEP(2100); modeActivationConditions[4].modeId = (boxId_e)4; modeActivationConditions[4].auxChannelIndex = AUX5 - NON_AUX_CHANNEL_COUNT; - modeActivationConditions[4].rangeStartStep = CHANNEL_VALUE_TO_STEP(900); - modeActivationConditions[4].rangeEndStep = CHANNEL_VALUE_TO_STEP(925); + modeActivationConditions[4].range.startStep = CHANNEL_VALUE_TO_STEP(900); + modeActivationConditions[4].range.endStep = CHANNEL_VALUE_TO_STEP(925); - EXPECT_EQ(0, modeActivationConditions[4].rangeStartStep); - EXPECT_EQ(1, modeActivationConditions[4].rangeEndStep); + EXPECT_EQ(0, modeActivationConditions[4].range.startStep); + EXPECT_EQ(1, modeActivationConditions[4].range.endStep); modeActivationConditions[5].modeId = (boxId_e)5; modeActivationConditions[5].auxChannelIndex = AUX6 - NON_AUX_CHANNEL_COUNT; - modeActivationConditions[5].rangeStartStep = CHANNEL_VALUE_TO_STEP(2075); - modeActivationConditions[5].rangeEndStep = CHANNEL_VALUE_TO_STEP(2100); + modeActivationConditions[5].range.startStep = CHANNEL_VALUE_TO_STEP(2075); + modeActivationConditions[5].range.endStep = CHANNEL_VALUE_TO_STEP(2100); - EXPECT_EQ(47, modeActivationConditions[5].rangeStartStep); - EXPECT_EQ(48, modeActivationConditions[5].rangeEndStep); + EXPECT_EQ(47, modeActivationConditions[5].range.startStep); + EXPECT_EQ(48, modeActivationConditions[5].range.endStep); modeActivationConditions[6].modeId = (boxId_e)6; modeActivationConditions[6].auxChannelIndex = AUX7 - NON_AUX_CHANNEL_COUNT; - modeActivationConditions[6].rangeStartStep = CHANNEL_VALUE_TO_STEP(925); - modeActivationConditions[6].rangeEndStep = CHANNEL_VALUE_TO_STEP(950); + modeActivationConditions[6].range.startStep = CHANNEL_VALUE_TO_STEP(925); + modeActivationConditions[6].range.endStep = CHANNEL_VALUE_TO_STEP(950); - EXPECT_EQ(1, modeActivationConditions[6].rangeStartStep); - EXPECT_EQ(2, modeActivationConditions[6].rangeEndStep); + EXPECT_EQ(1, modeActivationConditions[6].range.startStep); + EXPECT_EQ(2, modeActivationConditions[6].range.endStep); // and rcModeActivationMask = 0;