From c1480680096c72c29c3838f75fdee7b5ebd0a90f Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Sat, 5 Mar 2016 13:46:12 -0800 Subject: [PATCH] Add switch assignment --- .../PX4/PX4SimpleFlightModes.qml | 177 ++++++++++++------ .../PX4/PX4SimpleFlightModesController.cc | 6 + .../PX4/PX4SimpleFlightModesController.h | 7 +- 3 files changed, 126 insertions(+), 64 deletions(-) diff --git a/src/AutoPilotPlugins/PX4/PX4SimpleFlightModes.qml b/src/AutoPilotPlugins/PX4/PX4SimpleFlightModes.qml index 45df98829..bc74e5dec 100644 --- a/src/AutoPilotPlugins/PX4/PX4SimpleFlightModes.qml +++ b/src/AutoPilotPlugins/PX4/PX4SimpleFlightModes.qml @@ -57,79 +57,132 @@ Item { id: contentColumn spacing: _margins - QGCLabel { - id: flightModeLabel - text: "Flight Mode Settings" - font.weight: Font.DemiBold - } - - Item { - height: modeChannelCombo.height - width: modeChannelCombo.x + modeChannelCombo.width - - QGCLabel { - id: modeChannelLabel - anchors.baseline: modeChannelCombo.baseline - text: "Flight mode channel:" - } - - FactComboBox { - id: modeChannelCombo - anchors.leftMargin: _margins - anchors.left: modeChannelLabel.right - width: ScreenTools.defaultFontPixelWidth * 15 - fact: controller.getParameterFact(-1, "RC_MAP_FLTMODE") - indexModel: false - } - } - - Rectangle { - id: flightModeSettings - width: flightModeColumn.width + (_margins * 2) - height: flightModeColumn.height + ScreenTools.defaultFontPixelHeight - color: qgcPal.windowShade + Row { + id: settingsRow + spacing: _margins Column { - id: flightModeColumn - anchors.margins: ScreenTools.defaultFontPixelWidth - anchors.left: parent.left - anchors.top: parent.top - spacing: ScreenTools.defaultFontPixelHeight + id: flightModeSettingsColumn + spacing: _margins + + QGCLabel { + id: flightModeLabel + text: "Flight Mode Settings" + font.weight: Font.DemiBold + } + + Rectangle { + id: flightModeSettings + width: flightModeColumn.width + (_margins * 2) + height: flightModeColumn.height + ScreenTools.defaultFontPixelHeight + color: qgcPal.windowShade + + Column { + id: flightModeColumn + anchors.margins: ScreenTools.defaultFontPixelWidth + anchors.left: parent.left + anchors.top: parent.top + spacing: ScreenTools.defaultFontPixelHeight + + Row { + spacing: _margins + + QGCLabel { + id: modeChannelLabel + anchors.baseline: modeChannelCombo.baseline + text: "Flight mode channel:" + } + + FactComboBox { + id: modeChannelCombo + width: ScreenTools.defaultFontPixelWidth * 15 + fact: controller.getParameterFact(-1, "RC_MAP_FLTMODE") + indexModel: false + } + } - Repeater { - model: 6 + Repeater { + model: 6 - Row { - spacing: ScreenTools.defaultFontPixelWidth + Row { + spacing: ScreenTools.defaultFontPixelWidth - property int index: modelData + 1 - property var pwmStrings: [ "PWM 0 - 1230", "PWM 1231 - 1360", "PWM 1361 - 1490", "PWM 1491 - 1620", "PWM 1621 - 1749", "PWM 1750 +"] + property int index: modelData + 1 + property var pwmStrings: [ "PWM 0 - 1230", "PWM 1231 - 1360", "PWM 1361 - 1490", "PWM 1491 - 1620", "PWM 1621 - 1749", "PWM 1750 +"] - QGCLabel { - anchors.baseline: modeCombo.baseline - text: "Flight Mode " + index + ":" - color: controller.activeFlightMode == index ? "yellow" : qgcPal.text - } + QGCLabel { + anchors.baseline: modeCombo.baseline + text: "Flight Mode " + index + ":" + color: controller.activeFlightMode == index ? "yellow" : qgcPal.text + } - FactComboBox { - id: modeCombo - width: ScreenTools.defaultFontPixelWidth * 20 - fact: controller.getParameterFact(-1, "COM_FLTMODE" + index) - indexModel: false - } + FactComboBox { + id: modeCombo + width: ScreenTools.defaultFontPixelWidth * 20 + fact: controller.getParameterFact(-1, "COM_FLTMODE" + index) + indexModel: false + } - QGCLabel { - anchors.baseline: modeCombo.baseline - text: pwmStrings[modelData] - } - } - } // Repeater - Flight Modes - } // Column - Flight Modes - } // Rectangle - Flight Modes + QGCLabel { + anchors.baseline: modeCombo.baseline + text: pwmStrings[modelData] + } + } + } // Repeater - Flight Modes + } // Column - Flight Modes + } // Rectangle - Flight Modes + } // Column - Flight mode settings + + Column { + spacing: _margins + + QGCLabel { + text: "Switch Settings" + font.weight: Font.DemiBold + } + + Rectangle { + width: switchSettingsColumn.width + (_margins * 2) + height: switchSettingsColumn.height + ScreenTools.defaultFontPixelHeight + color: qgcPal.windowShade + + Column { + id: switchSettingsColumn + anchors.margins: ScreenTools.defaultFontPixelWidth + anchors.left: parent.left + anchors.top: parent.top + spacing: ScreenTools.defaultFontPixelHeight + + Repeater { + model: [ "RC_MAP_RETURN_SW", "RC_MAP_KILL_SW", "RC_MAP_FLAPS", "RC_MAP_AUX1", "RC_MAP_AUX2", "RC_MAP_AUX3", "RC_MAP_OFFB_SW" ] + + Row { + spacing: ScreenTools.defaultFontPixelWidth + + property Fact fact: controller.getParameterFact(-1, modelData) + + QGCLabel { + anchors.baseline: optCombo.baseline + text: fact.shortDescription + ":" + color: fact.value == 0 ? qgcPal.text : (controller.rcChannelValues[fact.value - 1] >= 1500 ? "yellow" : qgcPal.text) + } + + FactComboBox { + id: optCombo + width: ScreenTools.defaultFontPixelWidth * 15 + fact: parent.fact + indexModel: false + } + } + } // Repeater + } // Column + } // Rectangle + } // Column - Switch settings + } // Row - Settings QGCButton { - text: "Use Advanced Flight Modes" + text: "Use Advanced Flight Modes" onClicked: { controller.getParameterFact(-1, "RC_MAP_MODE_SW").value = 5 controller.getParameterFact(-1, "RC_MAP_FLTMODE").value = 0 diff --git a/src/AutoPilotPlugins/PX4/PX4SimpleFlightModesController.cc b/src/AutoPilotPlugins/PX4/PX4SimpleFlightModesController.cc index ffc4ee6e5..18808d951 100644 --- a/src/AutoPilotPlugins/PX4/PX4SimpleFlightModesController.cc +++ b/src/AutoPilotPlugins/PX4/PX4SimpleFlightModesController.cc @@ -47,6 +47,12 @@ PX4SimpleFlightModesController::PX4SimpleFlightModesController(void) /// Connected to Vehicle::rcChannelsChanged signal void PX4SimpleFlightModesController::_rcChannelsChanged(int channelCount, int pwmValues[Vehicle::cMaxRcChannels]) { + _rcChannelValues.clear(); + for (int i=0; irawValue().toInt() - 1; if (flightModeChannel < 0 || flightModeChannel > channelCount) { diff --git a/src/AutoPilotPlugins/PX4/PX4SimpleFlightModesController.h b/src/AutoPilotPlugins/PX4/PX4SimpleFlightModesController.h index 1a5c8ed49..c568efc7a 100644 --- a/src/AutoPilotPlugins/PX4/PX4SimpleFlightModesController.h +++ b/src/AutoPilotPlugins/PX4/PX4SimpleFlightModesController.h @@ -42,14 +42,16 @@ class PX4SimpleFlightModesController : public FactPanelController public: PX4SimpleFlightModesController(void); - Q_PROPERTY(int activeFlightMode READ activeFlightMode NOTIFY activeFlightModeChanged) - Q_PROPERTY(int channelCount MEMBER _channelCount CONSTANT) + Q_PROPERTY(int activeFlightMode READ activeFlightMode NOTIFY activeFlightModeChanged) + Q_PROPERTY(int channelCount MEMBER _channelCount CONSTANT) + Q_PROPERTY(QVariantList rcChannelValues MEMBER _rcChannelValues NOTIFY rcChannelValuesChanged) int activeFlightMode(void) const { return _activeFlightMode; } signals: void activeFlightModeChanged(int activeFlightMode); void channelOptionEnabledChanged(void); + void rcChannelValuesChanged(void); private slots: void _rcChannelsChanged(int channelCount, int pwmValues[Vehicle::cMaxRcChannels]); @@ -57,6 +59,7 @@ private slots: private: int _activeFlightMode; int _channelCount; + QVariantList _rcChannelValues; }; #endif -- 2.22.0