PX4SimpleFlightModes.qml 9.09 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

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

24 25 26 27
    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
28

Don Gagne's avatar
Don Gagne committed
29 30
    readonly property real _flightModeComboWidth:   ScreenTools.defaultFontPixelWidth * 13
    readonly property real _channelComboWidth:      ScreenTools.defaultFontPixelWidth * 13
31

32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
    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
50 51 52 53 54 55 56
    PX4SimpleFlightModesController {
        id:         controller
    }

    QGCFlickable {
        anchors.fill:   parent
        clip:           true
Don Gagne's avatar
Don Gagne committed
57 58
        contentWidth:   column2.x + column2.width
        contentHeight:  Math.max(column1.height, column2.height)
Don Gagne's avatar
Don Gagne committed
59 60

        Column {
Don Gagne's avatar
Don Gagne committed
61
            id:         column1
Don Gagne's avatar
Don Gagne committed
62 63
            spacing:    _margins

Don Gagne's avatar
Don Gagne committed
64 65 66
            Row {
                id:         settingsRow
                spacing:    _margins
Don Gagne's avatar
Don Gagne committed
67 68

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

                    QGCLabel {
                        id:             flightModeLabel
74
                        text:           qsTr("Flight Mode Settings")
75
                        font.family:    ScreenTools.demiboldFontFamily
Don Gagne's avatar
Don Gagne committed
76 77 78 79 80 81 82 83
                    }

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

84
                        ColumnLayout {
Don Gagne's avatar
Don Gagne committed
85 86 87 88 89 90
                            id:                 flightModeColumn
                            anchors.margins:    ScreenTools.defaultFontPixelWidth
                            anchors.left:       parent.left
                            anchors.top:        parent.top
                            spacing:            ScreenTools.defaultFontPixelHeight

91 92 93
                            RowLayout {
                                Layout.fillWidth:   true
                                spacing:            _margins
Don Gagne's avatar
Don Gagne committed
94 95

                                QGCLabel {
96
                                    Layout.fillWidth:   true
Don Gagne's avatar
Don Gagne committed
97
                                    text:               qsTr("Mode channel:")
Don Gagne's avatar
Don Gagne committed
98 99 100
                                }

                                FactComboBox {
101 102 103
                                    Layout.preferredWidth:  _channelComboWidth
                                    fact:                   controller.getParameterFact(-1, "RC_MAP_FLTMODE")
                                    indexModel:             false
Don Gagne's avatar
Don Gagne committed
104 105
                                }
                            }
Don Gagne's avatar
Don Gagne committed
106

Don Gagne's avatar
Don Gagne committed
107 108
                            Repeater {
                                model:  6
Don Gagne's avatar
Don Gagne committed
109

110 111 112
                                RowLayout {
                                    Layout.fillWidth:   true
                                    spacing:            ScreenTools.defaultFontPixelWidth
Don Gagne's avatar
Don Gagne committed
113

Don Gagne's avatar
Don Gagne committed
114
                                    property int index:         modelData + 1
Don Gagne's avatar
Don Gagne committed
115

Don Gagne's avatar
Don Gagne committed
116
                                    QGCLabel {
117
                                        Layout.fillWidth:   true
118
                                        text:               qsTr("Flight Mode %1").arg(index)
Don Gagne's avatar
Don Gagne committed
119 120
                                        color:              controller.activeFlightMode == index ? "yellow" : qgcPal.text
                                    }
Don Gagne's avatar
Don Gagne committed
121

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

                Column {
Don Gagne's avatar
Don Gagne committed
134 135
                    id:         column2
                    spacing:    _margins
Don Gagne's avatar
Don Gagne committed
136 137

                    QGCLabel {
138
                        text:           qsTr("Switch Settings")
139
                        font.family:    ScreenTools.demiboldFontFamily
Don Gagne's avatar
Don Gagne committed
140 141 142
                    }

                    Rectangle {
Don Gagne's avatar
Don Gagne committed
143
                        id:     switchSettingsRect
144 145
                        width:  switchSettingsGrid.width + (_margins * 2)
                        height: switchSettingsGrid.height + ScreenTools.defaultFontPixelHeight
Don Gagne's avatar
Don Gagne committed
146 147
                        color:  qgcPal.windowShade

148 149
                        GridLayout {
                            id:                 switchSettingsGrid
Don Gagne's avatar
Don Gagne committed
150 151 152
                            anchors.margins:    ScreenTools.defaultFontPixelWidth
                            anchors.left:       parent.left
                            anchors.top:        parent.top
153 154
                            columns:            2
                            columnSpacing:      ScreenTools.defaultFontPixelWidth
Don Gagne's avatar
Don Gagne committed
155

156
                            Repeater {
157
                                id: switchRepeater
Don Gagne's avatar
Don Gagne committed
158

159 160 161
                                RowLayout {
                                    spacing:            ScreenTools.defaultFontPixelWidth
                                    Layout.fillWidth:   true
Don Gagne's avatar
Don Gagne committed
162

163 164 165 166 167 168 169 170 171 172 173 174
                                    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))
175
                                    QGCLabel {
176
                                        text:               swFact.shortDescription
177
                                        Layout.fillWidth:   true
178
                                        color:              swActive ? "yellow" : qgcPal.text
179 180 181 182
                                    }

                                    FactComboBox {
                                        Layout.preferredWidth:  _channelComboWidth
183
                                        fact:                   swFact
184 185
                                        indexModel:             false
                                    }
Don Gagne's avatar
Don Gagne committed
186 187
                                }
                            }
Don Gagne's avatar
Don Gagne committed
188 189
                        } // Column
                    } // Rectangle
Don Gagne's avatar
Don Gagne committed
190 191

                    RCChannelMonitor {
192 193
                        width:      switchSettingsRect.width
                        twoColumn:  true
Don Gagne's avatar
Don Gagne committed
194
                    }
Don Gagne's avatar
Don Gagne committed
195 196
                } // Column - Switch settings
            } // Row - Settings
Don Gagne's avatar
Don Gagne committed
197 198

            QGCButton {
Don Gagne's avatar
Don Gagne committed
199
                text: "Use Multi Channel Mode Selection"
Don Gagne's avatar
Don Gagne committed
200 201 202 203 204
                onClicked: {
                    controller.getParameterFact(-1, "RC_MAP_MODE_SW").value = 5
                    controller.getParameterFact(-1, "RC_MAP_FLTMODE").value = 0
                }
            }
205 206 207
        }
    }
}