Extract range definition so it can be reused.

This commit is contained in:
Dominic Clifton 2014-10-24 18:57:06 +01:00
parent b2db6b3b80
commit 18abad5dd7
5 changed files with 41 additions and 38 deletions

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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++;
}
}

View File

@ -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);
}

View File

@ -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;