1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-26 15:54:15 +01:00

LP-478 Avoid transition values detected as Flightmode

This commit is contained in:
Laurent Lalanne 2017-01-22 00:34:35 +01:00
parent 184ac1e4e7
commit a071de9cc9

View File

@ -1172,6 +1172,7 @@ void ConfigInputWidget::identifyControls()
void ConfigInputWidget::identifyLimits() void ConfigInputWidget::identifyLimits()
{ {
uint16_t inputValue; uint16_t inputValue;
static uint16_t previousInputFMValue;
bool newLimitValue = false; bool newLimitValue = false;
bool newFlightModeValue = false; bool newFlightModeValue = false;
@ -1204,32 +1205,37 @@ void ConfigInputWidget::identifyLimits()
} }
// Flightmode channel // Flightmode channel
if (i == ManualControlSettings::CHANNELGROUPS_FLIGHTMODE) { if (i == ManualControlSettings::CHANNELGROUPS_FLIGHTMODE) {
// Avoid duplicate values too close and error due to RcTx drift int deltaInput = abs(previousInputFMValue - inputValue);
int minSpacing = 100; // 100µs previousInputFMValue = inputValue;
for (int pos = 0; pos < manualSettingsData.FlightModeNumber + 1; ++pos) { // Expecting two consecutive readings within a close value
if (flightModeSignalValue[pos] == 0) { if (deltaInput < 5) {
newFlightModeValue = true; // Avoid duplicate values too close and error due to RcTx drift
// A new flightmode value can be set now int minSpacing = 100; // 100µs
for (int checkpos = 0; checkpos < manualSettingsData.FlightModeNumber + 1; ++checkpos) { for (int pos = 0; pos < manualSettingsData.FlightModeNumber + 1; ++pos) {
// Check if value is already used, MinSpacing needed between values. if (flightModeSignalValue[pos] == 0) {
if ((flightModeSignalValue[checkpos] < inputValue + minSpacing) && newFlightModeValue = true;
(flightModeSignalValue[checkpos] > inputValue - minSpacing)) { // A new flightmode value can be set now
newFlightModeValue = false; for (int checkpos = 0; checkpos < manualSettingsData.FlightModeNumber + 1; ++checkpos) {
// Check if value is already used, MinSpacing needed between values.
if ((flightModeSignalValue[checkpos] < inputValue + minSpacing) &&
(flightModeSignalValue[checkpos] > inputValue - minSpacing)) {
newFlightModeValue = false;
}
} }
} // Be sure FlightModeNumber is < FlightModeSettings::FLIGHTMODEPOSITION_NUMELEM (6)
// Be sure FlightModeNumber is < FlightModeSettings::FLIGHTMODEPOSITION_NUMELEM (6) if ((manualSettingsData.FlightModeNumber < FlightModeSettings::FLIGHTMODEPOSITION_NUMELEM) && newFlightModeValue) {
if ((manualSettingsData.FlightModeNumber < FlightModeSettings::FLIGHTMODEPOSITION_NUMELEM) && newFlightModeValue) { // Start from 0, erase previous count
// Start from 0, erase previous count if (pos == 0) {
if (pos == 0) { manualSettingsData.FlightModeNumber = 0;
manualSettingsData.FlightModeNumber = 0; }
// Store new value and increase FlightModeNumber
flightModeSignalValue[pos] = inputValue;
manualSettingsData.FlightModeNumber++;
// Show flight mode number
m_txFlightModeCountText->setText(QString().number(manualSettingsData.FlightModeNumber));
m_txFlightModeCountText->setVisible(true);
m_txFlightModeCountBG->setVisible(true);
} }
// Store new value and increase FlightModeNumber
flightModeSignalValue[pos] = inputValue;
manualSettingsData.FlightModeNumber++;
// Show flight mode number
m_txFlightModeCountText->setText(QString().number(manualSettingsData.FlightModeNumber));
m_txFlightModeCountText->setVisible(true);
m_txFlightModeCountBG->setVisible(true);
} }
} }
} }