mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-18 22:05:17 +03:00
Seperate adjustment configuration from adjustment state. Rename 'step'
parameter to 'delta' applying the adjustment. Configure adjustment states based on adjustment configuration for AUX3 and AUX4.
This commit is contained in:
parent
45d9678a39
commit
a2a9443045
3 changed files with 59 additions and 23 deletions
|
@ -257,29 +257,46 @@ uint8_t adjustmentStateMask = 0;
|
||||||
|
|
||||||
#define IS_ADJUSTMENT_FUNCTION_BUSY(adjustmentIndex) (adjustmentStateMask & (1 << adjustmentIndex))
|
#define IS_ADJUSTMENT_FUNCTION_BUSY(adjustmentIndex) (adjustmentStateMask & (1 << adjustmentIndex))
|
||||||
|
|
||||||
typedef struct adjustmentConfig_s {
|
static const adjustmentConfig_t defaultAdjustmentConfigs[] = {
|
||||||
uint8_t auxChannelIndex;
|
|
||||||
uint8_t adjustmentFunction;
|
|
||||||
uint8_t step;
|
|
||||||
uint32_t timeoutAt;
|
|
||||||
} adjustmentConfig_t;
|
|
||||||
|
|
||||||
static adjustmentConfig_t adjustmentConfigs[1] = {
|
|
||||||
{
|
{
|
||||||
.auxChannelIndex = AUX3 - NON_AUX_CHANNEL_COUNT,
|
|
||||||
.adjustmentFunction = ADJUSTMENT_RC_RATE,
|
.adjustmentFunction = ADJUSTMENT_RC_RATE,
|
||||||
.step = 1,
|
.step = 1
|
||||||
.timeoutAt = 0
|
},
|
||||||
|
{
|
||||||
|
.adjustmentFunction = ADJUSTMENT_NONE,
|
||||||
|
.step = 0
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void applyAdjustment(controlRateConfig_t *controlRateConfig, uint8_t adjustmentFunction, int step) {
|
typedef struct adjustmentState_s {
|
||||||
|
uint8_t auxChannelIndex;
|
||||||
|
uint8_t adjustmentFunction;
|
||||||
|
uint8_t step;
|
||||||
|
uint32_t timeoutAt;
|
||||||
|
} adjustmentState_t;
|
||||||
|
|
||||||
|
#define MAX_SIMULTANEOUS_ADJUSTMENTS 2
|
||||||
|
|
||||||
|
static adjustmentState_t adjustmentStates[MAX_SIMULTANEOUS_ADJUSTMENTS];
|
||||||
|
|
||||||
|
void configureAdjustment(uint8_t index, uint8_t auxChannelIndex, const adjustmentConfig_t *adjustmentConfig) {
|
||||||
|
adjustmentState_t *adjustmentState = &adjustmentStates[index];
|
||||||
|
|
||||||
|
adjustmentState->auxChannelIndex = auxChannelIndex;
|
||||||
|
adjustmentState->adjustmentFunction = adjustmentConfig->adjustmentFunction;
|
||||||
|
adjustmentState->step = adjustmentConfig->step;
|
||||||
|
adjustmentState->timeoutAt = 0;
|
||||||
|
|
||||||
|
MARK_ADJUSTMENT_FUNCTION_AS_READY(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void applyAdjustment(controlRateConfig_t *controlRateConfig, uint8_t adjustmentFunction, int delta) {
|
||||||
int newValue;
|
int newValue;
|
||||||
|
|
||||||
switch(adjustmentFunction) {
|
switch(adjustmentFunction) {
|
||||||
case ADJUSTMENT_RC_RATE:
|
case ADJUSTMENT_RC_RATE:
|
||||||
newValue = (int)controlRateConfig->rcRate8 + step;
|
newValue = (int)controlRateConfig->rcRate8 + delta;
|
||||||
controlRateConfig->rcRate8 = constrain(newValue, 0, 250); // FIXME magic numbers repeated in serial_cli.c
|
controlRateConfig->rcRate8 = constrain(newValue, 0, 250); // FIXME magic numbers repeated in serial_cli.c
|
||||||
generatePitchRollCurve(controlRateConfig);
|
generatePitchRollCurve(controlRateConfig);
|
||||||
break;
|
break;
|
||||||
|
@ -296,33 +313,33 @@ void processRcAdjustments(controlRateConfig_t *controlRateConfig, rxConfig_t *rx
|
||||||
uint32_t now = millis();
|
uint32_t now = millis();
|
||||||
|
|
||||||
for (adjustmentIndex = 0; adjustmentIndex < ADJUSTMENT_COUNT; adjustmentIndex++) {
|
for (adjustmentIndex = 0; adjustmentIndex < ADJUSTMENT_COUNT; adjustmentIndex++) {
|
||||||
adjustmentConfig_t *adjustmentConfig = &adjustmentConfigs[adjustmentIndex];
|
adjustmentState_t *adjustmentState = &adjustmentStates[adjustmentIndex];
|
||||||
|
|
||||||
uint8_t adjustmentFunction = adjustmentConfig->adjustmentFunction;
|
uint8_t adjustmentFunction = adjustmentState->adjustmentFunction;
|
||||||
if (adjustmentFunction == ADJUSTMENT_NONE) {
|
if (adjustmentFunction == ADJUSTMENT_NONE) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t signedDiff = now - adjustmentConfig->timeoutAt;
|
int32_t signedDiff = now - adjustmentState->timeoutAt;
|
||||||
bool canResetReadyStates = signedDiff >= 0L;
|
bool canResetReadyStates = signedDiff >= 0L;
|
||||||
|
|
||||||
if (canResetReadyStates) {
|
if (canResetReadyStates) {
|
||||||
adjustmentConfig->timeoutAt = now + RESET_FREQUENCY_2HZ;
|
adjustmentState->timeoutAt = now + RESET_FREQUENCY_2HZ;
|
||||||
MARK_ADJUSTMENT_FUNCTION_AS_READY(adjustmentIndex);
|
MARK_ADJUSTMENT_FUNCTION_AS_READY(adjustmentIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint8_t channelIndex = NON_AUX_CHANNEL_COUNT + adjustmentConfig->auxChannelIndex;
|
uint8_t channelIndex = NON_AUX_CHANNEL_COUNT + adjustmentState->auxChannelIndex;
|
||||||
|
|
||||||
int step;
|
int delta;
|
||||||
if (rcData[channelIndex] > rxConfig->midrc + 200) {
|
if (rcData[channelIndex] > rxConfig->midrc + 200) {
|
||||||
step = adjustmentConfig->step;
|
delta = adjustmentState->step;
|
||||||
} else if (rcData[channelIndex] < rxConfig->midrc - 200) {
|
} else if (rcData[channelIndex] < rxConfig->midrc - 200) {
|
||||||
step = 0 - adjustmentConfig->step;
|
delta = 0 - adjustmentState->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(adjustmentIndex);
|
MARK_ADJUSTMENT_FUNCTION_AS_READY(adjustmentIndex);
|
||||||
adjustmentConfig->timeoutAt = now + RESET_FREQUENCY_2HZ;
|
adjustmentState->timeoutAt = now + RESET_FREQUENCY_2HZ;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -331,7 +348,7 @@ void processRcAdjustments(controlRateConfig_t *controlRateConfig, rxConfig_t *rx
|
||||||
}
|
}
|
||||||
|
|
||||||
MARK_ADJUSTMENT_FUNCTION_AS_BUSY(adjustmentIndex);
|
MARK_ADJUSTMENT_FUNCTION_AS_BUSY(adjustmentIndex);
|
||||||
applyAdjustment(controlRateConfig, adjustmentFunction, step);
|
applyAdjustment(controlRateConfig, adjustmentFunction, delta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,4 +363,7 @@ void useRcControlsConfig(modeActivationCondition_t *modeActivationConditions)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
configureAdjustment(0, AUX3 - NON_AUX_CHANNEL_COUNT, &defaultAdjustmentConfigs[0]);
|
||||||
|
configureAdjustment(1, AUX4 - NON_AUX_CHANNEL_COUNT, &defaultAdjustmentConfigs[1]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,10 +135,17 @@ typedef enum {
|
||||||
ADJUSTMENT_RC_RATE
|
ADJUSTMENT_RC_RATE
|
||||||
} adjustmentFunction_e;
|
} adjustmentFunction_e;
|
||||||
|
|
||||||
|
typedef struct adjustmentConfig_s {
|
||||||
|
uint8_t adjustmentFunction;
|
||||||
|
uint8_t step;
|
||||||
|
} adjustmentConfig_t;
|
||||||
|
|
||||||
|
|
||||||
#define ADJUSTMENT_COUNT 1
|
#define ADJUSTMENT_COUNT 1
|
||||||
|
|
||||||
#define ADJUSTMENT_INDEX_OFFSET 1
|
#define ADJUSTMENT_INDEX_OFFSET 1
|
||||||
|
|
||||||
|
void configureAdjustment(uint8_t index, uint8_t auxChannelIndex, const adjustmentConfig_t *adjustmentConfig);
|
||||||
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);
|
||||||
|
|
|
@ -187,6 +187,10 @@ rxConfig_t rxConfig;
|
||||||
|
|
||||||
extern uint8_t adjustmentStateMask;
|
extern uint8_t adjustmentStateMask;
|
||||||
|
|
||||||
|
static const adjustmentConfig_t rateAdjustmentConfig = {
|
||||||
|
.adjustmentFunction = ADJUSTMENT_RC_RATE,
|
||||||
|
.step = 1
|
||||||
|
};
|
||||||
TEST(RcControlsTest, processRcAdjustmentsSticksInMiddle)
|
TEST(RcControlsTest, processRcAdjustmentsSticksInMiddle)
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
|
@ -205,6 +209,8 @@ TEST(RcControlsTest, processRcAdjustmentsSticksInMiddle)
|
||||||
rxConfig.maxcheck = DEFAULT_MAX_CHECK;
|
rxConfig.maxcheck = DEFAULT_MAX_CHECK;
|
||||||
rxConfig.midrc = 1500;
|
rxConfig.midrc = 1500;
|
||||||
|
|
||||||
|
configureAdjustment(0, AUX3 - NON_AUX_CHANNEL_COUNT, &rateAdjustmentConfig);
|
||||||
|
|
||||||
// and
|
// and
|
||||||
uint8_t index;
|
uint8_t index;
|
||||||
for (index = AUX1; index < MAX_SUPPORTED_RC_CHANNEL_COUNT; index++) {
|
for (index = AUX1; index < MAX_SUPPORTED_RC_CHANNEL_COUNT; index++) {
|
||||||
|
@ -241,6 +247,9 @@ TEST(RcControlsTest, processRcAdjustmentsWithRcRateFunctionSwitchUp)
|
||||||
rxConfig.maxcheck = DEFAULT_MAX_CHECK;
|
rxConfig.maxcheck = DEFAULT_MAX_CHECK;
|
||||||
rxConfig.midrc = 1500;
|
rxConfig.midrc = 1500;
|
||||||
|
|
||||||
|
// and
|
||||||
|
configureAdjustment(0, AUX3 - NON_AUX_CHANNEL_COUNT, &rateAdjustmentConfig);
|
||||||
|
|
||||||
// and
|
// and
|
||||||
uint8_t index;
|
uint8_t index;
|
||||||
for (index = AUX1; index < MAX_SUPPORTED_RC_CHANNEL_COUNT; index++) {
|
for (index = AUX1; index < MAX_SUPPORTED_RC_CHANNEL_COUNT; index++) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue