Update `adjrange` command to take an 'adjustment index/slot'. Apply
adjustment ranges to adjustment slots when channel is within range. example: ``` adjrange 0 0 0 900 1700 0 2 adjrange 1 0 0 1700 2100 1 2 ``` explained: * configure adjrange 0 to use adjustment slot 1 (0) so that when aux1 (0) in the range 900-1700 then do nothing when aux 3 (2) is in any position. * configure adjrange 1 to use adjustment slot 1 (0) so that when aux1 (0) in the range 1700-2100 then do use adjustment 1 (rc rate) when aux 3 (2) is in the appropriate position. Without the entire range of aux1 being defined there is nothing that would stop aux 3 adjusting the rc rate once aux 1 wasn't in the higher range. There are 4 adjustment slots and 12 adjustment ranges. Adjustment slots and adjustment ranges can use the same aux channel. e.g. `adjrange 2 1 0 900 2100 1 3` * configure adjrange 2 to use adjustment slot 2 (1) so that when aux4 (3) in the range 900-2100 then use adjustment 1 (rc rate) when aux 4 (3) is in the appropriate position.
This commit is contained in:
parent
bd39445be8
commit
066c814a8a
|
@ -230,22 +230,26 @@ void processRcStickPositions(rxConfig_t *rxConfig, throttleStatus_e throttleStat
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isRangeActive(uint8_t auxChannelIndex, channelRange_t *range) {
|
||||||
|
if (!IS_RANGE_USABLE(range)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t channelValue = constrain(rcData[auxChannelIndex + NON_AUX_CHANNEL_COUNT], CHANNEL_RANGE_MIN, CHANNEL_RANGE_MAX - 1);
|
||||||
|
return (channelValue >= 900 + (range->startStep * 25) &&
|
||||||
|
channelValue < 900 + (range->endStep * 25));
|
||||||
|
}
|
||||||
|
|
||||||
void updateActivatedModes(modeActivationCondition_t *modeActivationConditions)
|
void updateActivatedModes(modeActivationCondition_t *modeActivationConditions)
|
||||||
{
|
{
|
||||||
rcModeActivationMask = 0; // FIXME implement, use rcData & modeActivationConditions
|
rcModeActivationMask = 0;
|
||||||
|
|
||||||
uint8_t index;
|
uint8_t index;
|
||||||
|
|
||||||
for (index = 0; index < MAX_MODE_ACTIVATION_CONDITION_COUNT; index++) {
|
for (index = 0; index < MAX_MODE_ACTIVATION_CONDITION_COUNT; index++) {
|
||||||
modeActivationCondition_t *modeActivationCondition = &modeActivationConditions[index];
|
modeActivationCondition_t *modeActivationCondition = &modeActivationConditions[index];
|
||||||
|
|
||||||
if (!IS_MODE_RANGE_USABLE(modeActivationCondition)) {
|
if (isRangeActive(modeActivationCondition->auxChannelIndex, &modeActivationCondition->range)) {
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t channelValue = constrain(rcData[modeActivationCondition->auxChannelIndex + NON_AUX_CHANNEL_COUNT], CHANNEL_RANGE_MIN, CHANNEL_RANGE_MAX - 1);
|
|
||||||
if (channelValue >= 900 + (modeActivationCondition->range.startStep * 25) &&
|
|
||||||
channelValue < 900 + (modeActivationCondition->range.endStep * 25)) {
|
|
||||||
ACTIVATE_RC_MODE(modeActivationCondition->modeId);
|
ACTIVATE_RC_MODE(modeActivationCondition->modeId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -258,17 +262,16 @@ uint8_t adjustmentStateMask = 0;
|
||||||
|
|
||||||
#define IS_ADJUSTMENT_FUNCTION_BUSY(adjustmentIndex) (adjustmentStateMask & (1 << adjustmentIndex))
|
#define IS_ADJUSTMENT_FUNCTION_BUSY(adjustmentIndex) (adjustmentStateMask & (1 << adjustmentIndex))
|
||||||
|
|
||||||
static const adjustmentConfig_t defaultAdjustmentConfigs[] = {
|
// sync with adjustmentFunction_e
|
||||||
|
static const adjustmentConfig_t defaultAdjustmentConfigs[ADJUSTMENT_FUNCTION_COUNT - 1] = {
|
||||||
{
|
{
|
||||||
.adjustmentFunction = ADJUSTMENT_RC_RATE,
|
.adjustmentFunction = ADJUSTMENT_RC_RATE,
|
||||||
.step = 1
|
.step = 1
|
||||||
},
|
|
||||||
{
|
|
||||||
.adjustmentFunction = ADJUSTMENT_NONE,
|
|
||||||
.step = 0
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define ADJUSTMENT_FUNCTION_CONFIG_INDEX_OFFSET 1
|
||||||
|
|
||||||
|
|
||||||
typedef struct adjustmentState_s {
|
typedef struct adjustmentState_s {
|
||||||
uint8_t auxChannelIndex;
|
uint8_t auxChannelIndex;
|
||||||
|
@ -277,14 +280,16 @@ typedef struct adjustmentState_s {
|
||||||
uint32_t timeoutAt;
|
uint32_t timeoutAt;
|
||||||
} adjustmentState_t;
|
} adjustmentState_t;
|
||||||
|
|
||||||
#define MAX_SIMULTANEOUS_ADJUSTMENTS 2
|
static adjustmentState_t adjustmentStates[MAX_SIMULTANEOUS_ADJUSTMENT_COUNT];
|
||||||
|
|
||||||
static adjustmentState_t adjustmentStates[MAX_SIMULTANEOUS_ADJUSTMENTS];
|
void configureAdjustment(uint8_t index, uint8_t auxSwitchChannelIndex, const adjustmentConfig_t *adjustmentConfig) {
|
||||||
|
|
||||||
void configureAdjustment(uint8_t index, uint8_t auxChannelIndex, const adjustmentConfig_t *adjustmentConfig) {
|
|
||||||
adjustmentState_t *adjustmentState = &adjustmentStates[index];
|
adjustmentState_t *adjustmentState = &adjustmentStates[index];
|
||||||
|
|
||||||
adjustmentState->auxChannelIndex = auxChannelIndex;
|
if (adjustmentState->adjustmentFunction == adjustmentConfig->adjustmentFunction) {
|
||||||
|
// already configured
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
adjustmentState->auxChannelIndex = auxSwitchChannelIndex;
|
||||||
adjustmentState->adjustmentFunction = adjustmentConfig->adjustmentFunction;
|
adjustmentState->adjustmentFunction = adjustmentConfig->adjustmentFunction;
|
||||||
adjustmentState->step = adjustmentConfig->step;
|
adjustmentState->step = adjustmentConfig->step;
|
||||||
adjustmentState->timeoutAt = 0;
|
adjustmentState->timeoutAt = 0;
|
||||||
|
@ -318,7 +323,7 @@ void processRcAdjustments(controlRateConfig_t *controlRateConfig, rxConfig_t *rx
|
||||||
uint8_t adjustmentIndex;
|
uint8_t adjustmentIndex;
|
||||||
uint32_t now = millis();
|
uint32_t now = millis();
|
||||||
|
|
||||||
for (adjustmentIndex = 0; adjustmentIndex < MAX_SIMULTANEOUS_ADJUSTMENTS; adjustmentIndex++) {
|
for (adjustmentIndex = 0; adjustmentIndex < MAX_SIMULTANEOUS_ADJUSTMENT_COUNT; adjustmentIndex++) {
|
||||||
adjustmentState_t *adjustmentState = &adjustmentStates[adjustmentIndex];
|
adjustmentState_t *adjustmentState = &adjustmentStates[adjustmentIndex];
|
||||||
|
|
||||||
uint8_t adjustmentFunction = adjustmentState->adjustmentFunction;
|
uint8_t adjustmentFunction = adjustmentState->adjustmentFunction;
|
||||||
|
@ -358,18 +363,31 @@ void processRcAdjustments(controlRateConfig_t *controlRateConfig, rxConfig_t *rx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateAdjustmentStates(adjustmentRange_t *adjustmentRanges)
|
||||||
|
{
|
||||||
|
uint8_t index;
|
||||||
|
|
||||||
|
for (index = 0; index < MAX_ADJUSTMENT_RANGE_COUNT; index++) {
|
||||||
|
adjustmentRange_t *adjustmentRange = &adjustmentRanges[index];
|
||||||
|
|
||||||
|
if (isRangeActive(adjustmentRange->auxChannelIndex, &adjustmentRange->range)) {
|
||||||
|
|
||||||
|
const adjustmentConfig_t *adjustmentConfig = &defaultAdjustmentConfigs[adjustmentRange->adjustmentFunction - ADJUSTMENT_FUNCTION_CONFIG_INDEX_OFFSET];
|
||||||
|
|
||||||
|
configureAdjustment(adjustmentRange->adjustmentIndex, adjustmentRange->auxSwitchChannelIndex, adjustmentConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void useRcControlsConfig(modeActivationCondition_t *modeActivationConditions)
|
void useRcControlsConfig(modeActivationCondition_t *modeActivationConditions)
|
||||||
{
|
{
|
||||||
uint8_t index;
|
uint8_t index;
|
||||||
|
|
||||||
for (index = 0; index < MAX_MODE_ACTIVATION_CONDITION_COUNT; index++) {
|
for (index = 0; index < MAX_MODE_ACTIVATION_CONDITION_COUNT; index++) {
|
||||||
modeActivationCondition_t *modeActivationCondition = &modeActivationConditions[index];
|
modeActivationCondition_t *modeActivationCondition = &modeActivationConditions[index];
|
||||||
if (modeActivationCondition->modeId == BOXARM && IS_MODE_RANGE_USABLE(modeActivationCondition)) {
|
if (modeActivationCondition->modeId == BOXARM && IS_RANGE_USABLE(&modeActivationCondition->range)) {
|
||||||
isUsingSticksToArm = false;
|
isUsingSticksToArm = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
configureAdjustment(0, AUX3 - NON_AUX_CHANNEL_COUNT, &defaultAdjustmentConfigs[0]);
|
|
||||||
configureAdjustment(1, AUX4 - NON_AUX_CHANNEL_COUNT, &defaultAdjustmentConfigs[1]);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,7 +113,7 @@ typedef struct modeActivationCondition_s {
|
||||||
channelRange_t range;
|
channelRange_t range;
|
||||||
} modeActivationCondition_t;
|
} modeActivationCondition_t;
|
||||||
|
|
||||||
#define IS_MODE_RANGE_USABLE(modeActivationCondition) (modeActivationCondition->range.startStep < modeActivationCondition->range.endStep)
|
#define IS_RANGE_USABLE(range) ((range)->startStep < (range)->endStep)
|
||||||
|
|
||||||
typedef struct controlRateConfig_s {
|
typedef struct controlRateConfig_s {
|
||||||
uint8_t rcRate8;
|
uint8_t rcRate8;
|
||||||
|
@ -150,16 +150,21 @@ typedef struct adjustmentRange_s {
|
||||||
uint8_t auxChannelIndex;
|
uint8_t auxChannelIndex;
|
||||||
channelRange_t range;
|
channelRange_t range;
|
||||||
|
|
||||||
// ..then apply the adjustment function to the auxSwitchChannel
|
// ..then apply the adjustment function to the auxSwitchChannel ...
|
||||||
uint8_t adjustmentFunction;
|
uint8_t adjustmentFunction;
|
||||||
uint8_t auxSwitchChannelIndex;
|
uint8_t auxSwitchChannelIndex;
|
||||||
|
|
||||||
|
// ... via slot
|
||||||
|
uint8_t adjustmentIndex;
|
||||||
} adjustmentRange_t;
|
} adjustmentRange_t;
|
||||||
|
|
||||||
#define ADJUSTMENT_INDEX_OFFSET 1
|
#define ADJUSTMENT_INDEX_OFFSET 1
|
||||||
|
|
||||||
|
#define MAX_SIMULTANEOUS_ADJUSTMENT_COUNT 4 // enough for 4 x 3position switches / 4 aux channel
|
||||||
#define MAX_ADJUSTMENT_RANGE_COUNT 12 // enough for 2 * 6pos switches.
|
#define MAX_ADJUSTMENT_RANGE_COUNT 12 // enough for 2 * 6pos switches.
|
||||||
|
|
||||||
void configureAdjustment(uint8_t index, uint8_t auxChannelIndex, const adjustmentConfig_t *adjustmentConfig);
|
void configureAdjustment(uint8_t index, uint8_t auxChannelIndex, const adjustmentConfig_t *adjustmentConfig);
|
||||||
|
void updateAdjustmentStates(adjustmentRange_t *adjustmentRanges);
|
||||||
void processRcAdjustments(controlRateConfig_t *controlRateConfig, rxConfig_t *rxConfig);
|
void processRcAdjustments(controlRateConfig_t *controlRateConfig, rxConfig_t *rxConfig);
|
||||||
|
|
||||||
void useRcControlsConfig(modeActivationCondition_t *modeActivationConditions);
|
void useRcControlsConfig(modeActivationCondition_t *modeActivationConditions);
|
||||||
|
|
|
@ -493,8 +493,9 @@ static void cliAdjustmentRange(char *cmdline)
|
||||||
// print out adjustment ranges channel settings
|
// print out adjustment ranges channel settings
|
||||||
for (i = 0; i < MAX_ADJUSTMENT_RANGE_COUNT; i++) {
|
for (i = 0; i < MAX_ADJUSTMENT_RANGE_COUNT; i++) {
|
||||||
adjustmentRange_t *ar = ¤tProfile->adjustmentRanges[i];
|
adjustmentRange_t *ar = ¤tProfile->adjustmentRanges[i];
|
||||||
printf("adjrange %u %u %u %u %u %u\r\n",
|
printf("adjrange %u %u %u %u %u %u %u\r\n",
|
||||||
i,
|
i,
|
||||||
|
ar->adjustmentIndex,
|
||||||
ar->auxChannelIndex,
|
ar->auxChannelIndex,
|
||||||
MODE_STEP_TO_CHANNEL_VALUE(ar->range.startStep),
|
MODE_STEP_TO_CHANNEL_VALUE(ar->range.startStep),
|
||||||
MODE_STEP_TO_CHANNEL_VALUE(ar->range.endStep),
|
MODE_STEP_TO_CHANNEL_VALUE(ar->range.endStep),
|
||||||
|
@ -509,6 +510,14 @@ static void cliAdjustmentRange(char *cmdline)
|
||||||
adjustmentRange_t *ar = ¤tProfile->adjustmentRanges[i];
|
adjustmentRange_t *ar = ¤tProfile->adjustmentRanges[i];
|
||||||
uint8_t validArgumentCount = 0;
|
uint8_t validArgumentCount = 0;
|
||||||
ptr = strchr(ptr, ' ');
|
ptr = strchr(ptr, ' ');
|
||||||
|
if (ptr) {
|
||||||
|
val = atoi(++ptr);
|
||||||
|
if (val >= 0 && val < MAX_SIMULTANEOUS_ADJUSTMENT_COUNT) {
|
||||||
|
ar->adjustmentIndex = val;
|
||||||
|
validArgumentCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ptr = strchr(ptr, ' ');
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
val = atoi(++ptr);
|
val = atoi(++ptr);
|
||||||
if (val >= 0 && val < MAX_AUX_CHANNEL_COUNT) {
|
if (val >= 0 && val < MAX_AUX_CHANNEL_COUNT) {
|
||||||
|
@ -534,7 +543,7 @@ static void cliAdjustmentRange(char *cmdline)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (validArgumentCount != 5) {
|
if (validArgumentCount != 6) {
|
||||||
memset(ar, 0, sizeof(adjustmentRange_t));
|
memset(ar, 0, sizeof(adjustmentRange_t));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -496,6 +496,7 @@ void processRx(void)
|
||||||
|
|
||||||
updateActivatedModes(currentProfile->modeActivationConditions);
|
updateActivatedModes(currentProfile->modeActivationConditions);
|
||||||
|
|
||||||
|
updateAdjustmentStates(currentProfile->adjustmentRanges);
|
||||||
processRcAdjustments(¤tProfile->controlRateConfig, &masterConfig.rxConfig);
|
processRcAdjustments(¤tProfile->controlRateConfig, &masterConfig.rxConfig);
|
||||||
|
|
||||||
bool canUseHorizonMode = true;
|
bool canUseHorizonMode = true;
|
||||||
|
|
Loading…
Reference in New Issue