JoystickConfig.qml 36.4 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 13 14


import QtQuick          2.2
import QtQuick.Controls 1.2
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.")

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

Don Gagne's avatar
Don Gagne committed
40 41 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
    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()
                    }
                }
70 71
            }

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

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

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

Don Gagne's avatar
Don Gagne committed
87 88 89
                    property int            __lastAxisValue:        0
                    readonly property int   __axisValueMaxJitter:   100
                    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 108 109 110 111 112 113
                    // Deadband
                    Rectangle {
                        id:                     deadbandBar
                        anchors.verticalCenter: parent.verticalCenter
                        x:                      _deadbandPosition
                        width:                  _deadbandWidth
                        height:                 parent.height / 2
                        color:                  "#8c161a"

                        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
114 115 116 117 118 119 120
                    // Center point
                    Rectangle {
                        anchors.horizontalCenter:   parent.horizontalCenter
                        width:                      defaultTextWidth / 2
                        height:                     parent.height
                        color:                      qgcPal.window
                    }
121

Don Gagne's avatar
Don Gagne committed
122 123 124 125 126 127 128 129 130 131 132 133 134
                    // 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
                    }
135

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

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

Gregory Dymarek's avatar
Gregory Dymarek committed
153

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

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

Don Gagne's avatar
Don Gagne committed
165 166 167 168 169 170 171 172 173
            // 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
174

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

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

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

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

Don Gagne's avatar
Don Gagne committed
192 193 194 195 196 197 198 199 200 201 202 203
                        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
                        }
204

Don Gagne's avatar
Don Gagne committed
205 206
                        Connections {
                            target: controller
207

Don Gagne's avatar
Don Gagne committed
208
                            onRollAxisValueChanged: rollLoader.item.axisValue = value
Gregory Dymarek's avatar
Gregory Dymarek committed
209 210

                            onRollAxisDeadbandChanged: rollLoader.item.deadbandValue = value
Don Gagne's avatar
Don Gagne committed
211
                        }
212 213
                    }

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

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

Don Gagne's avatar
Don Gagne committed
224 225 226 227 228 229 230 231 232 233 234 235
                        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
                        }
236

Don Gagne's avatar
Don Gagne committed
237 238
                        Connections {
                            target: controller
239

Don Gagne's avatar
Don Gagne committed
240
                            onPitchAxisValueChanged: pitchLoader.item.axisValue = value
Gregory Dymarek's avatar
Gregory Dymarek committed
241 242 243

                            onPitchAxisDeadbandChanged: pitchLoader.item.deadbandValue = value

Don Gagne's avatar
Don Gagne committed
244
                        }
245 246
                    }

Don Gagne's avatar
Don Gagne committed
247 248 249
                    Item {
                        width:  parent.width
                        height: defaultTextHeight * 2
250

Don Gagne's avatar
Don Gagne committed
251 252 253 254 255
                        QGCLabel {
                            id:     yawLabel
                            width:  defaultTextWidth * 10
                            text:   qsTr("Yaw")
                        }
256

Don Gagne's avatar
Don Gagne committed
257 258 259 260 261 262 263 264 265 266 267 268
                        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
                        }
269

Don Gagne's avatar
Don Gagne committed
270 271
                        Connections {
                            target: controller
272

Don Gagne's avatar
Don Gagne committed
273
                            onYawAxisValueChanged: yawLoader.item.axisValue = value
Gregory Dymarek's avatar
Gregory Dymarek committed
274 275

                            onYawAxisDeadbandChanged: yawLoader.item.deadbandValue = value
Don Gagne's avatar
Don Gagne committed
276
                        }
277 278
                    }

Don Gagne's avatar
Don Gagne committed
279 280 281
                    Item {
                        width:  parent.width
                        height: defaultTextHeight * 2
282

Don Gagne's avatar
Don Gagne committed
283 284 285 286 287
                        QGCLabel {
                            id:     throttleLabel
                            width:  defaultTextWidth * 10
                            text:   qsTr("Throttle")
                        }
288

Don Gagne's avatar
Don Gagne committed
289 290 291 292 293 294 295 296 297 298 299 300
                        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
                        }
301

Don Gagne's avatar
Don Gagne committed
302 303
                        Connections {
                            target: controller
304

Don Gagne's avatar
Don Gagne committed
305
                            onThrottleAxisValueChanged: throttleLoader.item.axisValue = value
Gregory Dymarek's avatar
Gregory Dymarek committed
306 307

                            onThrottleAxisDeadbandChanged: throttleLoader.item.deadbandValue = value
Don Gagne's avatar
Don Gagne committed
308
                        }
309
                    }
Don Gagne's avatar
Don Gagne committed
310
                } // Column - Attitude Control labels
311

Don Gagne's avatar
Don Gagne committed
312 313 314
                // Command Buttons
                Row {
                    spacing: 10
315
                    visible: _activeJoystick.requiresCalibration
Don Gagne's avatar
Don Gagne committed
316 317 318 319

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

Don Gagne's avatar
Don Gagne committed
321
                        onClicked: controller.skipButtonClicked()
322 323
                    }

Don Gagne's avatar
Don Gagne committed
324 325 326
                    QGCButton {
                        id:     cancelButton
                        text:   qsTr("Cancel")
327

Don Gagne's avatar
Don Gagne committed
328 329
                        onClicked: controller.cancelButtonClicked()
                    }
330

Don Gagne's avatar
Don Gagne committed
331 332 333 334
                    QGCButton {
                        id:         nextButton
                        primary:    true
                        text:       qsTr("Calibrate")
335

Don Gagne's avatar
Don Gagne committed
336 337 338
                        onClicked: controller.nextButtonClicked()
                    }
                } // Row - Buttons
339

Don Gagne's avatar
Don Gagne committed
340 341 342 343 344
                // Status Text
                QGCLabel {
                    id:         statusText
                    width:      parent.width
                    wrapMode:   Text.WordWrap
345 346
                }

Don Gagne's avatar
Don Gagne committed
347 348 349 350 351
                Rectangle {
                    width:          parent.width
                    height:         1
                    border.color:   qgcPal.text
                    border.width:   1
352 353
                }

Don Gagne's avatar
Don Gagne committed
354 355 356 357
                // Settings
                Row {
                    width:      parent.width
                    spacing:    ScreenTools.defaultFontPixelWidth
358

Don Gagne's avatar
Don Gagne committed
359
                    // Left column settings
360
                    Column {
Don Gagne's avatar
Don Gagne committed
361
                        width:      parent.width / 2
362 363
                        spacing:    ScreenTools.defaultFontPixelHeight

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

Don Gagne's avatar
Don Gagne committed
366 367 368
                        Column {
                            width:      parent.width
                            spacing:    ScreenTools.defaultFontPixelHeight
369 370


Don Gagne's avatar
Don Gagne committed
371
                            QGCCheckBox {
Jacob Walser's avatar
Jacob Walser committed
372
                                id:         enabledCheckBox
373 374
                                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
375
                                checked:    _activeVehicle.joystickEnabled
376

Don Gagne's avatar
Don Gagne committed
377
                                onClicked:  _activeVehicle.joystickEnabled = checked
Jacob Walser's avatar
Jacob Walser committed
378 379 380 381 382

                                Connections {
                                    target: joystickManager

                                    onActiveJoystickChanged: {
383
                                        if(_activeJoystick) {
Jacob Walser's avatar
Jacob Walser committed
384
                                            enabledCheckBox.checked = Qt.binding(function() { return _activeJoystick.calibrated && _activeVehicle.joystickEnabled })
385
                                        }
Jacob Walser's avatar
Jacob Walser committed
386 387
                                    }
                                }
388 389
                            }

Don Gagne's avatar
Don Gagne committed
390 391 392
                            Row {
                                width:      parent.width
                                spacing:    ScreenTools.defaultFontPixelWidth
393

Don Gagne's avatar
Don Gagne committed
394 395 396 397 398
                                QGCLabel {
                                    id:                 activeJoystickLabel
                                    anchors.baseline:   joystickCombo.baseline
                                    text:               qsTr("Active joystick:")
                                }
399

Don Gagne's avatar
Don Gagne committed
400 401 402 403 404 405 406 407 408 409 410 411 412 413
                                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
                                        }
414
                                    }
Jacob Walser's avatar
Jacob Walser committed
415 416 417 418 419

                                    Connections {
                                        target: joystickManager
                                        onAvailableJoysticksChanged: {
                                            var index = joystickCombo.find(joystickManager.activeJoystickName)
420
                                            if (index >= 0) {
Jacob Walser's avatar
Jacob Walser committed
421 422 423 424
                                                joystickCombo.currentIndex = index
                                            }
                                        }
                                    }
425
                                }
426 427
                            }

Don Gagne's avatar
Don Gagne committed
428 429 430
                            Column {
                                spacing: ScreenTools.defaultFontPixelHeight / 3
                                visible: _activeVehicle.supportsThrottleModeCenterZero
431

Don Gagne's avatar
Don Gagne committed
432
                                ExclusiveGroup { id: throttleModeExclusiveGroup }
433

Don Gagne's avatar
Don Gagne committed
434 435 436
                                QGCRadioButton {
                                    exclusiveGroup: throttleModeExclusiveGroup
                                    text:           qsTr("Center stick is zero throttle")
437
                                    checked:        _activeJoystick ? _activeJoystick.throttleMode == 0 : false
438

Don Gagne's avatar
Don Gagne committed
439 440
                                    onClicked: _activeJoystick.throttleMode = 0
                                }
441

442
                                Row {
Gregory Dymarek's avatar
Gregory Dymarek committed
443
                                    x:          20
444 445
                                    width:      parent.width
                                    spacing:    ScreenTools.defaultFontPixelWidth
446
                                    visible:    _activeJoystick ? _activeJoystick.throttleMode == 0 : false
447 448 449

                                    QGCCheckBox {
                                        id:         accumulator
450
                                        checked:    _activeJoystick ? _activeJoystick.accumulator : false
Gregory Dymarek's avatar
Gregory Dymarek committed
451
                                        text:       qsTr("Spring loaded throttle smoothing")
452 453 454 455 456

                                        onClicked:  _activeJoystick.accumulator = checked
                                    }
                                }

Don Gagne's avatar
Don Gagne committed
457 458 459
                                QGCRadioButton {
                                    exclusiveGroup: throttleModeExclusiveGroup
                                    text:           qsTr("Full down stick is zero throttle")
460
                                    checked:        _activeJoystick ? _activeJoystick.throttleMode == 1 : false
461

Don Gagne's avatar
Don Gagne committed
462 463
                                    onClicked: _activeJoystick.throttleMode = 1
                                }
464 465
                            }

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

Don Gagne's avatar
Don Gagne committed
469 470
                                QGCCheckBox {
                                    id:         exponential
471
                                    checked:    _activeJoystick ? _activeJoystick.exponential : false
Don Gagne's avatar
Don Gagne committed
472
                                    text:       qsTr("Use exponential curve on roll, pitch, yaw")
473

Don Gagne's avatar
Don Gagne committed
474 475
                                    onClicked:  _activeJoystick.exponential = checked
                                }
476 477
                            }

Don Gagne's avatar
Don Gagne committed
478 479 480 481
                            QGCCheckBox {
                                id:         advancedSettings
                                checked:    _activeVehicle.joystickMode != 0
                                text:       qsTr("Advanced settings (careful!)")
482

Don Gagne's avatar
Don Gagne committed
483 484 485 486
                                onClicked: {
                                    if (!checked) {
                                        _activeVehicle.joystickMode = 0
                                    }
487 488 489
                                }
                            }

Don Gagne's avatar
Don Gagne committed
490 491 492 493 494 495 496 497 498 499
                            Row {
                                width:      parent.width
                                spacing:    ScreenTools.defaultFontPixelWidth
                                visible:    advancedSettings.checked

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

Don Gagne's avatar
Don Gagne committed
501 502 503 504 505
                                QGCComboBox {
                                    id:             joystickModeCombo
                                    currentIndex:   _activeVehicle.joystickMode
                                    width:          ScreenTools.defaultFontPixelWidth * 20
                                    model:          _activeVehicle.joystickModes
506

Don Gagne's avatar
Don Gagne committed
507 508
                                    onActivated: _activeVehicle.joystickMode = index
                                }
509
                            }
510 511 512 513 514 515 516 517 518 519 520 521 522 523

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

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

                                    onClicked:  controller.deadbandToggle = checked
                                }
                            }
524
                        }
Don Gagne's avatar
Don Gagne committed
525
                    } // Column - left column
526

Don Gagne's avatar
Don Gagne committed
527 528 529 530
                    // Right column settings
                    Column {
                        width:      parent.width / 2
                        spacing:    ScreenTools.defaultFontPixelHeight
531

Don Gagne's avatar
Don Gagne committed
532 533
                        Connections {
                            target: _activeJoystick
534

Don Gagne's avatar
Don Gagne committed
535 536 537 538 539 540 541
                            onRawButtonPressedChanged: {
                                if (buttonActionRepeater.itemAt(index)) {
                                    buttonActionRepeater.itemAt(index).pressed = pressed
                                }
                                if (jsButtonActionRepeater.itemAt(index)) {
                                    jsButtonActionRepeater.itemAt(index).pressed = pressed
                                }
542
                            }
543 544
                        }

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

Don Gagne's avatar
Don Gagne committed
547 548 549
                        Column {
                            width:      parent.width
                            spacing:    ScreenTools.defaultFontPixelHeight / 3
550

Don Gagne's avatar
Don Gagne committed
551 552 553
                            QGCLabel {
                                visible: _activeVehicle.manualControlReservedButtonCount != 0
                                text: qsTr("Buttons 0-%1 reserved for firmware use").arg(reservedButtonCount)
554

Don Gagne's avatar
Don Gagne committed
555 556
                                property int reservedButtonCount: _activeVehicle.manualControlReservedButtonCount == -1 ? _activeJoystick.totalButtonCount : _activeVehicle.manualControlReservedButtonCount
                            }
557

Don Gagne's avatar
Don Gagne committed
558 559
                            Repeater {
                                id:     buttonActionRepeater
560
                                model:  _activeJoystick ? _activeJoystick.totalButtonCount : 0
561

Don Gagne's avatar
Don Gagne committed
562 563 564
                                Row {
                                    spacing: ScreenTools.defaultFontPixelWidth
                                    visible: (_activeVehicle.manualControlReservedButtonCount == -1 ? false : modelData >= _activeVehicle.manualControlReservedButtonCount) && !_activeVehicle.supportsJSButton
565

Don Gagne's avatar
Don Gagne committed
566
                                    property bool pressed
567

Don Gagne's avatar
Don Gagne committed
568 569
                                    QGCCheckBox {
                                        anchors.verticalCenter:     parent.verticalCenter
570
                                        checked:                    _activeJoystick ? _activeJoystick.buttonActions[modelData] != "" : false
571

Don Gagne's avatar
Don Gagne committed
572 573
                                        onClicked: _activeJoystick.setButtonAction(modelData, checked ? buttonActionCombo.textAt(buttonActionCombo.currentIndex) : "")
                                    }
574

Don Gagne's avatar
Don Gagne committed
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590
                                    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
                                        }
591 592
                                    }

Don Gagne's avatar
Don Gagne committed
593 594 595
                                    QGCComboBox {
                                        id:             buttonActionCombo
                                        width:          ScreenTools.defaultFontPixelWidth * 20
596
                                        model:          _activeJoystick ? _activeJoystick.actions : 0
597

Don Gagne's avatar
Don Gagne committed
598 599 600
                                        onActivated:            _activeJoystick.setButtonAction(modelData, textAt(index))
                                        Component.onCompleted:  currentIndex = find(_activeJoystick.buttonActions[modelData])
                                    }
601
                                }
Don Gagne's avatar
Don Gagne committed
602
                            } // Repeater
603 604 605

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

Don Gagne's avatar
Don Gagne committed
608 609 610 611
                                QGCLabel {
                                    horizontalAlignment:    Text.AlignHCenter
                                    width:                  ScreenTools.defaultFontPixelHeight * 1.5
                                    text:                   qsTr("#")
612 613
                                }

Don Gagne's avatar
Don Gagne committed
614 615 616
                                QGCLabel {
                                    width:                  ScreenTools.defaultFontPixelWidth * 15
                                    text:                   qsTr("Function: ")
617 618
                                }

Don Gagne's avatar
Don Gagne committed
619 620 621
                                QGCLabel {
                                    width:                  ScreenTools.defaultFontPixelWidth * 15
                                    text:                   qsTr("Shift Function: ")
622 623
                                }
                            } // Row
624

Don Gagne's avatar
Don Gagne committed
625 626
                            Repeater {
                                id:     jsButtonActionRepeater
627
                                model:  _activeJoystick ? _activeJoystick.totalButtonCount : 0
Don Gagne's avatar
Don Gagne committed
628 629 630 631 632 633 634 635 636 637 638 639 640 641 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

                                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
674
            Column {
Don Gagne's avatar
Don Gagne committed
675 676 677
                id:             rightColumn
                anchors.top:    parent.top
                anchors.right:  parent.right
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693
                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
694
                        enabled:        !controller.calibrating
695 696 697 698 699 700 701 702

                        onClicked: controller.transmitterMode = 1
                    }

                    QGCRadioButton {
                        exclusiveGroup: modeGroup
                        text:           "2"
                        checked:        controller.transmitterMode == 2
703
                        enabled:        !controller.calibrating
704 705 706 707 708 709 710 711

                        onClicked: controller.transmitterMode = 2
                    }

                    QGCRadioButton {
                        exclusiveGroup: modeGroup
                        text:           "3"
                        checked:        controller.transmitterMode == 3
712
                        enabled:        !controller.calibrating
713 714 715 716 717 718 719 720

                        onClicked: controller.transmitterMode = 3
                    }

                    QGCRadioButton {
                        exclusiveGroup: modeGroup
                        text:           "4"
                        checked:        controller.transmitterMode == 4
721
                        enabled:        !controller.calibrating
722 723 724 725

                        onClicked: controller.transmitterMode = 4
                    }
                }
Don Gagne's avatar
Don Gagne committed
726 727

                Image {
728
                    width:      parent.width
Don Gagne's avatar
Don Gagne committed
729 730 731 732
                    fillMode:   Image.PreserveAspectFit
                    smooth:     true
                    source:     controller.imageHelp
                }
733

Don Gagne's avatar
Don Gagne committed
734 735 736 737
                // Axis monitor
                Column {
                    width:      parent.width
                    spacing:    5
738

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

Don Gagne's avatar
Don Gagne committed
741 742 743 744 745 746 747
                    Connections {
                        target: controller

                        onAxisValueChanged: {
                            if (axisMonitorRepeater.itemAt(axis)) {
                                axisMonitorRepeater.itemAt(axis).loader.item.axisValue = value
                            }
748 749 750
                        }
                    }

Don Gagne's avatar
Don Gagne committed
751 752
                    Repeater {
                        id:     axisMonitorRepeater
753
                        model:  _activeJoystick ? _activeJoystick.axisCount : 0
Don Gagne's avatar
Don Gagne committed
754
                        width:  parent.width
755

Don Gagne's avatar
Don Gagne committed
756 757
                        Row {
                            spacing:    5
758

Don Gagne's avatar
Don Gagne committed
759 760
                            // Need this to get to loader from Connections above
                            property Item loader: theLoader
761

Don Gagne's avatar
Don Gagne committed
762 763 764 765
                            QGCLabel {
                                id:     axisLabel
                                text:   modelData
                            }
766

Don Gagne's avatar
Don Gagne committed
767 768 769 770 771 772 773 774 775 776 777
                            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
                            }
778 779
                        }
                    }
Don Gagne's avatar
Don Gagne committed
780
                } // Column - Axis Monitor
781

Don Gagne's avatar
Don Gagne committed
782 783 784 785
                // Button monitor
                Column {
                    width:      parent.width
                    spacing:    ScreenTools.defaultFontPixelHeight
786

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

Don Gagne's avatar
Don Gagne committed
789 790
                    Connections {
                        target: _activeJoystick
791

Don Gagne's avatar
Don Gagne committed
792 793 794 795
                        onRawButtonPressedChanged: {
                            if (buttonMonitorRepeater.itemAt(index)) {
                                buttonMonitorRepeater.itemAt(index).pressed = pressed
                            }
796 797 798
                        }
                    }

Don Gagne's avatar
Don Gagne committed
799 800 801
                    Flow {
                        width:      parent.width
                        spacing:    -1
802

Don Gagne's avatar
Don Gagne committed
803 804
                        Repeater {
                            id:     buttonMonitorRepeater
805
                            model:  _activeJoystick ? _activeJoystick.totalButtonCount : 0
806

Don Gagne's avatar
Don Gagne committed
807 808 809 810 811 812
                            Rectangle {
                                width:          ScreenTools.defaultFontPixelHeight * 1.2
                                height:         width
                                border.width:   1
                                border.color:   qgcPal.text
                                color:          pressed ? qgcPal.buttonHighlight : qgcPal.button
813

Don Gagne's avatar
Don Gagne committed
814
                                property bool pressed
815

Don Gagne's avatar
Don Gagne committed
816 817 818 819 820 821 822
                                QGCLabel {
                                    anchors.fill:           parent
                                    color:                  pressed ? qgcPal.buttonHighlightText : qgcPal.buttonText
                                    horizontalAlignment:    Text.AlignHCenter
                                    verticalAlignment:      Text.AlignVCenter
                                    text:                   modelData
                                }
823
                            }
Don Gagne's avatar
Don Gagne committed
824 825 826 827 828 829 830
                        } // Repeater
                    } // Row
                } // Column - Axis Monitor
            } // Column - Right Column
        } // Item
    } // Component - pageComponent
} // SetupPage
Gregory Dymarek's avatar
Gregory Dymarek committed
831 832