diff --git a/src/AutoPilotPlugins/APM/APMFlightModesComponent.qml b/src/AutoPilotPlugins/APM/APMFlightModesComponent.qml index 7c81ccbd1d899afde9420de3769380b79328c3c9..3e83137cc439cb7b7069922cbb1d992da0de174e 100644 --- a/src/AutoPilotPlugins/APM/APMFlightModesComponent.qml +++ b/src/AutoPilotPlugins/APM/APMFlightModesComponent.qml @@ -39,6 +39,9 @@ QGCView { property bool _channel7OptionsAvailable: controller.parameterExists(-1, "CH7_OPT") // Not available in all firmware types property bool _channel9OptionsAvailable: controller.parameterExists(-1, "CH9_OPT") // Not available in all firmware types property int _channelOptionCount: _channel7OptionsAvailable ? (_channel9OptionsAvailable ? 6 : 2) : 0 + property Fact _nullFact + property bool _fltmodeChExists: controller.parameterExists(-1, "FLTMODE_CH") + property Fact _fltmodeCh: _fltmodeChExists ? controller.getParameterFact(-1, "FLTMODE_CH") : _nullFact QGCPalette { id: qgcPal; colorGroupEnabled: panel.enabled } @@ -59,7 +62,7 @@ QGCView { QGCLabel { id: flightModeLabel - text: "Channel 5 Flight Mode Settings" + text: "Flight Mode Settings" + (_fltmodeChExists ? "" : " (Channel 5)") font.weight: Font.DemiBold } @@ -75,10 +78,28 @@ QGCView { id: flightModeColumn anchors.margins: ScreenTools.defaultFontPixelWidth anchors.left: parent.left - // anchors.right: parent.right anchors.top: parent.top spacing: ScreenTools.defaultFontPixelHeight + Row { + spacing: _margins + visible: _fltmodeChExists + + QGCLabel { + id: modeChannelLabel + anchors.baseline: modeChannelCombo.baseline + text: "Flight mode channel:" + } + + QGCComboBox { + id: modeChannelCombo + width: ScreenTools.defaultFontPixelWidth * 15 + model: [ "Not assigned", "Channel 1", "Channel 2","Channel 3","Channel 4","Channel 5","Channel 6","Channel 7","Channel 8" ] + currentIndex: _fltmodeCh.value + onActivated: _fltmodeCh.value = index + } + } + Repeater { model: 6 diff --git a/src/AutoPilotPlugins/APM/APMFlightModesComponentController.cc b/src/AutoPilotPlugins/APM/APMFlightModesComponentController.cc index b72f953b8e2c4893dd9203808163336707c3264c..d62eab020be27bde34ac17d88bf63be58accb684 100644 --- a/src/AutoPilotPlugins/APM/APMFlightModesComponentController.cc +++ b/src/AutoPilotPlugins/APM/APMFlightModesComponentController.cc @@ -32,8 +32,6 @@ APMFlightModesComponentController::APMFlightModesComponentController(void) : _activeFlightMode(0) , _channelCount(Vehicle::cMaxRcChannels) , _fixedWing(_vehicle->vehicleType() == MAV_TYPE_FIXED_WING) - , _flightModeChannel(5) - { QStringList usedParams; usedParams << QStringLiteral("FLTMODE1") << QStringLiteral("FLTMODE2") << QStringLiteral("FLTMODE3") @@ -42,10 +40,6 @@ APMFlightModesComponentController::APMFlightModesComponentController(void) return; } - if (parameterExists(FactSystem::defaultComponentId, QStringLiteral("FLTMODE_CH"))) { - _flightModeChannel = getParameterFact(FactSystem::defaultComponentId, QStringLiteral("FLTMODE_CH"))->rawValue().toInt(); - } - _rgChannelOptionEnabled << QVariant(false) << QVariant(false) << QVariant(false) << QVariant(false) << QVariant(false) << QVariant(false); connect(_vehicle, &Vehicle::rcChannelsChanged, this, &APMFlightModesComponentController::_rcChannelsChanged); @@ -54,12 +48,18 @@ APMFlightModesComponentController::APMFlightModesComponentController(void) /// Connected to Vehicle::rcChannelsChanged signal void APMFlightModesComponentController::_rcChannelsChanged(int channelCount, int pwmValues[Vehicle::cMaxRcChannels]) { - if (_flightModeChannel > channelCount) { + int flightModeChannel = 4; + + if (parameterExists(FactSystem::defaultComponentId, QStringLiteral("FLTMODE_CH"))) { + flightModeChannel = getParameterFact(FactSystem::defaultComponentId, QStringLiteral("FLTMODE_CH"))->rawValue().toInt() - 1; + } + + if (flightModeChannel >= channelCount) { return; } _activeFlightMode = 0; - int channelValue = pwmValues[_flightModeChannel - 1]; + int channelValue = pwmValues[flightModeChannel]; if (channelValue != -1) { bool found = false; int rgThreshold[] = { 1230, 1360, 1490, 1620, 1749 }; diff --git a/src/AutoPilotPlugins/APM/APMFlightModesComponentController.h b/src/AutoPilotPlugins/APM/APMFlightModesComponentController.h index c8a13223efe6cf07bdb8cc18029260f07911c593..66b57d200744a7f5ed03c24e5f11763a33e7f8a0 100644 --- a/src/AutoPilotPlugins/APM/APMFlightModesComponentController.h +++ b/src/AutoPilotPlugins/APM/APMFlightModesComponentController.h @@ -62,7 +62,6 @@ private: int _channelCount; QVariantList _rgChannelOptionEnabled; bool _fixedWing; - int _flightModeChannel; }; #endif