JoystickConfig.qml 41.2 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
    Component {
        id: pageComponent

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

49
            readonly property real labelToMonitorMargin: ScreenTools.defaultFontPixelWidth * 3
Don Gagne's avatar
Don Gagne committed
50 51 52

            property var _activeJoystick:   joystickManager.activeJoystick

53 54 55 56
            onSetupPageCompleted: {
                controller.start()
            }

Don Gagne's avatar
Don Gagne committed
57 58 59 60 61 62 63
            JoystickConfigController {
                id:             controller
                statusText:     statusText
                cancelButton:   cancelButton
                nextButton:     nextButton
                skipButton:     skipButton
            }
64

Don Gagne's avatar
Don Gagne committed
65 66 67
            // Live axis monitor control component
            Component {
                id: axisMonitorDisplayComponent
68

Don Gagne's avatar
Don Gagne committed
69 70
                Item {
                    property int axisValue: 0
Gregory Dymarek's avatar
Gregory Dymarek committed
71
                    property int deadbandValue: 0
72
                    property bool narrowIndicator: false
73
                    property color deadbandColor: "#8c161a"
74

Don Gagne's avatar
Don Gagne committed
75
                    property color          __barColor:             qgcPal.windowShade
76

Don Gagne's avatar
Don Gagne committed
77 78 79 80 81 82 83 84
                    // Bar
                    Rectangle {
                        id:                     bar
                        anchors.verticalCenter: parent.verticalCenter
                        width:                  parent.width
                        height:                 parent.height / 2
                        color:                  __barColor
                    }
85

Gregory Dymarek's avatar
Gregory Dymarek committed
86 87 88 89 90 91 92
                    // Deadband
                    Rectangle {
                        id:                     deadbandBar
                        anchors.verticalCenter: parent.verticalCenter
                        x:                      _deadbandPosition
                        width:                  _deadbandWidth
                        height:                 parent.height / 2
93
                        color:                  deadbandColor
94
                        visible:                controller.deadbandToggle
Gregory Dymarek's avatar
Gregory Dymarek committed
95 96 97 98 99 100

                        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
101 102 103
                    // Center point
                    Rectangle {
                        anchors.horizontalCenter:   parent.horizontalCenter
104
                        width:                      ScreenTools.defaultFontPixelWidth / 2
Don Gagne's avatar
Don Gagne committed
105 106 107
                        height:                     parent.height
                        color:                      qgcPal.window
                    }
108

Don Gagne's avatar
Don Gagne committed
109 110 111
                    // Indicator
                    Rectangle {
                        anchors.verticalCenter: parent.verticalCenter
112 113
                        width:                  parent.narrowIndicator ?  height/6 : height
                        height:                 parent.height * 0.75
Don Gagne's avatar
Don Gagne committed
114 115 116 117 118 119 120 121
                        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
                    }
122

Don Gagne's avatar
Don Gagne committed
123 124 125 126 127 128 129
                    QGCLabel {
                        anchors.fill:           parent
                        horizontalAlignment:    Text.AlignHCenter
                        verticalAlignment:      Text.AlignVCenter
                        text:                   qsTr("Not Mapped")
                        visible:                !mapped
                    }
130

Don Gagne's avatar
Don Gagne committed
131 132 133 134 135 136 137 138
                    ColorAnimation {
                        id:         barAnimation
                        target:     bar
                        property:   "color"
                        from:       "yellow"
                        to:         __barColor
                        duration:   1500
                    }
139

Gregory Dymarek's avatar
Gregory Dymarek committed
140

Don Gagne's avatar
Don Gagne committed
141
                    // Axis value debugger
Gregory Dymarek's avatar
Gregory Dymarek committed
142
                    /*
Don Gagne's avatar
Don Gagne committed
143 144 145 146 147
                    QGCLabel {
                        anchors.fill: parent
                        text: axisValue
                    }
                    */
Gregory Dymarek's avatar
Gregory Dymarek committed
148

149
                }
Don Gagne's avatar
Don Gagne committed
150
            } // Component - axisMonitorDisplayComponent
151

Don Gagne's avatar
Don Gagne committed
152 153 154 155 156 157 158 159 160
            // 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
161

Don Gagne's avatar
Don Gagne committed
162 163 164 165
                // Attitude Controls
                Column {
                    width:      parent.width
                    spacing:    5
166

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

Don Gagne's avatar
Don Gagne committed
169 170 171
                    Item {
                        width:  parent.width
                        height: defaultTextHeight * 2
172

Don Gagne's avatar
Don Gagne committed
173 174
                        QGCLabel {
                            id:     rollLabel
175
                            width:  ScreenTools.defaultFontPixelWidth * 10
176
                            text:   activeVehicle.sub ? qsTr("Lateral") : qsTr("Roll")
Don Gagne's avatar
Don Gagne committed
177
                        }
178

Don Gagne's avatar
Don Gagne committed
179 180 181 182 183 184 185 186
                        Loader {
                            id:                 rollLoader
                            anchors.left:       rollLabel.right
                            anchors.right:      parent.right
                            height:             ScreenTools.defaultFontPixelHeight
                            width:              100
                            sourceComponent:    axisMonitorDisplayComponent

187
                            property real ScreenTools.defaultFontPixelWidth: ScreenTools.defaultFontPixelWidth
Don Gagne's avatar
Don Gagne committed
188 189 190
                            property bool mapped:           controller.rollAxisMapped
                            property bool reversed:         controller.rollAxisReversed
                        }
191

192 193 194 195 196
                        Connections {
                            target: _activeJoystick

                            onManualControl: rollLoader.item.axisValue = roll*32768.0
                        }
197 198
                    }

Don Gagne's avatar
Don Gagne committed
199 200 201
                    Item {
                        width:  parent.width
                        height: defaultTextHeight * 2
202

Don Gagne's avatar
Don Gagne committed
203 204
                        QGCLabel {
                            id:     pitchLabel
205
                            width:  ScreenTools.defaultFontPixelWidth * 10
206
                            text:   activeVehicle.sub ? qsTr("Forward") : qsTr("Pitch")
Don Gagne's avatar
Don Gagne committed
207
                        }
208

Don Gagne's avatar
Don Gagne committed
209 210 211 212 213 214 215 216
                        Loader {
                            id:                 pitchLoader
                            anchors.left:       pitchLabel.right
                            anchors.right:      parent.right
                            height:             ScreenTools.defaultFontPixelHeight
                            width:              100
                            sourceComponent:    axisMonitorDisplayComponent

217
                            property real ScreenTools.defaultFontPixelWidth: ScreenTools.defaultFontPixelWidth
Don Gagne's avatar
Don Gagne committed
218 219 220
                            property bool mapped:           controller.pitchAxisMapped
                            property bool reversed:         controller.pitchAxisReversed
                        }
221

222 223 224 225 226
                        Connections {
                            target: _activeJoystick

                            onManualControl: pitchLoader.item.axisValue = pitch*32768.0
                        }
227 228
                    }

Don Gagne's avatar
Don Gagne committed
229 230 231
                    Item {
                        width:  parent.width
                        height: defaultTextHeight * 2
232

Don Gagne's avatar
Don Gagne committed
233 234
                        QGCLabel {
                            id:     yawLabel
235
                            width:  ScreenTools.defaultFontPixelWidth * 10
Don Gagne's avatar
Don Gagne committed
236 237
                            text:   qsTr("Yaw")
                        }
238

Don Gagne's avatar
Don Gagne committed
239 240 241 242 243 244 245 246
                        Loader {
                            id:                 yawLoader
                            anchors.left:       yawLabel.right
                            anchors.right:      parent.right
                            height:             ScreenTools.defaultFontPixelHeight
                            width:              100
                            sourceComponent:    axisMonitorDisplayComponent

247
                            property real ScreenTools.defaultFontPixelWidth: ScreenTools.defaultFontPixelWidth
Don Gagne's avatar
Don Gagne committed
248 249 250
                            property bool mapped:           controller.yawAxisMapped
                            property bool reversed:         controller.yawAxisReversed
                        }
251

252 253 254 255 256
                        Connections {
                            target: _activeJoystick

                            onManualControl: yawLoader.item.axisValue = yaw*32768.0
                        }
257 258
                    }

Don Gagne's avatar
Don Gagne committed
259 260 261
                    Item {
                        width:  parent.width
                        height: defaultTextHeight * 2
262

Don Gagne's avatar
Don Gagne committed
263 264
                        QGCLabel {
                            id:     throttleLabel
265
                            width:  ScreenTools.defaultFontPixelWidth * 10
Don Gagne's avatar
Don Gagne committed
266 267
                            text:   qsTr("Throttle")
                        }
268

Don Gagne's avatar
Don Gagne committed
269 270 271 272 273 274 275 276
                        Loader {
                            id:                 throttleLoader
                            anchors.left:       throttleLabel.right
                            anchors.right:      parent.right
                            height:             ScreenTools.defaultFontPixelHeight
                            width:              100
                            sourceComponent:    axisMonitorDisplayComponent

277
                            property real ScreenTools.defaultFontPixelWidth: ScreenTools.defaultFontPixelWidth
Don Gagne's avatar
Don Gagne committed
278 279 280
                            property bool mapped:           controller.throttleAxisMapped
                            property bool reversed:         controller.throttleAxisReversed
                        }
281

282 283 284
                        Connections {
                            target: _activeJoystick

285
                            onManualControl: throttleLoader.item.axisValue = _activeJoystick.negativeThrust ? -throttle*32768.0 : (-2*throttle+1)*32768.0
286
                        }
287
                    }
Don Gagne's avatar
Don Gagne committed
288
                } // Column - Attitude Control labels
289

Don Gagne's avatar
Don Gagne committed
290 291 292
                // Command Buttons
                Row {
                    spacing: 10
293
                    visible: _activeJoystick.requiresCalibration
Don Gagne's avatar
Don Gagne committed
294 295 296 297

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

Don Gagne's avatar
Don Gagne committed
299
                        onClicked: controller.skipButtonClicked()
300 301
                    }

Don Gagne's avatar
Don Gagne committed
302 303 304
                    QGCButton {
                        id:     cancelButton
                        text:   qsTr("Cancel")
305

Don Gagne's avatar
Don Gagne committed
306 307
                        onClicked: controller.cancelButtonClicked()
                    }
308

Don Gagne's avatar
Don Gagne committed
309 310 311 312
                    QGCButton {
                        id:         nextButton
                        primary:    true
                        text:       qsTr("Calibrate")
313

Don Gagne's avatar
Don Gagne committed
314 315 316
                        onClicked: controller.nextButtonClicked()
                    }
                } // Row - Buttons
317

Don Gagne's avatar
Don Gagne committed
318 319 320 321 322
                // Status Text
                QGCLabel {
                    id:         statusText
                    width:      parent.width
                    wrapMode:   Text.WordWrap
323 324
                }

Don Gagne's avatar
Don Gagne committed
325 326 327 328 329
                Rectangle {
                    width:          parent.width
                    height:         1
                    border.color:   qgcPal.text
                    border.width:   1
330 331
                }

Don Gagne's avatar
Don Gagne committed
332 333 334 335
                // Settings
                Row {
                    width:      parent.width
                    spacing:    ScreenTools.defaultFontPixelWidth
336

Don Gagne's avatar
Don Gagne committed
337
                    // Left column settings
338
                    Column {
Don Gagne's avatar
Don Gagne committed
339
                        width:      parent.width / 2
340 341
                        spacing:    ScreenTools.defaultFontPixelHeight

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

Don Gagne's avatar
Don Gagne committed
344 345 346
                        Column {
                            width:      parent.width
                            spacing:    ScreenTools.defaultFontPixelHeight
347 348


Don Gagne's avatar
Don Gagne committed
349
                            QGCCheckBox {
Jacob Walser's avatar
Jacob Walser committed
350
                                id:         enabledCheckBox
351 352
                                enabled:    _activeJoystick ? _activeJoystick.calibrated : false
                                text:       _activeJoystick ? _activeJoystick.calibrated ? qsTr("Enable joystick input") : qsTr("Enable not allowed (Calibrate First)") : ""
353 354
                                onClicked:  activeVehicle.joystickEnabled = checked
                                Component.onCompleted: checked = activeVehicle.joystickEnabled
355 356

                                Connections {
357
                                    target: activeVehicle
358 359

                                    onJoystickEnabledChanged: {
360
                                        enabledCheckBox.checked = activeVehicle.joystickEnabled
361 362
                                    }
                                }
363

Jacob Walser's avatar
Jacob Walser committed
364 365 366 367
                                Connections {
                                    target: joystickManager

                                    onActiveJoystickChanged: {
368
                                        if(_activeJoystick) {
369
                                            enabledCheckBox.checked = Qt.binding(function() { return _activeJoystick.calibrated && activeVehicle.joystickEnabled })
370
                                        }
Jacob Walser's avatar
Jacob Walser committed
371 372
                                    }
                                }
373 374
                            }

Don Gagne's avatar
Don Gagne committed
375 376 377
                            Row {
                                width:      parent.width
                                spacing:    ScreenTools.defaultFontPixelWidth
378

Don Gagne's avatar
Don Gagne committed
379 380 381 382 383
                                QGCLabel {
                                    id:                 activeJoystickLabel
                                    anchors.baseline:   joystickCombo.baseline
                                    text:               qsTr("Active joystick:")
                                }
384

Don Gagne's avatar
Don Gagne committed
385 386 387 388 389 390 391 392 393 394 395 396 397 398
                                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
                                        }
399
                                    }
Jacob Walser's avatar
Jacob Walser committed
400 401 402 403 404

                                    Connections {
                                        target: joystickManager
                                        onAvailableJoysticksChanged: {
                                            var index = joystickCombo.find(joystickManager.activeJoystickName)
405
                                            if (index >= 0) {
Jacob Walser's avatar
Jacob Walser committed
406 407 408 409
                                                joystickCombo.currentIndex = index
                                            }
                                        }
                                    }
410
                                }
411 412
                            }

Don Gagne's avatar
Don Gagne committed
413 414
                            Column {
                                spacing: ScreenTools.defaultFontPixelHeight / 3
415
                                visible: activeVehicle.supportsThrottleModeCenterZero
416

Don Gagne's avatar
Don Gagne committed
417
                                ExclusiveGroup { id: throttleModeExclusiveGroup }
418

Don Gagne's avatar
Don Gagne committed
419 420 421
                                QGCRadioButton {
                                    exclusiveGroup: throttleModeExclusiveGroup
                                    text:           qsTr("Center stick is zero throttle")
422
                                    checked:        _activeJoystick ? _activeJoystick.throttleMode == 0 : false
423

Don Gagne's avatar
Don Gagne committed
424 425
                                    onClicked: _activeJoystick.throttleMode = 0
                                }
426

427
                                Row {
Gregory Dymarek's avatar
Gregory Dymarek committed
428
                                    x:          20
429 430
                                    width:      parent.width
                                    spacing:    ScreenTools.defaultFontPixelWidth
431
                                    visible:    _activeJoystick ? _activeJoystick.throttleMode == 0 : false
432 433 434

                                    QGCCheckBox {
                                        id:         accumulator
435
                                        checked:    _activeJoystick ? _activeJoystick.accumulator : false
Gregory Dymarek's avatar
Gregory Dymarek committed
436
                                        text:       qsTr("Spring loaded throttle smoothing")
437 438 439 440 441

                                        onClicked:  _activeJoystick.accumulator = checked
                                    }
                                }

Don Gagne's avatar
Don Gagne committed
442 443 444
                                QGCRadioButton {
                                    exclusiveGroup: throttleModeExclusiveGroup
                                    text:           qsTr("Full down stick is zero throttle")
445
                                    checked:        _activeJoystick ? _activeJoystick.throttleMode == 1 : false
446

Don Gagne's avatar
Don Gagne committed
447 448
                                    onClicked: _activeJoystick.throttleMode = 1
                                }
449 450

                                QGCCheckBox {
451
                                    visible:        activeVehicle.supportsNegativeThrust
452 453
                                    id:             negativeThrust
                                    text:           qsTr("Allow negative Thrust")
454
                                    enabled:        _activeJoystick.negativeThrust = activeVehicle.supportsNegativeThrust
455
                                    checked:        _activeJoystick ? _activeJoystick.negativeThrust : false
456
                                    onClicked:      _activeJoystick.negativeThrust = checked
457
                                }
458 459
                            }

Don Gagne's avatar
Don Gagne committed
460 461
                            Column {
                                spacing: ScreenTools.defaultFontPixelHeight / 3
462

463 464 465 466 467 468 469 470 471 472 473
                                QGCLabel {
                                    id:                 expoSliderLabel
                                    text:               qsTr("Exponential:")
                                }

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

nanthony21's avatar
nanthony21 committed
474 475
                                        Component.onCompleted: value=-_activeJoystick.exponential
                                        onValueChanged: _activeJoystick.exponential=-value
476 477 478 479 480
                                     }

                                    QGCLabel {
                                        id:     expoSliderIndicator
                                        text:   expoSlider.value.toFixed(2)
481
                                    }
Don Gagne's avatar
Don Gagne committed
482
                                }
483 484
                            }

Don Gagne's avatar
Don Gagne committed
485 486
                            QGCCheckBox {
                                id:         advancedSettings
487
                                checked:    activeVehicle.joystickMode != 0
Don Gagne's avatar
Don Gagne committed
488
                                text:       qsTr("Advanced settings (careful!)")
489

Don Gagne's avatar
Don Gagne committed
490 491
                                onClicked: {
                                    if (!checked) {
492
                                        activeVehicle.joystickMode = 0
Don Gagne's avatar
Don Gagne committed
493
                                    }
494 495 496
                                }
                            }

Don Gagne's avatar
Don Gagne committed
497 498 499 500 501 502 503 504 505 506
                            Row {
                                width:      parent.width
                                spacing:    ScreenTools.defaultFontPixelWidth
                                visible:    advancedSettings.checked

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

Don Gagne's avatar
Don Gagne committed
508 509
                                QGCComboBox {
                                    id:             joystickModeCombo
510
                                    currentIndex:   activeVehicle.joystickMode
Don Gagne's avatar
Don Gagne committed
511
                                    width:          ScreenTools.defaultFontPixelWidth * 20
512
                                    model:          activeVehicle.joystickModes
513

514
                                    onActivated: activeVehicle.joystickMode = index
Don Gagne's avatar
Don Gagne committed
515
                                }
516
                            }
517

518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535
                            Row {
                                width:      parent.width
                                spacing:    ScreenTools.defaultFontPixelWidth
                                visible:    advancedSettings.checked
                                QGCLabel {
                                    text:       qsTr("Message frequency (Hz):")
                                    anchors.verticalCenter: parent.verticalCenter
                                }
                                QGCTextField {
                                    text:       _activeJoystick.frequency
                                    validator:  DoubleValidator { bottom: 0.25; top: 100.0; }
                                    inputMethodHints: Qt.ImhFormattedNumbersOnly
                                    onEditingFinished: {
                                        _activeJoystick.frequency = parseFloat(text)
                                    }
                                }
                            }

536 537 538 539 540 541
                            Row {
                                width:      parent.width
                                spacing:    ScreenTools.defaultFontPixelWidth
                                visible:    advancedSettings.checked
                                QGCCheckBox {
                                    id:         joystickCircleCorrection
542
                                    checked:    activeVehicle.joystickMode != 0
543 544 545 546 547 548 549 550 551
                                    text:       qsTr("Enable circle correction")

                                    Component.onCompleted: checked = _activeJoystick.circleCorrection
                                    onClicked: {
                                        _activeJoystick.circleCorrection = checked
                                    }
                                }
                            }

552 553 554 555 556 557 558 559 560 561 562 563 564
                            Row {
                                width:      parent.width
                                spacing:    ScreenTools.defaultFontPixelWidth
                                visible:    advancedSettings.checked

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

                                    onClicked:  controller.deadbandToggle = checked
                                }
                            }
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579
                            Row{
                                width: parent.width
                                spacing: ScreenTools.defaultFontPixelWidth
                                visible: advancedSettings.checked
                                QGCLabel{
                                    width:       parent.width * 0.85
                                    font.pointSize:     ScreenTools.smallFontPointSize
                                    wrapMode:           Text.WordWrap
                                    text:   qsTr("Deadband can be set during the first ") +
                                            qsTr("step of calibration by gently wiggling each axis. ") +
                                            qsTr("Deadband can also be adjusted by clicking and ") +
                                            qsTr("dragging vertically on the corresponding axis monitor.")
                                    visible: controller.deadbandToggle
                                }
                            }
580
                        }
Don Gagne's avatar
Don Gagne committed
581
                    } // Column - left column
582

Don Gagne's avatar
Don Gagne committed
583 584 585 586
                    // Right column settings
                    Column {
                        width:      parent.width / 2
                        spacing:    ScreenTools.defaultFontPixelHeight
587

Don Gagne's avatar
Don Gagne committed
588 589
                        Connections {
                            target: _activeJoystick
590

Don Gagne's avatar
Don Gagne committed
591 592 593 594 595 596 597
                            onRawButtonPressedChanged: {
                                if (buttonActionRepeater.itemAt(index)) {
                                    buttonActionRepeater.itemAt(index).pressed = pressed
                                }
                                if (jsButtonActionRepeater.itemAt(index)) {
                                    jsButtonActionRepeater.itemAt(index).pressed = pressed
                                }
598
                            }
599 600
                        }

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

Don Gagne's avatar
Don Gagne committed
603 604 605
                        Column {
                            width:      parent.width
                            spacing:    ScreenTools.defaultFontPixelHeight / 3
606

Don Gagne's avatar
Don Gagne committed
607 608
                            Repeater {
                                id:     buttonActionRepeater
dheideman's avatar
dheideman committed
609
                                model:  _activeJoystick ? Math.min(_activeJoystick.totalButtonCount, _maxButtons) : 0
610

Don Gagne's avatar
Don Gagne committed
611 612
                                Row {
                                    spacing: ScreenTools.defaultFontPixelWidth
613
                                    visible: !activeVehicle.supportsJSButton
614

Don Gagne's avatar
Don Gagne committed
615
                                    property bool pressed
616

Don Gagne's avatar
Don Gagne committed
617 618
                                    QGCCheckBox {
                                        anchors.verticalCenter:     parent.verticalCenter
619
                                        checked:                    _activeJoystick ? _activeJoystick.buttonActions[modelData] != "" : false
620

Don Gagne's avatar
Don Gagne committed
621 622
                                        onClicked: _activeJoystick.setButtonAction(modelData, checked ? buttonActionCombo.textAt(buttonActionCombo.currentIndex) : "")
                                    }
623

Don Gagne's avatar
Don Gagne committed
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639
                                    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
                                        }
640 641
                                    }

Don Gagne's avatar
Don Gagne committed
642 643 644
                                    QGCComboBox {
                                        id:             buttonActionCombo
                                        width:          ScreenTools.defaultFontPixelWidth * 20
645
                                        model:          _activeJoystick ? _activeJoystick.actions : 0
646

Don Gagne's avatar
Don Gagne committed
647 648 649
                                        onActivated:            _activeJoystick.setButtonAction(modelData, textAt(index))
                                        Component.onCompleted:  currentIndex = find(_activeJoystick.buttonActions[modelData])
                                    }
650
                                }
Don Gagne's avatar
Don Gagne committed
651
                            } // Repeater
652 653 654

                            Row {
                                spacing: ScreenTools.defaultFontPixelWidth
655
                                visible: activeVehicle.supportsJSButton
656

Don Gagne's avatar
Don Gagne committed
657 658 659 660
                                QGCLabel {
                                    horizontalAlignment:    Text.AlignHCenter
                                    width:                  ScreenTools.defaultFontPixelHeight * 1.5
                                    text:                   qsTr("#")
661 662
                                }

Don Gagne's avatar
Don Gagne committed
663 664 665
                                QGCLabel {
                                    width:                  ScreenTools.defaultFontPixelWidth * 15
                                    text:                   qsTr("Function: ")
666 667
                                }

Don Gagne's avatar
Don Gagne committed
668 669 670
                                QGCLabel {
                                    width:                  ScreenTools.defaultFontPixelWidth * 15
                                    text:                   qsTr("Shift Function: ")
671 672
                                }
                            } // Row
673

Don Gagne's avatar
Don Gagne committed
674 675
                            Repeater {
                                id:     jsButtonActionRepeater
dheideman's avatar
dheideman committed
676
                                model:  _activeJoystick ? Math.min(_activeJoystick.totalButtonCount, _maxButtons) : 0
Don Gagne's avatar
Don Gagne committed
677 678 679

                                Row {
                                    spacing: ScreenTools.defaultFontPixelWidth
680
                                    visible: activeVehicle.supportsJSButton
Don Gagne's avatar
Don Gagne committed
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722

                                    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
723
            Column {
Don Gagne's avatar
Don Gagne committed
724 725 726
                id:             rightColumn
                anchors.top:    parent.top
                anchors.right:  parent.right
727
                width:          Math.min(joystickPage.ScreenTools.defaultFontPixelWidth * 35, availableWidth * 0.4)
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742
                spacing:        ScreenTools.defaultFontPixelHeight / 2

                Row {
                    spacing: ScreenTools.defaultFontPixelWidth

                    ExclusiveGroup { id: modeGroup }

                    QGCLabel {
                        text: "TX Mode:"
                    }

                    QGCRadioButton {
                        exclusiveGroup: modeGroup
                        text:           "1"
                        checked:        controller.transmitterMode == 1
743
                        enabled:        !controller.calibrating
744 745 746 747 748 749 750 751

                        onClicked: controller.transmitterMode = 1
                    }

                    QGCRadioButton {
                        exclusiveGroup: modeGroup
                        text:           "2"
                        checked:        controller.transmitterMode == 2
752
                        enabled:        !controller.calibrating
753 754 755 756 757 758 759 760

                        onClicked: controller.transmitterMode = 2
                    }

                    QGCRadioButton {
                        exclusiveGroup: modeGroup
                        text:           "3"
                        checked:        controller.transmitterMode == 3
761
                        enabled:        !controller.calibrating
762 763 764 765 766 767 768 769

                        onClicked: controller.transmitterMode = 3
                    }

                    QGCRadioButton {
                        exclusiveGroup: modeGroup
                        text:           "4"
                        checked:        controller.transmitterMode == 4
770
                        enabled:        !controller.calibrating
771 772 773 774

                        onClicked: controller.transmitterMode = 4
                    }
                }
Don Gagne's avatar
Don Gagne committed
775 776

                Image {
777
                    width:      parent.width
Don Gagne's avatar
Don Gagne committed
778 779 780 781
                    fillMode:   Image.PreserveAspectFit
                    smooth:     true
                    source:     controller.imageHelp
                }
782

Don Gagne's avatar
Don Gagne committed
783 784 785 786
                // Axis monitor
                Column {
                    width:      parent.width
                    spacing:    5
787

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

Don Gagne's avatar
Don Gagne committed
790 791 792 793 794 795 796
                    Connections {
                        target: controller

                        onAxisValueChanged: {
                            if (axisMonitorRepeater.itemAt(axis)) {
                                axisMonitorRepeater.itemAt(axis).loader.item.axisValue = value
                            }
797
                        }
798 799 800 801 802 803

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

Don Gagne's avatar
Don Gagne committed
806 807
                    Repeater {
                        id:     axisMonitorRepeater
808
                        model:  _activeJoystick ? _activeJoystick.axisCount : 0
Don Gagne's avatar
Don Gagne committed
809
                        width:  parent.width
810

Don Gagne's avatar
Don Gagne committed
811 812
                        Row {
                            spacing:    5
813

Don Gagne's avatar
Don Gagne committed
814 815
                            // Need this to get to loader from Connections above
                            property Item loader: theLoader
816

Don Gagne's avatar
Don Gagne committed
817 818 819 820
                            QGCLabel {
                                id:     axisLabel
                                text:   modelData
                            }
821

Don Gagne's avatar
Don Gagne committed
822 823 824 825 826 827
                            Loader {
                                id:                     theLoader
                                anchors.verticalCenter: axisLabel.verticalCenter
                                height:                 ScreenTools.defaultFontPixelHeight
                                width:                  200
                                sourceComponent:        axisMonitorDisplayComponent
828
                                Component.onCompleted:  item.narrowIndicator = true
Don Gagne's avatar
Don Gagne committed
829

830
                                property real ScreenTools.defaultFontPixelWidth:     ScreenTools.defaultFontPixelWidth
Don Gagne's avatar
Don Gagne committed
831 832
                                property bool mapped:               true
                                readonly property bool reversed:    false
833 834 835 836 837


                                MouseArea {
                                    id:             deadbandMouseArea
                                    anchors.fill:   parent.item
838
                                    enabled:        controller.deadbandToggle
839 840 841 842 843

                                    property real startY

                                    onPressed: {
                                        startY = mouseY
844
                                        parent.item.deadbandColor = "#3C6315"
845 846 847 848 849 850 851 852
                                    }
                                    onPositionChanged: {
                                        var newValue = parent.item.deadbandValue + (startY - mouseY)*15
                                        if ((newValue > 0) && (newValue <32768)){parent.item.deadbandValue=newValue;}
                                        startY = mouseY
                                    }
                                    onReleased: {
                                        controller.setDeadbandValue(modelData,parent.item.deadbandValue)
853
                                        parent.item.deadbandColor = "#8c161a"
854 855
                                    }
                                }
Don Gagne's avatar
Don Gagne committed
856
                            }
857

858 859
                        }
                    }
Don Gagne's avatar
Don Gagne committed
860
                } // Column - Axis Monitor
861

Don Gagne's avatar
Don Gagne committed
862 863 864 865
                // Button monitor
                Column {
                    width:      parent.width
                    spacing:    ScreenTools.defaultFontPixelHeight
866

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

Don Gagne's avatar
Don Gagne committed
869 870
                    Connections {
                        target: _activeJoystick
871

Don Gagne's avatar
Don Gagne committed
872 873 874 875
                        onRawButtonPressedChanged: {
                            if (buttonMonitorRepeater.itemAt(index)) {
                                buttonMonitorRepeater.itemAt(index).pressed = pressed
                            }
876 877 878
                        }
                    }

Don Gagne's avatar
Don Gagne committed
879 880 881
                    Flow {
                        width:      parent.width
                        spacing:    -1
882

Don Gagne's avatar
Don Gagne committed
883 884
                        Repeater {
                            id:     buttonMonitorRepeater
885
                            model:  _activeJoystick ? _activeJoystick.totalButtonCount : 0
886

Don Gagne's avatar
Don Gagne committed
887 888 889 890 891 892
                            Rectangle {
                                width:          ScreenTools.defaultFontPixelHeight * 1.2
                                height:         width
                                border.width:   1
                                border.color:   qgcPal.text
                                color:          pressed ? qgcPal.buttonHighlight : qgcPal.button
893

Don Gagne's avatar
Don Gagne committed
894
                                property bool pressed
895

Don Gagne's avatar
Don Gagne committed
896 897 898 899 900 901 902
                                QGCLabel {
                                    anchors.fill:           parent
                                    color:                  pressed ? qgcPal.buttonHighlightText : qgcPal.buttonText
                                    horizontalAlignment:    Text.AlignHCenter
                                    verticalAlignment:      Text.AlignVCenter
                                    text:                   modelData
                                }
903
                            }
Don Gagne's avatar
Don Gagne committed
904 905 906 907 908 909 910
                        } // Repeater
                    } // Row
                } // Column - Axis Monitor
            } // Column - Right Column
        } // Item
    } // Component - pageComponent
} // SetupPage
Gregory Dymarek's avatar
Gregory Dymarek committed
911 912