1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-26 17:55:30 +03:00

Prevent bad data being used during early system startup.

This commit is contained in:
Dominic Clifton 2014-06-23 22:08:29 +01:00
parent e30a373c92
commit 2413130c0f
2 changed files with 31 additions and 15 deletions

View file

@ -515,12 +515,6 @@ void processRx(void)
LED1_OFF;
}
#ifdef BARO
if (sensors(SENSOR_BARO)) {
updateAltHoldState();
}
#endif
#ifdef MAG
if (sensors(SENSOR_ACC) || sensors(SENSOR_MAG)) {
if (rcOptions[BOXMAG]) {
@ -562,13 +556,23 @@ void processRx(void)
void loop(void)
{
static uint32_t loopTime;
static bool haveProcessedAnnexCodeOnce = false;
updateRx();
if (shouldProcessRx(currentTime)) {
processRx();
#ifdef BARO
// the 'annexCode' initialses rcCommand, updateAltHoldState depends on valid rcCommand data.
if (haveProcessedAnnexCodeOnce) {
if (sensors(SENSOR_BARO)) {
updateAltHoldState();
}
}
#endif
} else {
// not in rc loop
// not processing rx this iteration
executePeriodicTasks();
}
@ -584,6 +588,7 @@ void loop(void)
previousTime = currentTime;
annexCode();
haveProcessedAnnexCodeOnce = true;
updateAutotuneState();
@ -598,6 +603,7 @@ void loop(void)
if (f.BARO_MODE) {
updateAltHold();
}
debug[0] = rcCommand[THROTTLE];
}
#endif

View file

@ -202,11 +202,21 @@ uint16_t calculateNonDataDrivenChannel(uint8_t chan, uint16_t sample)
{
static int16_t rcSamples[MAX_SUPPORTED_RX_PARALLEL_PWM_OR_PPM_CHANNEL_COUNT][PPM_AND_PWM_SAMPLE_COUNT];
static int16_t rcDataMean[MAX_SUPPORTED_RX_PARALLEL_PWM_OR_PPM_CHANNEL_COUNT];
static bool rxSamplesCollected = false;
uint8_t currentSampleIndex = rcSampleIndex % PPM_AND_PWM_SAMPLE_COUNT;
// update the recent samples and compute the average of them
rcSamples[chan][currentSampleIndex] = sample;
// avoid returning an incorrect average which would otherwise occur before enough samples
if (!rxSamplesCollected) {
if (rcSampleIndex < PPM_AND_PWM_SAMPLE_COUNT) {
return sample;
}
rxSamplesCollected = true;
}
rcDataMean[chan] = 0;
uint8_t sampleIndex;