Update adjustmentConfig to include the adjustment timeout.

This commit is contained in:
Dominic Clifton 2014-10-24 14:58:41 +01:00
parent 02c93f1c1a
commit e21f0667c5
1 changed files with 10 additions and 11 deletions

View File

@ -261,13 +261,15 @@ typedef struct adjustmentConfig_s {
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,
.step = 1
.step = 1,
.timeoutAt = 0
}
};
@ -291,15 +293,7 @@ void applyAdjustment(controlRateConfig_t *controlRateConfig, uint8_t adjustmentF
void processRcAdjustments(controlRateConfig_t *controlRateConfig, rxConfig_t *rxConfig)
{
uint8_t adjustmentIndex;
static uint32_t timeoutAt = 0;
uint32_t now = millis();
int32_t signedDiff = now - timeoutAt;
bool canResetReadyStates = signedDiff >= 0L;
if (canResetReadyStates) {
timeoutAt = now + RESET_FREQUENCY_2HZ;
}
for (adjustmentIndex = 0; adjustmentIndex < ADJUSTMENT_COUNT; adjustmentIndex++) {
adjustmentConfig_t *adjustmentConfig = &adjustmentConfigs[adjustmentIndex];
@ -309,10 +303,15 @@ void processRcAdjustments(controlRateConfig_t *controlRateConfig, rxConfig_t *rx
continue;
}
int32_t signedDiff = now - adjustmentConfig->timeoutAt;
bool canResetReadyStates = signedDiff >= 0L;
if (canResetReadyStates) {
adjustmentConfig->timeoutAt = now + RESET_FREQUENCY_2HZ;
MARK_ADJUSTMENT_FUNCTION_AS_READY(adjustmentFunction);
}
uint8_t channelIndex = NON_AUX_CHANNEL_COUNT + adjustmentConfig->auxChannelIndex;
int step;
@ -323,7 +322,7 @@ void processRcAdjustments(controlRateConfig_t *controlRateConfig, rxConfig_t *rx
} else {
// returning the switch to the middle immediately resets the ready state
MARK_ADJUSTMENT_FUNCTION_AS_READY(adjustmentFunction);
timeoutAt = now + RESET_FREQUENCY_2HZ;
adjustmentConfig->timeoutAt = now + RESET_FREQUENCY_2HZ;
continue;
}