FlightModesComponent.qml 46.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*=====================================================================

 QGroundControl Open Source Ground Control Station

 (c) 2009 - 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>

 This file is part of the QGROUNDCONTROL project

 QGROUNDCONTROL is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 QGROUNDCONTROL is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.

 ======================================================================*/

Don Gagne's avatar
Don Gagne committed
24 25 26 27 28 29 30 31 32
import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2

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
33
import QGroundControl.ScreenTools 1.0
Don Gagne's avatar
Don Gagne committed
34 35 36

Item {
    Loader {
Don Gagne's avatar
Don Gagne committed
37 38 39 40 41
        id:                 loader
        anchors.fill:       parent
        sourceComponent:    controller.validConfiguration ? validComponent : invalidComponent

        property FlightModesComponentController controller: FlightModesComponentController { factPanel: loader.item }
Don Gagne's avatar
Don Gagne committed
42 43 44 45 46 47 48 49 50
        property QGCPalette qgcPal: QGCPalette { colorGroupEnabled: true }
        property bool loading: true

        onLoaded: loading = false
    }

    Component {
        id: validComponent

51
        FactPanel {
Don Gagne's avatar
Don Gagne committed
52 53 54 55 56 57 58 59 60 61 62 63 64
            property Fact rc_map_throttle:      controller.getParameterFact(-1, "RC_MAP_THROTTLE")
            property Fact rc_map_yaw:           controller.getParameterFact(-1, "RC_MAP_YAW")
            property Fact rc_map_pitch:         controller.getParameterFact(-1, "RC_MAP_PITCH")
            property Fact rc_map_roll:          controller.getParameterFact(-1, "RC_MAP_ROLL")
            property Fact rc_map_flaps:         controller.getParameterFact(-1, "RC_MAP_FLAPS")
            property Fact rc_map_aux1:          controller.getParameterFact(-1, "RC_MAP_AUX1")
            property Fact rc_map_aux2:          controller.getParameterFact(-1, "RC_MAP_AUX2")

            property Fact rc_map_mode_sw:       controller.getParameterFact(-1, "RC_MAP_MODE_SW")
            property Fact rc_map_posctl_sw:     controller.getParameterFact(-1, "RC_MAP_POSCTL_SW")
            property Fact rc_map_return_sw:     controller.getParameterFact(-1, "RC_MAP_RETURN_SW")
            property Fact rc_map_offboard_sw:   controller.getParameterFact(-1, "RC_MAP_OFFB_SW")
            property Fact rc_map_loiter_sw:     controller.getParameterFact(-1, "RC_MAP_LOITER_SW")
Don Gagne's avatar
Don Gagne committed
65
            property Fact rc_map_acro_sw:       controller.getParameterFact(-1, "RC_MAP_ACRO_SW")
Don Gagne's avatar
Don Gagne committed
66 67 68 69 70 71 72

            property Fact rc_assist_th:         controller.getParameterFact(-1, "RC_ASSIST_TH")
            property Fact rc_posctl_th:         controller.getParameterFact(-1, "RC_POSCTL_TH")
            property Fact rc_auto_th:           controller.getParameterFact(-1, "RC_AUTO_TH")
            property Fact rc_loiter_th:         controller.getParameterFact(-1, "RC_LOITER_TH")
            property Fact rc_return_th:         controller.getParameterFact(-1, "RC_RETURN_TH")
            property Fact rc_offboard_th:       controller.getParameterFact(-1, "RC_OFFB_TH")
Don Gagne's avatar
Don Gagne committed
73
            property Fact rc_acro_th:           controller.getParameterFact(-1, "RC_ACRO_TH")
Don Gagne's avatar
Don Gagne committed
74 75

            property Fact rc_th_user:           controller.getParameterFact(-1, "RC_TH_USER")
Don Gagne's avatar
Don Gagne committed
76 77 78 79 80 81 82 83 84 85 86 87

            property int throttleChannel:   rc_map_throttle.value
            property int yawChannel:        rc_map_yaw.value
            property int pitchChannel:      rc_map_pitch.value
            property int rollChannel:       rc_map_roll.value
            property int flapsChannel:      rc_map_flaps.value
            property int aux1Channel:       rc_map_aux1.value
            property int aux2Channel:       rc_map_aux2.value

            property int modeChannel:       rc_map_mode_sw.value
            property int posCtlChannel:     rc_map_posctl_sw.value
            property int returnChannel:     rc_map_return_sw.value
88
            property int offboardChannel:   rc_map_offboard_sw.value
Don Gagne's avatar
Don Gagne committed
89
            property int loiterChannel:     rc_map_loiter_sw.value
Don Gagne's avatar
Don Gagne committed
90
            property int acroChannel:       rc_map_acro_sw.value
Don Gagne's avatar
Don Gagne committed
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139

            property real rcThUserValue: rc_th_user.value

            readonly property int channelCount: controller.channelCount

            property bool inRedistribution: false

            readonly property int tileWidth: 150
            readonly property int tileHeight: 30

            readonly property int progressBarHeight: 200

            anchors.fill: parent

            Component {
                id: dragHandle

                Item {
                    id:     outerItem
                    width:  parent.width
                    height: parent.height

                    Column {
                        x: 4
                        y: 4
                        spacing: 3

                        Repeater {
                            model: (outerItem.height - 8) / 4
                            Rectangle {
                                color: qgcPal.text
                                width: 15
                                height: 1
                            }
                        }
                    }
                }
            }

            // This component is used to create draggable tiles for unassigned mode switches. It also
            // creates the drop area for dragging an assigned mode switch tile back to an unassigned state.
            // The following properties must be set in the Loader:
            //  tileLabel - label for tile
            //  tileParam - parameter to load from
            //  tileDragEnabled - true: this tile can be dragged
            Component {
                id: unassignedModeTileComponent

                Rectangle {
Don Gagne's avatar
Don Gagne committed
140
                    property Fact fact: controller.getParameterFact(-1, tileParam)
Don Gagne's avatar
Don Gagne committed
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
                    property bool dragEnabled: fact.value == 0

                    id:             outerRect
                    width:          tileWidth
                    height:         tileHeight
                    color:          qgcPal.windowShadeDark
                    border.width:   dragEnabled ? 1 : 0
                    border.color:   qgcPal.text

                    Drag.active:    mouseArea.drag.active
                    Drag.hotSpot.x: width / 2
                    Drag.hotSpot.y: height / 2
                    Drag.keys:      [ "unassigned"]

                    states: [
                        State {
                            when: dropArea.containsDrag
                            PropertyChanges {
                                target: outerRect
                                color: "red"
                            }
                        }
                    ]

                    Loader {
                        width: parent.width
                        height: parent.height
                        visible: dragEnabled
                        sourceComponent: dragHandle
                    }

                    QGCLabel {
                        width:                  parent.width
                        height:                 parent.height
                        text:                   tileLabel
                        enabled:                dragEnabled
                        horizontalAlignment:    Text.AlignHCenter
                        verticalAlignment:      Text.AlignVCenter
                    }

                    MouseArea {
                        id:             mouseArea
                        width:          parent.width
                        height:         parent.height
                        drag.target:    dragEnabled ? parent : null

                        onReleased: {
                            // Move tile back to original position
                            parent.x = 0; parent.y = 0;

                            // If dropped over a channel target remap switch
                            if (parent.Drag.target && parent.Drag.target.dropAllowed) {
193 194 195
                                if (!singleSwitchRequired || parent.Drag.target.unassignedChannel) {
                                    fact.value = parent.Drag.target.channel
                                }
Don Gagne's avatar
Don Gagne committed
196 197 198 199 200 201
                            }
                        }
                    }

                    DropArea {
                        // This will cause to tile to go back to unassigned if dropped here
202 203 204 205
                        readonly property int channel:      0
                        property bool dropAllowed:          true
                        property bool unassignedChannel:    true

Don Gagne's avatar
Don Gagne committed
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225

                        id:     dropArea
                        width:  parent.width
                        height: parent.height

                        keys: [ "assigned" ]
                    }
                }
            }

            // This component is used to create draggable tiles for currently assigned mode switches. The following
            // properties must be set in the Loader:
            //  tileLabel - label for tile
            //  tileVisible - visibility for tile
            //  tileDragEnabled - true: this tile can be dragged
            //  tileParam - parameter to load from
            Component {
                id: assignedModeTileComponent

                Rectangle {
Don Gagne's avatar
Don Gagne committed
226 227
                    Fact{ id: nullFact }
                    property Fact fact: tileDragEnabled ? controller.getParameterFact(-1, tileParam) : nullFact
Don Gagne's avatar
Don Gagne committed
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268

                    width:          tileWidth
                    height:         tileHeight
                    color:          qgcPal.windowShadeDark
                    border.width:   tileDragEnabled ? 1 : 0
                    border.color:   qgcPal.text
                    visible:        tileVisible

                    Drag.active:    mouseArea.drag.active
                    Drag.hotSpot.x: width / 2
                    Drag.hotSpot.y: height / 2
                    Drag.keys:      [ "assigned" ]

                    Loader {
                        width: parent.width
                        height: parent.height
                        visible: tileDragEnabled
                        sourceComponent: dragHandle
                    }

                    QGCLabel {
                        width:                  parent.width
                        height:                 parent.height
                        enabled:                tileDragEnabled
                        horizontalAlignment:    Text.AlignHCenter
                        verticalAlignment:      Text.AlignVCenter
                        text:                   tileLabel
                    }

                    MouseArea {
                        id:             mouseArea
                        width:          parent.width
                        height:         parent.height
                        drag.target:    tileDragEnabled ? parent : null

                        onReleased: {
                            // Move tile back to original position
                            parent.x = 0; parent.y = 0;

                            // If dropped over a channel target remap switch
                            if (parent.Drag.target && parent.Drag.target.dropAllowed) {
269 270 271
                                if (!singleSwitchRequired || parent.Drag.target.unassignedChannel) {
                                    fact.value = parent.Drag.target.channel
                                }
Don Gagne's avatar
Don Gagne committed
272 273 274 275 276 277 278 279
                            }
                        }
                    }
                }
            }

            onModeChannelChanged: if (!inRedistribution) redistributeThresholds()
            onReturnChannelChanged: if (!inRedistribution) redistributeThresholds()
280
            onOffboardChannelChanged: if (!inRedistribution) redistributeThresholds()
Don Gagne's avatar
Don Gagne committed
281 282
            onLoiterChannelChanged: if (!inRedistribution) redistributeThresholds()
            onPosCtlChannelChanged: if (!inRedistribution) redistributeThresholds()
Don Gagne's avatar
Don Gagne committed
283
            onAcroChannelChanged: if (!inRedistribution) redistributeThresholds()
Don Gagne's avatar
Don Gagne committed
284 285 286 287 288 289 290 291 292 293 294 295 296
            onRcThUserValue: if (!inRedistribution) redistributeThresholds()

            function redistributeThresholds() {
                if (loading || rcThUserValue != 0) {
                    // User is specifying thresholds, do not auto-calculate
                    return
                }

                if (modeChannel != 0) {
                    var positions = 3  // Manual/Assist/Auto always exist

                    var loiterOnModeSwitch = modeChannel == loiterChannel
                    var posCtlOnModeSwitch = modeChannel == posCtlChannel
Don Gagne's avatar
Don Gagne committed
297
                    var acroOnModeSwitch = modeChannel == acroChannel
Don Gagne's avatar
Don Gagne committed
298 299 300

                    positions += loiterOnModeSwitch ? 1 : 0
                    positions += posCtlOnModeSwitch ? 1 : 0
Don Gagne's avatar
Don Gagne committed
301
                    positions += acroOnModeSwitch ? 1 : 0
Don Gagne's avatar
Don Gagne committed
302 303 304 305 306 307 308

                    var increment = 1.0 / positions
                    var currentThreshold = 0.0

                    // Make sure we don't re-enter
                    inRedistribution = true

Don Gagne's avatar
Don Gagne committed
309 310 311 312 313
                    if (acroOnModeSwitch) {
                        currentThreshold += increment
                        rc_acro_th.value = currentThreshold
                    }

Don Gagne's avatar
Don Gagne committed
314 315 316 317 318 319
                    currentThreshold += increment
                    rc_assist_th.value = currentThreshold
                    if (posCtlOnModeSwitch) {
                        currentThreshold += increment
                        rc_posctl_th.value = currentThreshold
                    }
Don Gagne's avatar
Don Gagne committed
320

Don Gagne's avatar
Don Gagne committed
321 322 323 324 325 326 327 328 329 330
                    currentThreshold += increment
                    rc_auto_th.value = currentThreshold
                    if (loiterOnModeSwitch) {
                        currentThreshold += increment
                        rc_loiter_th.value = currentThreshold
                    }

                    inRedistribution = false
                }

331
                if (returnChannel != 0) {
Don Gagne's avatar
Don Gagne committed
332 333
                    inRedistribution = true

334 335 336
                    // If only two positions don't set threshold at midrange. Setting to 0.25
                    // allows for this channel to work with either two or three position switch
                    rc_return_th.value = 0.25
Don Gagne's avatar
Don Gagne committed
337 338 339 340

                    inRedistribution = false
                }

341 342 343
                if (offboardChannel != 0) {
                    inRedistribution = true

Don Gagne's avatar
Don Gagne committed
344 345
                    // If only two positions don't set threshold at midrange. Setting to 0.25
                    // allows for this channel to work with either two or three position switch
346
                    rc_offboard_th.value = 0.25
Don Gagne's avatar
Don Gagne committed
347

348 349
                    inRedistribution = false
                }
Don Gagne's avatar
Don Gagne committed
350

351
                if (loiterChannel != 0 && loiterChannel != modeChannel) {
Don Gagne's avatar
Don Gagne committed
352 353
                    inRedistribution = true

354 355 356
                    // If only two positions don't set threshold at midrange. Setting to 0.25
                    // allows for this channel to work with either two or three position switch
                    rc_loiter_th.value = 0.25
Don Gagne's avatar
Don Gagne committed
357 358 359 360 361 362 363

                    inRedistribution = false
                }

                if (posCtlChannel != 0 & posCtlChannel != modeChannel) {
                    inRedistribution = true

364 365 366
                    // If only two positions don't set threshold at midrange. Setting to 0.25
                    // allows for this channel to work with either two or three position switch
                    rc_posctl_th.value = 0.25
Don Gagne's avatar
Don Gagne committed
367 368 369

                    inRedistribution = false
                }
Don Gagne's avatar
Don Gagne committed
370 371 372 373 374 375 376 377 378 379

                if (acroChannel != 0 & acroChannel != modeChannel) {
                    inRedistribution = true

                    // If only two positions don't set threshold at midrange. Setting to 0.25
                    // allows for this channel to work with either two or three position switch
                    rc_acro_th.value = 0.25

                    inRedistribution = false
                }
Don Gagne's avatar
Don Gagne committed
380 381 382 383 384 385 386
            }

            Column {
                anchors.fill: parent

                QGCLabel {
                    text: "FLIGHT MODES CONFIG"
387
                    font.pixelSize: ScreenTools.largeFontPixelSize
Don Gagne's avatar
Don Gagne committed
388 389 390 391 392 393
                }

                Item { height: 20; width: 10 } // spacer

                QGCLabel {
                    width: parent.width
Don Gagne's avatar
Don Gagne committed
394
                    text: "The Main Mode, Loiter, PostCtl and Acro switches can be assigned to any channel which is not currently being used for attitude control. The Return and Offboard switches must be assigned to their seperate channel. " +
395 396 397
                            "All channels are displayed below. " +
                            "You can drag Flight Modes from the Flight Modes section below to a channel and drop it there. You can also drag switches assigned to a channel " +
                            "to another channel or back to the Unassigned Switches section. The Switch Display section at the very bottom will show you the results of your Flight Mode setup."
Don Gagne's avatar
Don Gagne committed
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
                    wrapMode: Text.WordWrap
                }

                Item { height: 20; width: 10 } // spacer

                QGCLabel {
                    text: "Channel Assignments"
                }
                Flow {
                    width: parent.width
                    spacing: 5

                    Repeater {
                        model: channelCount

                        Rectangle {
                            property int channel:           modelData + 1
                            property bool throttleMapped:   channel == throttleChannel
                            property bool yawMapped:        channel == yawChannel
                            property bool pitchMapped:      channel == pitchChannel
                            property bool rollMapped:       channel == rollChannel
                            property bool flapsMapped:      channel == flapsChannel
                            property bool aux1Mapped:       channel == aux1Channel
                            property bool aux2Mapped:       channel == aux2Channel

                            property bool modeMapped:       channel == modeChannel
                            property bool posCtlMapped:     channel == posCtlChannel
                            property bool returnMapped:     channel == returnChannel
426
                            property bool offboardMapped:   channel == offboardChannel
Don Gagne's avatar
Don Gagne committed
427
                            property bool loiterMapped:     channel == loiterChannel
Don Gagne's avatar
Don Gagne committed
428
                            property bool acroMapped:       channel == acroChannel
Don Gagne's avatar
Don Gagne committed
429 430

                            property bool nonFlightModeMapping: throttleMapped | yawMapped | pitchMapped | rollMapped | flapsMapped | aux1Mapped | aux2Mapped
Don Gagne's avatar
Don Gagne committed
431
                            property bool unassignedMapping: !(nonFlightModeMapping | modeMapped | posCtlMapped | returnMapped | offboardMapped | loiterMapped | acroMapped)
432
                            property bool singleSwitchMapping: returnMapped | offboardMapped
Don Gagne's avatar
Don Gagne committed
433 434 435 436 437 438 439 440 441

                            id:     channelTarget
                            width:  tileWidth
                            height: channelCol.implicitHeight

                            color:  qgcPal.windowShadeDark

                            states: [
                                State {
442
                                    when: dropArea.containsDrag && dropArea.dropAllowed && (!dropArea.drag.source.singleSwitchRequired || dropArea.unassignedChannel)
Don Gagne's avatar
Don Gagne committed
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530
                                    PropertyChanges {
                                        target: channelHeader
                                        color: "red"
                                    }
                                }
                            ]

                            Column {
                                id:         channelCol
                                spacing:    3

                                Rectangle {
                                    id: channelHeader
                                    width:  tileWidth
                                    height: tileHeight
                                    color:  qgcPal.windowShade

                                    QGCLabel {
                                        verticalAlignment:      Text.AlignVCenter
                                        horizontalAlignment:    Text.AlignHCenter
                                        text:                   "Channel " + (modelData + 1) + (nonFlightModeMapping ? ": Unavailable" : "")
                                    }
                                }
                                Loader {
                                    property string tileLabel:      "Available"
                                    property bool tileVisible:      visible
                                    property bool tileDragEnabled:  false

                                    visible:            unassignedMapping
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
                                    property string tileLabel:      "Throttle"
                                    property bool tileVisible:      visible
                                    property bool tileDragEnabled:  false

                                    visible:            throttleMapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
                                    property string tileLabel:      "Yaw"
                                    property bool tileVisible:      visible
                                    property bool tileDragEnabled:  false

                                    visible:            yawMapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
                                    property string tileLabel:      "Pitch"
                                    property bool tileVisible:      visible
                                    property bool tileDragEnabled:  false

                                    visible:            pitchMapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
                                    property string tileLabel:      "Roll"
                                    property bool tileVisible:      visible
                                    property bool tileDragEnabled:  false

                                    visible:            rollMapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
                                    property string tileLabel:      "Flaps Switch"
                                    property bool tileVisible:      visible
                                    property bool tileDragEnabled:  false

                                    visible:            flapsMapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
                                    property string tileLabel:      "Aux1 Switch"
                                    property bool tileVisible:      visible
                                    property bool tileDragEnabled:  false

                                    visible:            aux1Mapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
                                    property string tileLabel:      "Aux2 Switch"
                                    property bool tileVisible:      visible
                                    property bool tileDragEnabled:  false

                                    visible:            aux2Mapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
531 532 533 534 535
                                    property string tileLabel:          "Main Mode"
                                    property bool tileVisible:          visible
                                    property bool tileDragEnabled:      true
                                    property string tileParam:          "RC_MAP_MODE_SW"
                                    property bool singleSwitchRequired: false
Don Gagne's avatar
Don Gagne committed
536 537 538 539 540

                                    visible:            modeMapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
541 542 543 544 545
                                    property string tileLabel:          "Return"
                                    property bool tileVisible:          visible
                                    property bool tileDragEnabled:      true
                                    property string tileParam:          "RC_MAP_RETURN_SW"
                                    property bool singleSwitchRequired: true
Don Gagne's avatar
Don Gagne committed
546 547 548 549 550

                                    visible:            returnMapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565
                                    property string tileLabel:          "Offboard"
                                    property bool tileVisible:          visible
                                    property bool tileDragEnabled:      true
                                    property string tileParam:          "RC_MAP_OFFB_SW"
                                    property bool singleSwitchRequired: true

                                    visible:            offboardMapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
                                    property string tileLabel:          "Loiter"
                                    property bool tileVisible:          visible
                                    property bool tileDragEnabled:      true
                                    property string tileParam:          "RC_MAP_LOITER_SW"
                                    property bool singleSwitchRequired: false
Don Gagne's avatar
Don Gagne committed
566 567 568 569 570

                                    visible:            loiterMapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
571 572 573 574 575
                                    property string tileLabel:          "PosCtl"
                                    property bool tileVisible:          visible
                                    property bool tileDragEnabled:      true
                                    property string tileParam:          "RC_MAP_POSCTL_SW"
                                    property bool singleSwitchRequired: false
Don Gagne's avatar
Don Gagne committed
576 577 578 579

                                    visible:            posCtlMapped
                                    sourceComponent:    assignedModeTileComponent
                                }
Don Gagne's avatar
Don Gagne committed
580 581 582 583 584 585 586 587 588 589
                                Loader {
                                    property string tileLabel:          "Acro/Stabilize"
                                    property bool tileVisible:          visible
                                    property bool tileDragEnabled:      true
                                    property string tileParam:          "RC_MAP_ACRO_SW"
                                    property bool singleSwitchRequired: false

                                    visible:            acroMapped
                                    sourceComponent:    assignedModeTileComponent
                                }
Don Gagne's avatar
Don Gagne committed
590 591 592 593
                            }

                            DropArea {
                                // Drops are not allowed on channels which are mapped to non-flight mode switches
594 595
                                property bool dropAllowed: !nonFlightModeMapping && !singleSwitchMapping
                                property bool unassignedChannel: unassignedMapping
Don Gagne's avatar
Don Gagne committed
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625
                                property int channel: parent.channel

                                id:     dropArea
                                width:  parent.width
                                height: parent.height

                                keys: [ "unassigned", "assigned" ]
                            }
                        }
                    }
                }

                Item { height: 20; width: 10 } // spacer

                Row {
                    spacing: 5

                    QGCLabel {
                        text: "Flight Modes"
                    }
                    QGCLabel {
                        text: "(Mode Switch must be assigned to channel before flight is allowed)"
                        visible: rc_map_mode_sw.value == 0
                    }
                }
                Flow {
                    width: parent.width
                    spacing: 5

                    Loader {
626 627 628 629 630 631 632 633 634 635
                        property string tileLabel:          "Main Mode"
                        property string tileParam:          "RC_MAP_MODE_SW"
                        property bool singleSwitchRequired: false
                        sourceComponent:                    unassignedModeTileComponent
                    }
                    Loader {
                        property string tileLabel:          "Loiter"
                        property string tileParam:          "RC_MAP_LOITER_SW"
                        property bool singleSwitchRequired: false
                        sourceComponent:                    unassignedModeTileComponent
Don Gagne's avatar
Don Gagne committed
636 637
                    }
                    Loader {
638 639 640 641
                        property string tileLabel:          "PosCtl"
                        property string tileParam:          "RC_MAP_POSCTL_SW"
                        property bool singleSwitchRequired: false
                        sourceComponent:                    unassignedModeTileComponent
Don Gagne's avatar
Don Gagne committed
642
                    }
Don Gagne's avatar
Don Gagne committed
643 644 645 646 647 648
                    Loader {
                        property string tileLabel:          "Acro/Stabilize"
                        property string tileParam:          "RC_MAP_ACRO_SW"
                        property bool singleSwitchRequired: false
                        sourceComponent:                    unassignedModeTileComponent
                    }
Don Gagne's avatar
Don Gagne committed
649
                    Loader {
650 651 652 653
                        property string tileLabel:          "Return"
                        property string tileParam:          "RC_MAP_RETURN_SW"
                        property bool singleSwitchRequired: true
                        sourceComponent:                    unassignedModeTileComponent
Don Gagne's avatar
Don Gagne committed
654 655
                    }
                    Loader {
656 657 658 659
                        property string tileLabel:          "Offboard"
                        property string tileParam:          "RC_MAP_OFFB_SW"
                        property bool singleSwitchRequired: true
                        sourceComponent:                    unassignedModeTileComponent
Don Gagne's avatar
Don Gagne committed
660 661 662 663 664 665
                    }
                }

                Item { height: 20; width: 10 } // spacer

                FactCheckBox {
Don Gagne's avatar
Don Gagne committed
666
                    checkedValue:   0
Don Gagne's avatar
Don Gagne committed
667
                    uncheckedValue: 1
Don Gagne's avatar
Don Gagne committed
668 669
                    fact:           rc_th_user
                    text:           "Allow setup to generate the thresholds for the flight mode positions within a switch (recommended)"
Don Gagne's avatar
Don Gagne committed
670 671 672 673 674 675 676 677 678 679 680
                }

                Item { height: 20; width: 10 } // spacer

                Row {
                spacing: 20

                    QGCLabel {
                        text: "Switch Display"
                    }
                    QGCCheckBox {
Don Gagne's avatar
Don Gagne committed
681 682 683
                        checked:    controller.sendLiveRCSwitchRanges
                        text:       "Show live RC display"

Don Gagne's avatar
Don Gagne committed
684 685 686 687 688 689 690 691 692
                        onClicked: {
                            controller.sendLiveRCSwitchRanges = checked
                        }
                    }
                }

                Item { height: 20; width: 10 } // spacer

                Row {
Don Gagne's avatar
Don Gagne committed
693 694 695
                    property bool modeSwitchVisible:        modeChannel != 0
                    property bool loiterSwitchVisible:      loiterChannel != 0 && loiterChannel != modeChannel && loiterChannel != returnChannel
                    property bool posCtlSwitchVisible:      posCtlChannel != 0 && posCtlChannel != modeChannel
Don Gagne's avatar
Don Gagne committed
696
                    property bool acroSwitchVisible:        acroChannel != 0 && acroChannel != modeChannel
Don Gagne's avatar
Don Gagne committed
697 698
                    property bool returnSwitchVisible:      returnChannel != 0
                    property bool offboardSwitchVisible:    offboardChannel != 0
Don Gagne's avatar
Don Gagne committed
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768

                    width:      parent.width
                    spacing:    20

                    Column {
                        visible: parent.modeSwitchVisible

                        QGCLabel { text: "Mode Switch" }

                        Row {
                            Item {
                                height: progressBarHeight
                                width:  150

                                QGCLabel {
                                    width:                  parent.width
                                    y:                      (parent.height * (1.0 - rc_auto_th.value)) - (implicitHeight / 2)
                                    visible:                modeChannel != returnChannel && modeChannel != loiterChannel
                                    horizontalAlignment:    Text.AlignRight
                                    text:                   "Auto"
                                }

                                QGCLabel {
                                    width:                  parent.width
                                    y:                      (parent.height * (1.0 - rc_loiter_th.value)) - (implicitHeight / 2)
                                    visible:                modeChannel == loiterChannel
                                    horizontalAlignment:    Text.AlignRight
                                    text:                   "Auto: Loiter"
                                }

                                QGCLabel {
                                    width:                  parent.width
                                    y:                      (parent.height * (1.0 - rc_auto_th.value)) - (implicitHeight / 2)
                                    visible:                modeChannel == loiterChannel
                                    horizontalAlignment:    Text.AlignRight
                                    text:                   "Auto: Mission"
                                }

                                QGCLabel {
                                    width:                  parent.width
                                    y:                      (parent.height * (1.0 - rc_auto_th.value)) - (implicitHeight / 2)
                                    visible:                modeChannel == returnChannel && modeChannel != loiterChannel
                                    horizontalAlignment:    Text.AlignRight
                                    text:                   "Auto: Loiter/Mission"
                                }

                                QGCLabel {
                                    width:                  parent.width
                                    y:                      (parent.height * (1.0 - rc_assist_th.value)) - (implicitHeight / 2)
                                    visible:                modeChannel != posCtlChannel
                                    horizontalAlignment:    Text.AlignRight
                                    text:                   "Assist"
                                }

                                QGCLabel {
                                    width:                  parent.width
                                    y:                      (parent.height * (1.0 - rc_posctl_th.value)) - (implicitHeight / 2)
                                    visible:                modeChannel == posCtlChannel
                                    horizontalAlignment:    Text.AlignRight
                                    text:                   "Assist: PosCtl"
                                }

                                QGCLabel {
                                    width:                  parent.width
                                    y:                      (parent.height * (1.0 - rc_assist_th.value)) - (implicitHeight / 2)
                                    visible:                modeChannel == posCtlChannel
                                    horizontalAlignment:    Text.AlignRight
                                    text:                   "Assist: AltCtl"
                                }

Don Gagne's avatar
Don Gagne committed
769 770 771 772 773 774 775 776
                                QGCLabel {
                                    width:                  parent.width
                                    y:                      (parent.height * (1.0 - rc_acro_th.value)) - (implicitHeight / 2)
                                    visible:                modeChannel == acroChannel
                                    horizontalAlignment:    Text.AlignRight
                                    text:                   "Acro/Stabilize"
                                }

Don Gagne's avatar
Don Gagne committed
777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793
                                QGCLabel {
                                    width:              parent.width
                                    y:                  parent.height - (implicitHeight / 2)
                                    text:               "Manual"
                                    horizontalAlignment: Text.AlignRight
                                }
                            }

                            ProgressBar {
                                height:         progressBarHeight
                                orientation:    Qt.Vertical
                                value:          controller.modeSwitchLiveRange
                            }
                        }
                    }

                    Column {
794
                        visible: parent.loiterSwitchVisible
Don Gagne's avatar
Don Gagne committed
795

796
                        QGCLabel { text: "Loiter Switch" }
Don Gagne's avatar
Don Gagne committed
797 798 799 800 801 802 803 804

                        Row {
                            Item {
                                height: progressBarHeight
                                width:  150

                                QGCLabel {
                                    width:                  parent.width
805
                                    y:                      (parent.height * (1.0 - rc_loiter_th.value)) - (implicitHeight / 2)
Don Gagne's avatar
Don Gagne committed
806
                                    horizontalAlignment:    Text.AlignRight
807
                                    text:                   "Auto: Loiter"
Don Gagne's avatar
Don Gagne committed
808 809 810 811
                                }

                                QGCLabel {
                                    width:                  parent.width
812
                                    y:                      parent.height - (implicitHeight / 2)
Don Gagne's avatar
Don Gagne committed
813
                                    horizontalAlignment:    Text.AlignRight
814
                                    text:                   "Auto: Mission"
Don Gagne's avatar
Don Gagne committed
815
                                }
816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834
                            }

                            ProgressBar {
                                height:         progressBarHeight
                                orientation:    Qt.Vertical
                                value:          controller.loiterSwitchLiveRange
                            }
                        }
                    }

                    Column {
                        visible: parent.posCtlSwitchVisible

                        QGCLabel { text: "PosCtl Switch" }

                        Row {
                            Item {
                                height: progressBarHeight
                                width:  150
Don Gagne's avatar
Don Gagne committed
835 836 837

                                QGCLabel {
                                    width:                  parent.width
838
                                    y:                      (parent.height * (1.0 - rc_posctl_th.value)) - (implicitHeight / 2)
Don Gagne's avatar
Don Gagne committed
839
                                    horizontalAlignment:    Text.AlignRight
840
                                    text:                   "Assist: PosCtl"
Don Gagne's avatar
Don Gagne committed
841 842 843 844 845 846
                                }

                                QGCLabel {
                                    width:                  parent.width
                                    y:                      parent.height - (implicitHeight / 2)
                                    horizontalAlignment:    Text.AlignRight
847
                                    text:                   "Assist: AltCtl"
Don Gagne's avatar
Don Gagne committed
848 849 850 851 852 853
                                }
                            }

                            ProgressBar {
                                height:         progressBarHeight
                                orientation:    Qt.Vertical
854
                                value:          controller.posCtlSwitchLiveRange
Don Gagne's avatar
Don Gagne committed
855 856 857 858
                            }
                        }
                    }

Don Gagne's avatar
Don Gagne committed
859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891
                    Column {
                        visible: parent.acroSwitchVisible

                        QGCLabel { text: "Acro/Stabilize Switch" }

                        Row {
                            Item {
                                height: progressBarHeight
                                width:  150

                                QGCLabel {
                                    width:                  parent.width
                                    y:                      (parent.height * (1.0 - rc_acro_th.value)) - (implicitHeight / 2)
                                    horizontalAlignment:    Text.AlignRight
                                    text:                   "Acro/Stabilize"
                                }

                                QGCLabel {
                                    width:                  parent.width
                                    y:                      parent.height - (implicitHeight / 2)
                                    horizontalAlignment:    Text.AlignRight
                                    text:                   "Manual"
                                }
                            }

                            ProgressBar {
                                height:         progressBarHeight
                                orientation:    Qt.Vertical
                                value:          controller.acroSwitchLiveRange
                            }
                        }
                    }

Don Gagne's avatar
Don Gagne committed
892
                    Column {
893
                        visible: parent.returnSwitchVisible
Don Gagne's avatar
Don Gagne committed
894

895
                        QGCLabel { text: "Return Switch" }
Don Gagne's avatar
Don Gagne committed
896 897 898 899 900 901 902 903

                        Row {
                            Item {
                                height: progressBarHeight
                                width:  150

                                QGCLabel {
                                    width:                  parent.width
904
                                    y:                      (parent.height * (1.0 - rc_return_th.value)) - (implicitHeight / 2)
Don Gagne's avatar
Don Gagne committed
905
                                    horizontalAlignment:    Text.AlignRight
906
                                    text:                   "Return"
Don Gagne's avatar
Don Gagne committed
907 908 909 910 911 912
                                }

                                QGCLabel {
                                    width:                  parent.width
                                    y:                      parent.height - (implicitHeight / 2)
                                    horizontalAlignment:    Text.AlignRight
913
                                    text:                   "Return Off"
Don Gagne's avatar
Don Gagne committed
914 915 916 917 918 919
                                }
                            }

                            ProgressBar {
                                height:         progressBarHeight
                                orientation:    Qt.Vertical
920
                                value:          controller.returnSwitchLiveRange
Don Gagne's avatar
Don Gagne committed
921 922 923 924 925
                            }
                        }
                    }

                    Column {
926
                        visible: parent.offboardSwitchVisible
Don Gagne's avatar
Don Gagne committed
927

928
                        QGCLabel { text: "Offboard Switch" }
Don Gagne's avatar
Don Gagne committed
929 930 931 932 933 934 935 936

                        Row {
                            Item {
                                height: progressBarHeight
                                width:  150

                                QGCLabel {
                                    width:                  parent.width
937
                                    y:                      (parent.height * (1.0 - rc_return_th.value)) - (implicitHeight / 2)
Don Gagne's avatar
Don Gagne committed
938
                                    horizontalAlignment:    Text.AlignRight
dogmaphobic's avatar
dogmaphobic committed
939
                                    text:                   "Offboard"
Don Gagne's avatar
Don Gagne committed
940 941 942 943 944
                                }

                                QGCLabel {
                                    width:                  parent.width
                                    y:                      parent.height - (implicitHeight / 2)
945
                                    visible:                returnChannel != loiterChannel
Don Gagne's avatar
Don Gagne committed
946
                                    horizontalAlignment:    Text.AlignRight
947
                                    text:                   "Offboard Off"
Don Gagne's avatar
Don Gagne committed
948 949 950 951 952 953
                                }
                            }

                            ProgressBar {
                                height:         progressBarHeight
                                orientation:    Qt.Vertical
954
                                value:          controller.offboardSwitchLiveRange
Don Gagne's avatar
Don Gagne committed
955 956 957 958 959 960 961 962 963 964 965
                            }
                        }
                    }
                }
            }
        }
    }

    Component {
        id: invalidComponent

Don Gagne's avatar
Don Gagne committed
966
        FactPanel {
Don Gagne's avatar
Don Gagne committed
967 968 969 970 971 972 973 974
            anchors.fill: parent
            color: qgcPal.window

            Column {
                width: parent.width
                spacing: 20

                QGCLabel {
Don Gagne's avatar
Don Gagne committed
975 976
                    text:           "FLIGHT MODES CONFIG"
                    font.pixelSize: ScreenTools.largeFontPixelSize
Don Gagne's avatar
Don Gagne committed
977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994
                }

                QGCLabel {
                    width:      parent.width
                    wrapMode:   Text.WordWrap
                    text:       "There are errors in your current configuration which will need to be fixed before you can used Flight Config setup. " +
                                "You will need to change Parameters directly using Parameters Setup to remove these errors."
                }

                QGCLabel {
                    width:      parent.width
                    wrapMode:   Text.WordWrap
                    text:       controller.configurationErrors
                }
            }
        }
    }
}