JoystickConfig.qml 37.5 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.
 *
 ****************************************************************************/
9 10


11 12
import QtQuick          2.3
import QtQuick.Controls 1.2
13 14
import QtQuick.Dialogs  1.2

15
import QGroundControl               1.0
16 17 18 19
import QGroundControl.Palette       1.0
import QGroundControl.Controls      1.0
import QGroundControl.ScreenTools   1.0
import QGroundControl.Controllers   1.0
20
import QGroundControl.FactSystem    1.0
21
import QGroundControl.FactControls  1.0
22 23

/// Joystick Config
Don Gagne's avatar
Don Gagne committed
24 25 26 27 28 29
SetupPage {
    id:                 joystickPage
    pageComponent:      pageComponent
    pageName:           qsTr("Joystick")
    pageDescription:    qsTr("Joystick Setup is used to configure a calibrate joysticks.")

dheideman's avatar
dheideman committed
30 31
    readonly property real _maxButtons: 16

Jacob Walser's avatar
Jacob Walser committed
32 33 34 35 36 37 38 39 40 41
    Connections {
        target: joystickManager
        onAvailableJoysticksChanged: {
            if( joystickManager.joysticks.length == 0 ) {
                summaryButton.checked = true
                setupView.showSummaryPanel()
            }
        }
    }

Don Gagne's avatar
Don Gagne committed
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
    Component {
        id: pageComponent

        Item {
            width:  availableWidth
            height: Math.max(leftColumn.height, rightColumn.height)

            property bool controllerCompleted:      false
            property bool controllerAndViewReady:   false

            readonly property real labelToMonitorMargin: defaultTextWidth * 3

            property var _activeVehicle:    QGroundControl.multiVehicleManager.activeVehicle
            property var _activeJoystick:   joystickManager.activeJoystick

            JoystickConfigController {
                id:             controller
                factPanel:      joystickPage.viewPanel
                statusText:     statusText
                cancelButton:   cancelButton
                nextButton:     nextButton
                skipButton:     skipButton

                Component.onCompleted: {
                    controllerCompleted = true
                    if (joystickPage.completedSignalled) {
                        controllerAndViewReady = true
                        controller.start()
                    }
                }
72 73
            }

Don Gagne's avatar
Don Gagne committed
74 75 76 77 78 79
            Component.onCompleted: {
                if (controllerCompleted) {
                    controllerAndViewReady = true
                    controller.start()
                }
            }
80

Don Gagne's avatar
Don Gagne committed
81 82 83
            // Live axis monitor control component
            Component {
                id: axisMonitorDisplayComponent
84

Don Gagne's avatar
Don Gagne committed
85 86
                Item {
                    property int axisValue: 0
Gregory Dymarek's avatar
Gregory Dymarek committed
87
                    property int deadbandValue: 0
88

Don Gagne's avatar
Don Gagne committed
89
                    property color          __barColor:             qgcPal.windowShade
90

Don Gagne's avatar
Don Gagne committed
91 92 93 94 95 96 97 98
                    // Bar
                    Rectangle {
                        id:                     bar
                        anchors.verticalCenter: parent.verticalCenter
                        width:                  parent.width
                        height:                 parent.height / 2
                        color:                  __barColor
                    }
99

Gregory Dymarek's avatar
Gregory Dymarek committed
100 101 102 103 104 105 106 107
                    // Deadband
                    Rectangle {
                        id:                     deadbandBar
                        anchors.verticalCenter: parent.verticalCenter
                        x:                      _deadbandPosition
                        width:                  _deadbandWidth
                        height:                 parent.height / 2
                        color:                  "#8c161a"
108
                        visible:                controller.deadbandToggle
Gregory Dymarek's avatar
Gregory Dymarek committed
109 110 111 112 113 114

                        property real _percentDeadband:    ((2 * deadbandValue) / (32768.0 * 2))
                        property real _deadbandWidth:   parent.width * _percentDeadband
                        property real _deadbandPosition:   (parent.width - _deadbandWidth) / 2
                    }

Don Gagne's avatar
Don Gagne committed
115 116 117 118 119 120 121
                    // Center point
                    Rectangle {
                        anchors.horizontalCenter:   parent.horizontalCenter
                        width:                      defaultTextWidth / 2
                        height:                     parent.height
                        color:                      qgcPal.window
                    }
122

Don Gagne's avatar
Don Gagne committed
123 124 125 126 127 128 129 130 131 132 133 134 135
                    // Indicator
                    Rectangle {
                        anchors.verticalCenter: parent.verticalCenter
                        width:                  parent.height * 0.75
                        height:                 width
                        x:                      (reversed ? (parent.width - _indicatorPosition) : _indicatorPosition) - (width / 2)
                        radius:                 width / 2
                        color:                  qgcPal.text
                        visible:                mapped

                        property real _percentAxisValue:    ((axisValue + 32768.0) / (32768.0 * 2))
                        property real _indicatorPosition:   parent.width * _percentAxisValue
                    }
136

Don Gagne's avatar
Don Gagne committed
137 138 139 140 141 142 143
                    QGCLabel {
                        anchors.fill:           parent
                        horizontalAlignment:    Text.AlignHCenter
                        verticalAlignment:      Text.AlignVCenter
                        text:                   qsTr("Not Mapped")
                        visible:                !mapped
                    }
144

Don Gagne's avatar
Don Gagne committed
145 146 147 148 149 150 151 152
                    ColorAnimation {
                        id:         barAnimation
                        target:     bar
                        property:   "color"
                        from:       "yellow"
                        to:         __barColor
                        duration:   1500
                    }
153

Gregory Dymarek's avatar
Gregory Dymarek committed
154

Don Gagne's avatar
Don Gagne committed
155
                    // Axis value debugger
Gregory Dymarek's avatar
Gregory Dymarek committed
156
                    /*
Don Gagne's avatar
Don Gagne committed
157 158 159 160 161
                    QGCLabel {
                        anchors.fill: parent
                        text: axisValue
                    }
                    */
Gregory Dymarek's avatar
Gregory Dymarek committed
162

163
                }
Don Gagne's avatar
Don Gagne committed
164
            } // Component - axisMonitorDisplayComponent
165

Don Gagne's avatar
Don Gagne committed
166 167 168 169 170 171 172 173 174
            // Main view Qml starts here

            // Left side column
            Column {
                id:                     leftColumn
                anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
                anchors.left:           parent.left
                anchors.right:          rightColumn.left
                spacing:                10
175

Don Gagne's avatar
Don Gagne committed
176 177 178 179
                // Attitude Controls
                Column {
                    width:      parent.width
                    spacing:    5
180

Don Gagne's avatar
Don Gagne committed
181
                    QGCLabel { text: qsTr("Attitude Controls") }
182

Don Gagne's avatar
Don Gagne committed
183 184 185
                    Item {
                        width:  parent.width
                        height: defaultTextHeight * 2
186

Don Gagne's avatar
Don Gagne committed
187 188 189
                        QGCLabel {
                            id:     rollLabel
                            width:  defaultTextWidth * 10
190
                            text:   _activeVehicle.sub ? qsTr("Lateral") : qsTr("Roll")
Don Gagne's avatar
Don Gagne committed
191
                        }
192

Don Gagne's avatar
Don Gagne committed
193 194 195 196 197 198 199 200 201 202 203 204
                        Loader {
                            id:                 rollLoader
                            anchors.left:       rollLabel.right
                            anchors.right:      parent.right
                            height:             ScreenTools.defaultFontPixelHeight
                            width:              100
                            sourceComponent:    axisMonitorDisplayComponent

                            property real defaultTextWidth: ScreenTools.defaultFontPixelWidth
                            property bool mapped:           controller.rollAxisMapped
                            property bool reversed:         controller.rollAxisReversed
                        }
205

206 207 208 209 210
                        Connections {
                            target: _activeJoystick

                            onManualControl: rollLoader.item.axisValue = roll*32768.0
                        }
211 212
                    }

Don Gagne's avatar
Don Gagne committed
213 214 215
                    Item {
                        width:  parent.width
                        height: defaultTextHeight * 2
216

Don Gagne's avatar
Don Gagne committed
217 218 219
                        QGCLabel {
                            id:     pitchLabel
                            width:  defaultTextWidth * 10
220
                            text:   _activeVehicle.sub ? qsTr("Forward") : qsTr("Pitch")
Don Gagne's avatar
Don Gagne committed
221
                        }
222

Don Gagne's avatar
Don Gagne committed
223 224 225 226 227 228 229 230 231 232 233 234
                        Loader {
                            id:                 pitchLoader
                            anchors.left:       pitchLabel.right
                            anchors.right:      parent.right
                            height:             ScreenTools.defaultFontPixelHeight
                            width:              100
                            sourceComponent:    axisMonitorDisplayComponent

                            property real defaultTextWidth: ScreenTools.defaultFontPixelWidth
                            property bool mapped:           controller.pitchAxisMapped
                            property bool reversed:         controller.pitchAxisReversed
                        }
235

236 237 238 239 240
                        Connections {
                            target: _activeJoystick

                            onManualControl: pitchLoader.item.axisValue = pitch*32768.0
                        }
241 242
                    }

Don Gagne's avatar
Don Gagne committed
243 244 245
                    Item {
                        width:  parent.width
                        height: defaultTextHeight * 2
246

Don Gagne's avatar
Don Gagne committed
247 248 249 250 251
                        QGCLabel {
                            id:     yawLabel
                            width:  defaultTextWidth * 10
                            text:   qsTr("Yaw")
                        }
252

Don Gagne's avatar
Don Gagne committed
253 254 255 256 257 258 259 260 261 262 263 264
                        Loader {
                            id:                 yawLoader
                            anchors.left:       yawLabel.right
                            anchors.right:      parent.right
                            height:             ScreenTools.defaultFontPixelHeight
                            width:              100
                            sourceComponent:    axisMonitorDisplayComponent

                            property real defaultTextWidth: ScreenTools.defaultFontPixelWidth
                            property bool mapped:           controller.yawAxisMapped
                            property bool reversed:         controller.yawAxisReversed
                        }
265

266 267 268 269 270
                        Connections {
                            target: _activeJoystick

                            onManualControl: yawLoader.item.axisValue = yaw*32768.0
                        }
271 272
                    }

Don Gagne's avatar
Don Gagne committed
273 274 275
                    Item {
                        width:  parent.width
                        height: defaultTextHeight * 2
276

Don Gagne's avatar
Don Gagne committed
277 278 279 280 281
                        QGCLabel {
                            id:     throttleLabel
                            width:  defaultTextWidth * 10
                            text:   qsTr("Throttle")
                        }
282

Don Gagne's avatar
Don Gagne committed
283 284 285 286 287 288 289 290 291 292 293 294
                        Loader {
                            id:                 throttleLoader
                            anchors.left:       throttleLabel.right
                            anchors.right:      parent.right
                            height:             ScreenTools.defaultFontPixelHeight
                            width:              100
                            sourceComponent:    axisMonitorDisplayComponent

                            property real defaultTextWidth: ScreenTools.defaultFontPixelWidth
                            property bool mapped:           controller.throttleAxisMapped
                            property bool reversed:         controller.throttleAxisReversed
                        }
295

296 297 298
                        Connections {
                            target: _activeJoystick

299
                            onManualControl: throttleLoader.item.axisValue = _activeJoystick.negativeThrust ? -throttle*32768.0 : (-2*throttle+1)*32768.0
300
                        }
301
                    }
Don Gagne's avatar
Don Gagne committed
302
                } // Column - Attitude Control labels
303

Don Gagne's avatar
Don Gagne committed
304 305 306
                // Command Buttons
                Row {
                    spacing: 10
307
                    visible: _activeJoystick.requiresCalibration
Don Gagne's avatar
Don Gagne committed
308 309 310 311

                    QGCButton {
                        id:     skipButton
                        text:   qsTr("Skip")
312

Don Gagne's avatar
Don Gagne committed
313
                        onClicked: controller.skipButtonClicked()
314 315
                    }

Don Gagne's avatar
Don Gagne committed
316 317 318
                    QGCButton {
                        id:     cancelButton
                        text:   qsTr("Cancel")
319

Don Gagne's avatar
Don Gagne committed
320 321
                        onClicked: controller.cancelButtonClicked()
                    }
322

Don Gagne's avatar
Don Gagne committed
323 324 325 326
                    QGCButton {
                        id:         nextButton
                        primary:    true
                        text:       qsTr("Calibrate")
327

Don Gagne's avatar
Don Gagne committed
328 329 330
                        onClicked: controller.nextButtonClicked()
                    }
                } // Row - Buttons
331

Don Gagne's avatar
Don Gagne committed
332 333 334 335 336
                // Status Text
                QGCLabel {
                    id:         statusText
                    width:      parent.width
                    wrapMode:   Text.WordWrap
337 338
                }

Don Gagne's avatar
Don Gagne committed
339 340 341 342 343
                Rectangle {
                    width:          parent.width
                    height:         1
                    border.color:   qgcPal.text
                    border.width:   1
344 345
                }

Don Gagne's avatar
Don Gagne committed
346 347 348 349
                // Settings
                Row {
                    width:      parent.width
                    spacing:    ScreenTools.defaultFontPixelWidth
350

Don Gagne's avatar
Don Gagne committed
351
                    // Left column settings
352
                    Column {
Don Gagne's avatar
Don Gagne committed
353
                        width:      parent.width / 2
354 355
                        spacing:    ScreenTools.defaultFontPixelHeight

Don Gagne's avatar
Don Gagne committed
356
                        QGCLabel { text: qsTr("Additional Joystick settings:") }
357

Don Gagne's avatar
Don Gagne committed
358 359 360
                        Column {
                            width:      parent.width
                            spacing:    ScreenTools.defaultFontPixelHeight
361 362


Don Gagne's avatar
Don Gagne committed
363
                            QGCCheckBox {
Jacob Walser's avatar
Jacob Walser committed
364
                                id:         enabledCheckBox
365 366
                                enabled:    _activeJoystick ? _activeJoystick.calibrated : false
                                text:       _activeJoystick ? _activeJoystick.calibrated ? qsTr("Enable joystick input") : qsTr("Enable not allowed (Calibrate First)") : ""
Don Gagne's avatar
Don Gagne committed
367
                                checked:    _activeVehicle.joystickEnabled
368

Don Gagne's avatar
Don Gagne committed
369
                                onClicked:  _activeVehicle.joystickEnabled = checked
Jacob Walser's avatar
Jacob Walser committed
370 371 372 373 374

                                Connections {
                                    target: joystickManager

                                    onActiveJoystickChanged: {
375
                                        if(_activeJoystick) {
Jacob Walser's avatar
Jacob Walser committed
376
                                            enabledCheckBox.checked = Qt.binding(function() { return _activeJoystick.calibrated && _activeVehicle.joystickEnabled })
377
                                        }
Jacob Walser's avatar
Jacob Walser committed
378 379
                                    }
                                }
380 381
                            }

Don Gagne's avatar
Don Gagne committed
382 383 384
                            Row {
                                width:      parent.width
                                spacing:    ScreenTools.defaultFontPixelWidth
385

Don Gagne's avatar
Don Gagne committed
386 387 388 389 390
                                QGCLabel {
                                    id:                 activeJoystickLabel
                                    anchors.baseline:   joystickCombo.baseline
                                    text:               qsTr("Active joystick:")
                                }
391

Don Gagne's avatar
Don Gagne committed
392 393 394 395 396 397 398 399 400 401 402 403 404 405
                                QGCComboBox {
                                    id:                 joystickCombo
                                    width:              parent.width - activeJoystickLabel.width - parent.spacing
                                    model:              joystickManager.joystickNames

                                    onActivated: joystickManager.activeJoystickName = textAt(index)

                                    Component.onCompleted: {
                                        var index = joystickCombo.find(joystickManager.activeJoystickName)
                                        if (index == -1) {
                                            console.warn(qsTr("Active joystick name not in combo"), joystickManager.activeJoystickName)
                                        } else {
                                            joystickCombo.currentIndex = index
                                        }
406
                                    }
Jacob Walser's avatar
Jacob Walser committed
407 408 409 410 411

                                    Connections {
                                        target: joystickManager
                                        onAvailableJoysticksChanged: {
                                            var index = joystickCombo.find(joystickManager.activeJoystickName)
412
                                            if (index >= 0) {
Jacob Walser's avatar
Jacob Walser committed
413 414 415 416
                                                joystickCombo.currentIndex = index
                                            }
                                        }
                                    }
417
                                }
418 419
                            }

Don Gagne's avatar
Don Gagne committed
420 421 422
                            Column {
                                spacing: ScreenTools.defaultFontPixelHeight / 3
                                visible: _activeVehicle.supportsThrottleModeCenterZero
423

Don Gagne's avatar
Don Gagne committed
424
                                ExclusiveGroup { id: throttleModeExclusiveGroup }
425

Don Gagne's avatar
Don Gagne committed
426 427 428
                                QGCRadioButton {
                                    exclusiveGroup: throttleModeExclusiveGroup
                                    text:           qsTr("Center stick is zero throttle")
429
                                    checked:        _activeJoystick ? _activeJoystick.throttleMode == 0 : false
430

Don Gagne's avatar
Don Gagne committed
431 432
                                    onClicked: _activeJoystick.throttleMode = 0
                                }
433

434
                                Row {
Gregory Dymarek's avatar
Gregory Dymarek committed
435
                                    x:          20
436 437
                                    width:      parent.width
                                    spacing:    ScreenTools.defaultFontPixelWidth
438
                                    visible:    _activeJoystick ? _activeJoystick.throttleMode == 0 : false
439 440 441

                                    QGCCheckBox {
                                        id:         accumulator
442
                                        checked:    _activeJoystick ? _activeJoystick.accumulator : false
Gregory Dymarek's avatar
Gregory Dymarek committed
443
                                        text:       qsTr("Spring loaded throttle smoothing")
444 445 446 447 448

                                        onClicked:  _activeJoystick.accumulator = checked
                                    }
                                }

Don Gagne's avatar
Don Gagne committed
449 450 451
                                QGCRadioButton {
                                    exclusiveGroup: throttleModeExclusiveGroup
                                    text:           qsTr("Full down stick is zero throttle")
452
                                    checked:        _activeJoystick ? _activeJoystick.throttleMode == 1 : false
453

Don Gagne's avatar
Don Gagne committed
454 455
                                    onClicked: _activeJoystick.throttleMode = 1
                                }
456 457

                                QGCCheckBox {
458
                                    visible:        _activeVehicle.supportsNegativeThrust
459 460 461 462 463 464
                                    id:             negativeThrust
                                    text:           qsTr("Allow negative Thrust")
                                    checked:        _activeJoystick ? _activeJoystick.negativeThrust : false

                                    onClicked: _activeJoystick.negativeThrust = checked
                                }
465 466
                            }

Don Gagne's avatar
Don Gagne committed
467 468
                            Column {
                                spacing: ScreenTools.defaultFontPixelHeight / 3
469

470 471 472 473 474 475 476 477 478 479 480
                                QGCLabel {
                                    id:                 expoSliderLabel
                                    text:               qsTr("Exponential:")
                                }

                                Row {
                                    QGCSlider {
                                        id: expoSlider
                                        minimumValue: 0
                                        maximumValue: 0.75

nanthony21's avatar
nanthony21 committed
481 482
                                        Component.onCompleted: value=-_activeJoystick.exponential
                                        onValueChanged: _activeJoystick.exponential=-value
483 484 485 486 487
                                     }

                                    QGCLabel {
                                        id:     expoSliderIndicator
                                        text:   expoSlider.value.toFixed(2)
488
                                    }
Don Gagne's avatar
Don Gagne committed
489
                                }
490 491
                            }

Don Gagne's avatar
Don Gagne committed
492 493 494 495
                            QGCCheckBox {
                                id:         advancedSettings
                                checked:    _activeVehicle.joystickMode != 0
                                text:       qsTr("Advanced settings (careful!)")
496

Don Gagne's avatar
Don Gagne committed
497 498 499 500
                                onClicked: {
                                    if (!checked) {
                                        _activeVehicle.joystickMode = 0
                                    }
501 502 503
                                }
                            }

Don Gagne's avatar
Don Gagne committed
504 505 506 507 508 509 510 511 512 513
                            Row {
                                width:      parent.width
                                spacing:    ScreenTools.defaultFontPixelWidth
                                visible:    advancedSettings.checked

                                QGCLabel {
                                    id:                 joystickModeLabel
                                    anchors.baseline:   joystickModeCombo.baseline
                                    text:               qsTr("Joystick mode:")
                                }
514

Don Gagne's avatar
Don Gagne committed
515 516 517 518 519
                                QGCComboBox {
                                    id:             joystickModeCombo
                                    currentIndex:   _activeVehicle.joystickMode
                                    width:          ScreenTools.defaultFontPixelWidth * 20
                                    model:          _activeVehicle.joystickModes
520

Don Gagne's avatar
Don Gagne committed
521 522
                                    onActivated: _activeVehicle.joystickMode = index
                                }
523
                            }
524 525 526 527 528 529 530 531 532 533 534 535 536 537

                            Row {
                                width:      parent.width
                                spacing:    ScreenTools.defaultFontPixelWidth
                                visible:    advancedSettings.checked

                                QGCCheckBox {
                                    id:         deadband
                                    checked:    controller.deadbandToggle
                                    text:       qsTr("Deadbands")

                                    onClicked:  controller.deadbandToggle = checked
                                }
                            }
538
                        }
Don Gagne's avatar
Don Gagne committed
539
                    } // Column - left column
540

Don Gagne's avatar
Don Gagne committed
541 542 543 544
                    // Right column settings
                    Column {
                        width:      parent.width / 2
                        spacing:    ScreenTools.defaultFontPixelHeight
545

Don Gagne's avatar
Don Gagne committed
546 547
                        Connections {
                            target: _activeJoystick
548

Don Gagne's avatar
Don Gagne committed
549 550 551 552 553 554 555
                            onRawButtonPressedChanged: {
                                if (buttonActionRepeater.itemAt(index)) {
                                    buttonActionRepeater.itemAt(index).pressed = pressed
                                }
                                if (jsButtonActionRepeater.itemAt(index)) {
                                    jsButtonActionRepeater.itemAt(index).pressed = pressed
                                }
556
                            }
557 558
                        }

Don Gagne's avatar
Don Gagne committed
559
                        QGCLabel { text: qsTr("Button actions:") }
560

Don Gagne's avatar
Don Gagne committed
561 562 563
                        Column {
                            width:      parent.width
                            spacing:    ScreenTools.defaultFontPixelHeight / 3
564

Don Gagne's avatar
Don Gagne committed
565 566 567
                            QGCLabel {
                                visible: _activeVehicle.manualControlReservedButtonCount != 0
                                text: qsTr("Buttons 0-%1 reserved for firmware use").arg(reservedButtonCount)
568

Don Gagne's avatar
Don Gagne committed
569 570
                                property int reservedButtonCount: _activeVehicle.manualControlReservedButtonCount == -1 ? _activeJoystick.totalButtonCount : _activeVehicle.manualControlReservedButtonCount
                            }
571

Don Gagne's avatar
Don Gagne committed
572 573
                            Repeater {
                                id:     buttonActionRepeater
dheideman's avatar
dheideman committed
574
                                model:  _activeJoystick ? Math.min(_activeJoystick.totalButtonCount, _maxButtons) : 0
575

Don Gagne's avatar
Don Gagne committed
576 577 578
                                Row {
                                    spacing: ScreenTools.defaultFontPixelWidth
                                    visible: (_activeVehicle.manualControlReservedButtonCount == -1 ? false : modelData >= _activeVehicle.manualControlReservedButtonCount) && !_activeVehicle.supportsJSButton
579

Don Gagne's avatar
Don Gagne committed
580
                                    property bool pressed
581

Don Gagne's avatar
Don Gagne committed
582 583
                                    QGCCheckBox {
                                        anchors.verticalCenter:     parent.verticalCenter
584
                                        checked:                    _activeJoystick ? _activeJoystick.buttonActions[modelData] != "" : false
585

Don Gagne's avatar
Don Gagne committed
586 587
                                        onClicked: _activeJoystick.setButtonAction(modelData, checked ? buttonActionCombo.textAt(buttonActionCombo.currentIndex) : "")
                                    }
588

Don Gagne's avatar
Don Gagne committed
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604
                                    Rectangle {
                                        anchors.verticalCenter:     parent.verticalCenter
                                        width:                      ScreenTools.defaultFontPixelHeight * 1.5
                                        height:                     width
                                        border.width:               1
                                        border.color:               qgcPal.text
                                        color:                      pressed ? qgcPal.buttonHighlight : qgcPal.button


                                        QGCLabel {
                                            anchors.fill:           parent
                                            color:                  pressed ? qgcPal.buttonHighlightText : qgcPal.buttonText
                                            horizontalAlignment:    Text.AlignHCenter
                                            verticalAlignment:      Text.AlignVCenter
                                            text:                   modelData
                                        }
605 606
                                    }

Don Gagne's avatar
Don Gagne committed
607 608 609
                                    QGCComboBox {
                                        id:             buttonActionCombo
                                        width:          ScreenTools.defaultFontPixelWidth * 20
610
                                        model:          _activeJoystick ? _activeJoystick.actions : 0
611

Don Gagne's avatar
Don Gagne committed
612 613 614
                                        onActivated:            _activeJoystick.setButtonAction(modelData, textAt(index))
                                        Component.onCompleted:  currentIndex = find(_activeJoystick.buttonActions[modelData])
                                    }
615
                                }
Don Gagne's avatar
Don Gagne committed
616
                            } // Repeater
617 618 619

                            Row {
                                spacing: ScreenTools.defaultFontPixelWidth
620
                                visible: _activeVehicle.supportsJSButton
621

Don Gagne's avatar
Don Gagne committed
622 623 624 625
                                QGCLabel {
                                    horizontalAlignment:    Text.AlignHCenter
                                    width:                  ScreenTools.defaultFontPixelHeight * 1.5
                                    text:                   qsTr("#")
626 627
                                }

Don Gagne's avatar
Don Gagne committed
628 629 630
                                QGCLabel {
                                    width:                  ScreenTools.defaultFontPixelWidth * 15
                                    text:                   qsTr("Function: ")
631 632
                                }

Don Gagne's avatar
Don Gagne committed
633 634 635
                                QGCLabel {
                                    width:                  ScreenTools.defaultFontPixelWidth * 15
                                    text:                   qsTr("Shift Function: ")
636 637
                                }
                            } // Row
638

Don Gagne's avatar
Don Gagne committed
639 640
                            Repeater {
                                id:     jsButtonActionRepeater
dheideman's avatar
dheideman committed
641
                                model:  _activeJoystick ? Math.min(_activeJoystick.totalButtonCount, _maxButtons) : 0
Don Gagne's avatar
Don Gagne committed
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687

                                Row {
                                    spacing: ScreenTools.defaultFontPixelWidth
                                    visible: _activeVehicle.supportsJSButton

                                    property bool pressed

                                    Rectangle {
                                        anchors.verticalCenter:     parent.verticalCenter
                                        width:                      ScreenTools.defaultFontPixelHeight * 1.5
                                        height:                     width
                                        border.width:               1
                                        border.color:               qgcPal.text
                                        color:                      pressed ? qgcPal.buttonHighlight : qgcPal.button


                                        QGCLabel {
                                            anchors.fill:           parent
                                            color:                  pressed ? qgcPal.buttonHighlightText : qgcPal.buttonText
                                            horizontalAlignment:    Text.AlignHCenter
                                            verticalAlignment:      Text.AlignVCenter
                                            text:                   modelData
                                        }
                                    }

                                    FactComboBox {
                                        id:         mainJSButtonActionCombo
                                        width:      ScreenTools.defaultFontPixelWidth * 15
                                        fact:       controller.parameterExists(-1, "BTN"+index+"_FUNCTION") ? controller.getParameterFact(-1, "BTN" + index + "_FUNCTION") : null;
                                        indexModel: false
                                    }

                                    FactComboBox {
                                        id:         shiftJSButtonActionCombo
                                        width:      ScreenTools.defaultFontPixelWidth * 15
                                        fact:       controller.parameterExists(-1, "BTN"+index+"_SFUNCTION") ? controller.getParameterFact(-1, "BTN" + index + "_SFUNCTION") : null;
                                        indexModel: false
                                    }
                                } // Row
                            } // Repeater
                        } // Column
                    } // Column - right setting column
                } // Row - Settings
            } // Column - Left Main Column

            // Right side column
688
            Column {
Don Gagne's avatar
Don Gagne committed
689 690 691
                id:             rightColumn
                anchors.top:    parent.top
                anchors.right:  parent.right
692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707
                width:          Math.min(joystickPage.defaultTextWidth * 35, availableWidth * 0.4)
                spacing:        ScreenTools.defaultFontPixelHeight / 2

                Row {
                    spacing: ScreenTools.defaultFontPixelWidth

                    ExclusiveGroup { id: modeGroup }

                    QGCLabel {
                        text: "TX Mode:"
                    }

                    QGCRadioButton {
                        exclusiveGroup: modeGroup
                        text:           "1"
                        checked:        controller.transmitterMode == 1
708
                        enabled:        !controller.calibrating
709 710 711 712 713 714 715 716

                        onClicked: controller.transmitterMode = 1
                    }

                    QGCRadioButton {
                        exclusiveGroup: modeGroup
                        text:           "2"
                        checked:        controller.transmitterMode == 2
717
                        enabled:        !controller.calibrating
718 719 720 721 722 723 724 725

                        onClicked: controller.transmitterMode = 2
                    }

                    QGCRadioButton {
                        exclusiveGroup: modeGroup
                        text:           "3"
                        checked:        controller.transmitterMode == 3
726
                        enabled:        !controller.calibrating
727 728 729 730 731 732 733 734

                        onClicked: controller.transmitterMode = 3
                    }

                    QGCRadioButton {
                        exclusiveGroup: modeGroup
                        text:           "4"
                        checked:        controller.transmitterMode == 4
735
                        enabled:        !controller.calibrating
736 737 738 739

                        onClicked: controller.transmitterMode = 4
                    }
                }
Don Gagne's avatar
Don Gagne committed
740 741

                Image {
742
                    width:      parent.width
Don Gagne's avatar
Don Gagne committed
743 744 745 746
                    fillMode:   Image.PreserveAspectFit
                    smooth:     true
                    source:     controller.imageHelp
                }
747

Don Gagne's avatar
Don Gagne committed
748 749 750 751
                // Axis monitor
                Column {
                    width:      parent.width
                    spacing:    5
752

Don Gagne's avatar
Don Gagne committed
753
                    QGCLabel { text: qsTr("Axis Monitor") }
754

Don Gagne's avatar
Don Gagne committed
755 756 757 758 759 760 761
                    Connections {
                        target: controller

                        onAxisValueChanged: {
                            if (axisMonitorRepeater.itemAt(axis)) {
                                axisMonitorRepeater.itemAt(axis).loader.item.axisValue = value
                            }
762
                        }
763 764 765 766 767 768

                        onAxisDeadbandChanged: {
                            if (axisMonitorRepeater.itemAt(axis)) {
                                axisMonitorRepeater.itemAt(axis).loader.item.deadbandValue = value
                            }
                        }
769 770
                    }

Don Gagne's avatar
Don Gagne committed
771 772
                    Repeater {
                        id:     axisMonitorRepeater
773
                        model:  _activeJoystick ? _activeJoystick.axisCount : 0
Don Gagne's avatar
Don Gagne committed
774
                        width:  parent.width
775

Don Gagne's avatar
Don Gagne committed
776 777
                        Row {
                            spacing:    5
778

Don Gagne's avatar
Don Gagne committed
779 780
                            // Need this to get to loader from Connections above
                            property Item loader: theLoader
781

Don Gagne's avatar
Don Gagne committed
782 783 784 785
                            QGCLabel {
                                id:     axisLabel
                                text:   modelData
                            }
786

Don Gagne's avatar
Don Gagne committed
787 788 789 790 791 792 793 794 795 796 797
                            Loader {
                                id:                     theLoader
                                anchors.verticalCenter: axisLabel.verticalCenter
                                height:                 ScreenTools.defaultFontPixelHeight
                                width:                  200
                                sourceComponent:        axisMonitorDisplayComponent

                                property real defaultTextWidth:     ScreenTools.defaultFontPixelWidth
                                property bool mapped:               true
                                readonly property bool reversed:    false
                            }
798 799
                        }
                    }
Don Gagne's avatar
Don Gagne committed
800
                } // Column - Axis Monitor
801

Don Gagne's avatar
Don Gagne committed
802 803 804 805
                // Button monitor
                Column {
                    width:      parent.width
                    spacing:    ScreenTools.defaultFontPixelHeight
806

Don Gagne's avatar
Don Gagne committed
807
                    QGCLabel { text: qsTr("Button Monitor") }
808

Don Gagne's avatar
Don Gagne committed
809 810
                    Connections {
                        target: _activeJoystick
811

Don Gagne's avatar
Don Gagne committed
812 813 814 815
                        onRawButtonPressedChanged: {
                            if (buttonMonitorRepeater.itemAt(index)) {
                                buttonMonitorRepeater.itemAt(index).pressed = pressed
                            }
816 817 818
                        }
                    }

Don Gagne's avatar
Don Gagne committed
819 820 821
                    Flow {
                        width:      parent.width
                        spacing:    -1
822

Don Gagne's avatar
Don Gagne committed
823 824
                        Repeater {
                            id:     buttonMonitorRepeater
825
                            model:  _activeJoystick ? _activeJoystick.totalButtonCount : 0
826

Don Gagne's avatar
Don Gagne committed
827 828 829 830 831 832
                            Rectangle {
                                width:          ScreenTools.defaultFontPixelHeight * 1.2
                                height:         width
                                border.width:   1
                                border.color:   qgcPal.text
                                color:          pressed ? qgcPal.buttonHighlight : qgcPal.button
833

Don Gagne's avatar
Don Gagne committed
834
                                property bool pressed
835

Don Gagne's avatar
Don Gagne committed
836 837 838 839 840 841 842
                                QGCLabel {
                                    anchors.fill:           parent
                                    color:                  pressed ? qgcPal.buttonHighlightText : qgcPal.buttonText
                                    horizontalAlignment:    Text.AlignHCenter
                                    verticalAlignment:      Text.AlignVCenter
                                    text:                   modelData
                                }
843
                            }
Don Gagne's avatar
Don Gagne committed
844 845 846 847 848 849 850
                        } // Repeater
                    } // Row
                } // Column - Axis Monitor
            } // Column - Right Column
        } // Item
    } // Component - pageComponent
} // SetupPage
Gregory Dymarek's avatar
Gregory Dymarek committed
851 852