static void detectAndApplySignalLossBehaviour(void) { int channel; uint16_t sample; bool useValueFromRx = true; bool rxIsDataDriven = isRxDataDriven(); if (!rxSignalReceived) { if (rxIsDataDriven && rxDataReceived) { // use the values from the RX } else { useValueFromRx = false; } } rxResetFlightChannelStatus(); for (channel = 0; channel < rxRuntimeConfig.channelCount; channel++) { sample = (useValueFromRx) ? rcRaw[channel] : PPM_RCVR_TIMEOUT; bool validPulse = isPulseValid(sample); if (!validPulse) { sample = getRxfailValue(channel); } rxUpdateFlightChannelStatus(channel, validPulse); if (rxIsDataDriven) { rcData[channel] = sample; } else { rcData[channel] = calculateNonDataDrivenChannel(channel, sample); } } rxFlightChannelsValid = rxHaveValidFlightChannels(); if ((rxFlightChannelsValid) && !IS_RC_MODE_ACTIVE(BOXFAILSAFE)) { failsafeOnValidDataReceived(); } else { rxSignalReceived = false; failsafeOnValidDataFailed(); for (channel = 0; channel < rxRuntimeConfig.channelCount; channel++) { rcData[channel] = getRxfailValue(channel); } } }
static void detectAndApplySignalLossBehaviour(void) { int channel; uint16_t sample; bool useValueFromRx = true; bool rxIsDataDriven = isRxDataDriven(); uint32_t currentMilliTime = millis(); if (!rxIsDataDriven) { rxSignalReceived = rxSignalReceivedNotDataDriven; rxIsInFailsafeMode = rxIsInFailsafeModeNotDataDriven; } if (!rxSignalReceived || rxIsInFailsafeMode) { useValueFromRx = false; } #ifdef DEBUG_RX_SIGNAL_LOSS debug[0] = rxSignalReceived; debug[1] = rxIsInFailsafeMode; debug[2] = rxRuntimeConfig.rcReadRawFn(&rxRuntimeConfig, 0); #endif rxResetFlightChannelStatus(); for (channel = 0; channel < rxRuntimeConfig.channelCount; channel++) { sample = (useValueFromRx) ? rcRaw[channel] : PPM_RCVR_TIMEOUT; bool validPulse = isPulseValid(sample); if (!validPulse) { if (currentMilliTime < rcInvalidPulsPeriod[channel]) { sample = rcData[channel]; // hold channel for MAX_INVALID_PULS_TIME } else { sample = getRxfailValue(channel); // after that apply rxfail value rxUpdateFlightChannelStatus(channel, validPulse); } } else { rcInvalidPulsPeriod[channel] = currentMilliTime + MAX_INVALID_PULS_TIME; } if (rxIsDataDriven) { rcData[channel] = sample; } else { rcData[channel] = calculateNonDataDrivenChannel(channel, sample); } } rxFlightChannelsValid = rxHaveValidFlightChannels(); if ((rxFlightChannelsValid) && !(IS_RC_MODE_ACTIVE(BOXFAILSAFE) && feature(FEATURE_FAILSAFE))) { failsafeOnValidDataReceived(); } else { rxIsInFailsafeMode = rxIsInFailsafeModeNotDataDriven = true; failsafeOnValidDataFailed(); for (channel = 0; channel < rxRuntimeConfig.channelCount; channel++) { rcData[channel] = getRxfailValue(channel); } } #ifdef DEBUG_RX_SIGNAL_LOSS debug[3] = rcData[THROTTLE]; #endif }