From a071de9cc9ff1b9756bbe652e67d0d6aa7a60139 Mon Sep 17 00:00:00 2001 From: Laurent Lalanne Date: Sun, 22 Jan 2017 00:34:35 +0100 Subject: [PATCH] LP-478 Avoid transition values detected as Flightmode --- .../gcs/src/plugins/config/configinputwidget.cpp | 54 ++++++++++++---------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/ground/gcs/src/plugins/config/configinputwidget.cpp b/ground/gcs/src/plugins/config/configinputwidget.cpp index 54fa301b1..fd78e4399 100644 --- a/ground/gcs/src/plugins/config/configinputwidget.cpp +++ b/ground/gcs/src/plugins/config/configinputwidget.cpp @@ -1172,6 +1172,7 @@ void ConfigInputWidget::identifyControls() void ConfigInputWidget::identifyLimits() { uint16_t inputValue; + static uint16_t previousInputFMValue; bool newLimitValue = false; bool newFlightModeValue = false; @@ -1204,32 +1205,37 @@ void ConfigInputWidget::identifyLimits() } // Flightmode channel if (i == ManualControlSettings::CHANNELGROUPS_FLIGHTMODE) { - // Avoid duplicate values too close and error due to RcTx drift - int minSpacing = 100; // 100µs - for (int pos = 0; pos < manualSettingsData.FlightModeNumber + 1; ++pos) { - if (flightModeSignalValue[pos] == 0) { - newFlightModeValue = true; - // A new flightmode value can be set now - 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; + int deltaInput = abs(previousInputFMValue - inputValue); + previousInputFMValue = inputValue; + // Expecting two consecutive readings within a close value + if (deltaInput < 5) { + // Avoid duplicate values too close and error due to RcTx drift + int minSpacing = 100; // 100µs + for (int pos = 0; pos < manualSettingsData.FlightModeNumber + 1; ++pos) { + if (flightModeSignalValue[pos] == 0) { + newFlightModeValue = true; + // A new flightmode value can be set now + 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) - if ((manualSettingsData.FlightModeNumber < FlightModeSettings::FLIGHTMODEPOSITION_NUMELEM) && newFlightModeValue) { - // Start from 0, erase previous count - if (pos == 0) { - manualSettingsData.FlightModeNumber = 0; + // Be sure FlightModeNumber is < FlightModeSettings::FLIGHTMODEPOSITION_NUMELEM (6) + if ((manualSettingsData.FlightModeNumber < FlightModeSettings::FLIGHTMODEPOSITION_NUMELEM) && newFlightModeValue) { + // Start from 0, erase previous count + if (pos == 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); } } } -- 2.11.4.GIT