PX4SimpleFlightModes.qml 9.33 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
Don Gagne's avatar
Don Gagne committed
9

10 11 12
import QtQuick          2.3
import QtQuick.Controls 1.2
import QtQuick.Layouts  1.2
Don Gagne's avatar
Don Gagne committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

import QGroundControl.FactSystem    1.0
import QGroundControl.FactControls  1.0
import QGroundControl.Palette       1.0
import QGroundControl.Controls      1.0
import QGroundControl.Controllers   1.0
import QGroundControl.ScreenTools   1.0

Item {
    id: root

    // The following properties must be pushed in from the Loader
    //property var qgcView      - QGCView control
    //property var qgcViewPanel - QGCViewPanel control

28 29 30 31
    property real _margins:             ScreenTools.defaultFontPixelHeight / 2
    property var  _switchNameList:      [ "ACRO", "ARM", "GEAR", "KILL", "LOITER", "OFFB", "POSCTL", "RATT", "RETURN", "STAB" ]
    property var  _switchFactList:      [ ]
    property var  _switchTHFactList:    [ ]
Don Gagne's avatar
Don Gagne committed
32

Don Gagne's avatar
Don Gagne committed
33 34
    readonly property real _flightModeComboWidth:   ScreenTools.defaultFontPixelWidth * 13
    readonly property real _channelComboWidth:      ScreenTools.defaultFontPixelWidth * 13
35

36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
    Component.onCompleted: {
        if (controller.vehicle.fixedWing) {
            _switchNameList.push("MAN")
        }
        if (controller.vehicle.vtol) {
            _switchNameList.push("TRANS")
        }
        for (var i=0; i<_switchNameList.length; i++) {
            _switchFactList.push("RC_MAP_" + _switchNameList[i] + "_SW")
            _switchTHFactList.push("RC_" + _switchNameList[i] + "_TH")
        }
        if (controller.vehicle.fixedWing) {
            _switchFactList.push("RC_MAP_FLAPS")
            _switchTHFactList.push("")
        }
        switchRepeater.model = _switchFactList
    }

Don Gagne's avatar
Don Gagne committed
54 55 56 57 58 59 60 61
    PX4SimpleFlightModesController {
        id:         controller
        factPanel:  qgcViewPanel
    }

    QGCFlickable {
        anchors.fill:   parent
        clip:           true
Don Gagne's avatar
Don Gagne committed
62 63
        contentWidth:   column2.x + column2.width
        contentHeight:  Math.max(column1.height, column2.height)
Don Gagne's avatar
Don Gagne committed
64 65

        Column {
Don Gagne's avatar
Don Gagne committed
66
            id:         column1
Don Gagne's avatar
Don Gagne committed
67 68
            spacing:    _margins

Don Gagne's avatar
Don Gagne committed
69 70 71
            Row {
                id:         settingsRow
                spacing:    _margins
Don Gagne's avatar
Don Gagne committed
72 73

                Column {
Don Gagne's avatar
Don Gagne committed
74 75 76 77 78
                    id:     flightModeSettingsColumn
                    spacing: _margins

                    QGCLabel {
                        id:             flightModeLabel
79
                        text:           qsTr("Flight Mode Settings")
80
                        font.family:    ScreenTools.demiboldFontFamily
Don Gagne's avatar
Don Gagne committed
81 82 83 84 85 86 87 88
                    }

                    Rectangle {
                        id:                 flightModeSettings
                        width:              flightModeColumn.width + (_margins * 2)
                        height:             flightModeColumn.height + ScreenTools.defaultFontPixelHeight
                        color:              qgcPal.windowShade

89
                        ColumnLayout {
Don Gagne's avatar
Don Gagne committed
90 91 92 93 94 95
                            id:                 flightModeColumn
                            anchors.margins:    ScreenTools.defaultFontPixelWidth
                            anchors.left:       parent.left
                            anchors.top:        parent.top
                            spacing:            ScreenTools.defaultFontPixelHeight

96 97 98
                            RowLayout {
                                Layout.fillWidth:   true
                                spacing:            _margins
Don Gagne's avatar
Don Gagne committed
99 100

                                QGCLabel {
101
                                    Layout.fillWidth:   true
Don Gagne's avatar
Don Gagne committed
102
                                    text:               qsTr("Mode channel:")
Don Gagne's avatar
Don Gagne committed
103 104 105
                                }

                                FactComboBox {
106 107 108
                                    Layout.preferredWidth:  _channelComboWidth
                                    fact:                   controller.getParameterFact(-1, "RC_MAP_FLTMODE")
                                    indexModel:             false
Don Gagne's avatar
Don Gagne committed
109 110
                                }
                            }
Don Gagne's avatar
Don Gagne committed
111

Don Gagne's avatar
Don Gagne committed
112 113
                            Repeater {
                                model:  6
Don Gagne's avatar
Don Gagne committed
114

115 116 117
                                RowLayout {
                                    Layout.fillWidth:   true
                                    spacing:            ScreenTools.defaultFontPixelWidth
Don Gagne's avatar
Don Gagne committed
118

Don Gagne's avatar
Don Gagne committed
119
                                    property int index:         modelData + 1
Don Gagne's avatar
Don Gagne committed
120

Don Gagne's avatar
Don Gagne committed
121
                                    QGCLabel {
122
                                        Layout.fillWidth:   true
123
                                        text:               qsTr("Flight Mode %1").arg(index)
Don Gagne's avatar
Don Gagne committed
124 125
                                        color:              controller.activeFlightMode == index ? "yellow" : qgcPal.text
                                    }
Don Gagne's avatar
Don Gagne committed
126

Don Gagne's avatar
Don Gagne committed
127
                                    FactComboBox {
128 129 130
                                        Layout.preferredWidth:  _channelComboWidth
                                        fact:                   controller.getParameterFact(-1, "COM_FLTMODE" + index)
                                        indexModel:             false
Don Gagne's avatar
Don Gagne committed
131 132 133 134 135 136 137 138
                                    }
                                }
                            } // Repeater - Flight Modes
                        } // Column - Flight Modes
                    } // Rectangle - Flight Modes
                } // Column - Flight mode settings

                Column {
Don Gagne's avatar
Don Gagne committed
139 140
                    id:         column2
                    spacing:    _margins
Don Gagne's avatar
Don Gagne committed
141 142

                    QGCLabel {
143
                        text:           qsTr("Switch Settings")
144
                        font.family:    ScreenTools.demiboldFontFamily
Don Gagne's avatar
Don Gagne committed
145 146 147
                    }

                    Rectangle {
Don Gagne's avatar
Don Gagne committed
148
                        id:     switchSettingsRect
149 150
                        width:  switchSettingsGrid.width + (_margins * 2)
                        height: switchSettingsGrid.height + ScreenTools.defaultFontPixelHeight
Don Gagne's avatar
Don Gagne committed
151 152
                        color:  qgcPal.windowShade

153 154
                        GridLayout {
                            id:                 switchSettingsGrid
Don Gagne's avatar
Don Gagne committed
155 156 157
                            anchors.margins:    ScreenTools.defaultFontPixelWidth
                            anchors.left:       parent.left
                            anchors.top:        parent.top
158 159
                            columns:            2
                            columnSpacing:      ScreenTools.defaultFontPixelWidth
Don Gagne's avatar
Don Gagne committed
160

161
                            Repeater {
162
                                id: switchRepeater
Don Gagne's avatar
Don Gagne committed
163

164 165 166
                                RowLayout {
                                    spacing:            ScreenTools.defaultFontPixelWidth
                                    Layout.fillWidth:   true
Don Gagne's avatar
Don Gagne committed
167

168 169 170 171 172 173 174 175 176 177 178 179
                                    property string thFactName:     _switchTHFactList[index]
                                    property bool   thFactExists:   thFactName == ""
                                    property Fact   swFact:         controller.getParameterFact(-1, modelData)
                                    property Fact   thFact:         thFactExists ? controller.getParameterFact(-1, thFactName) : null
                                    property real   thValue:        thFactExists ? thFact.rawValue : 0.5
                                    property real   thPWM:          1000 + (1000 * thValue)
                                    property int    swChannel:      swFact.rawValue - 1
                                    property bool   swActive:       swChannel < 0 ?
                                                                        false :
                                                                        (thValue >= 0 ?
                                                                             (controller.rcChannelValues[swChannel] > thPWM) :
                                                                             (controller.rcChannelValues[swChannel] <= thPWM))
180
                                    QGCLabel {
181
                                        text:               swFact.shortDescription
182
                                        Layout.fillWidth:   true
183
                                        color:              swActive ? "yellow" : qgcPal.text
184 185 186 187
                                    }

                                    FactComboBox {
                                        Layout.preferredWidth:  _channelComboWidth
188
                                        fact:                   swFact
189 190
                                        indexModel:             false
                                    }
Don Gagne's avatar
Don Gagne committed
191 192
                                }
                            }
Don Gagne's avatar
Don Gagne committed
193 194
                        } // Column
                    } // Rectangle
Don Gagne's avatar
Don Gagne committed
195 196

                    RCChannelMonitor {
197 198
                        width:      switchSettingsRect.width
                        twoColumn:  true
Don Gagne's avatar
Don Gagne committed
199
                    }
Don Gagne's avatar
Don Gagne committed
200 201
                } // Column - Switch settings
            } // Row - Settings
Don Gagne's avatar
Don Gagne committed
202 203

            QGCButton {
Don Gagne's avatar
Don Gagne committed
204
                text: "Use Multi Channel Mode Selection"
Don Gagne's avatar
Don Gagne committed
205 206 207 208 209 210 211 212
                onClicked: {
                    controller.getParameterFact(-1, "RC_MAP_MODE_SW").value = 5
                    controller.getParameterFact(-1, "RC_MAP_FLTMODE").value = 0
                }
            }
        } // Column
    } // QGCFlickable
} // QGCView