JoystickConfig.qml 40.5 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
9 10


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

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

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

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

Jacob Walser's avatar
Jacob Walser committed
32 33 34
    Connections {
        target: joystickManager
        onAvailableJoysticksChanged: {
Gus Grubba's avatar
Gus Grubba committed
35
            if( joystickManager.joysticks.length === 0 ) {
Jacob Walser's avatar
Jacob Walser committed
36 37 38 39 40 41
                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
            function setupPageCompleted() {
54 55 56
                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 188
                            property bool mapped:   controller.rollAxisMapped
                            property bool reversed: controller.rollAxisReversed
Don Gagne's avatar
Don Gagne committed
189
                        }
190

191 192 193 194 195
                        Connections {
                            target: _activeJoystick

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

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

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

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

                            property bool mapped:           controller.pitchAxisMapped
                            property bool reversed:         controller.pitchAxisReversed
                        }
219

220 221 222 223 224
                        Connections {
                            target: _activeJoystick

                            onManualControl: pitchLoader.item.axisValue = pitch*32768.0
                        }
225 226
                    }

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

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

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

                            property bool mapped:           controller.yawAxisMapped
                            property bool reversed:         controller.yawAxisReversed
                        }
248

249 250 251 252 253
                        Connections {
                            target: _activeJoystick

                            onManualControl: yawLoader.item.axisValue = yaw*32768.0
                        }
254 255
                    }

Don Gagne's avatar
Don Gagne committed
256 257 258
                    Item {
                        width:  parent.width
                        height: defaultTextHeight * 2
259

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

Don Gagne's avatar
Don Gagne committed
266 267 268 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

                            property bool mapped:           controller.throttleAxisMapped
                            property bool reversed:         controller.throttleAxisReversed
                        }
277

278 279 280
                        Connections {
                            target: _activeJoystick

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

Don Gagne's avatar
Don Gagne committed
286 287 288
                // Command Buttons
                Row {
                    spacing: 10
289
                    visible: _activeJoystick.requiresCalibration
Don Gagne's avatar
Don Gagne committed
290 291 292 293

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

Don Gagne's avatar
Don Gagne committed
295
                        onClicked: controller.skipButtonClicked()
296 297
                    }

Don Gagne's avatar
Don Gagne committed
298 299 300
                    QGCButton {
                        id:     cancelButton
                        text:   qsTr("Cancel")
301

Don Gagne's avatar
Don Gagne committed
302 303
                        onClicked: controller.cancelButtonClicked()
                    }
304

Don Gagne's avatar
Don Gagne committed
305 306 307 308
                    QGCButton {
                        id:         nextButton
                        primary:    true
                        text:       qsTr("Calibrate")
309

Don Gagne's avatar
Don Gagne committed
310 311 312
                        onClicked: controller.nextButtonClicked()
                    }
                } // Row - Buttons
313

Don Gagne's avatar
Don Gagne committed
314 315 316 317 318
                // Status Text
                QGCLabel {
                    id:         statusText
                    width:      parent.width
                    wrapMode:   Text.WordWrap
319 320
                }

Don Gagne's avatar
Don Gagne committed
321 322 323 324 325
                Rectangle {
                    width:          parent.width
                    height:         1
                    border.color:   qgcPal.text
                    border.width:   1
326 327
                }

Don Gagne's avatar
Don Gagne committed
328 329 330 331
                // Settings
                Row {
                    width:      parent.width
                    spacing:    ScreenTools.defaultFontPixelWidth
332

Don Gagne's avatar
Don Gagne committed
333
                    // Left column settings
334
                    Column {
Don Gagne's avatar
Don Gagne committed
335
                        width:      parent.width / 2
336 337
                        spacing:    ScreenTools.defaultFontPixelHeight

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

Don Gagne's avatar
Don Gagne committed
340 341 342
                        Column {
                            width:      parent.width
                            spacing:    ScreenTools.defaultFontPixelHeight
343 344


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

                                Connections {
353
                                    target: activeVehicle
354 355

                                    onJoystickEnabledChanged: {
356
                                        enabledCheckBox.checked = activeVehicle.joystickEnabled
357 358
                                    }
                                }
359

Jacob Walser's avatar
Jacob Walser committed
360 361 362 363
                                Connections {
                                    target: joystickManager

                                    onActiveJoystickChanged: {
364
                                        if(_activeJoystick) {
365
                                            enabledCheckBox.checked = Qt.binding(function() { return _activeJoystick.calibrated && activeVehicle.joystickEnabled })
366
                                        }
Jacob Walser's avatar
Jacob Walser committed
367 368
                                    }
                                }
369 370
                            }

Don Gagne's avatar
Don Gagne committed
371 372 373
                            Row {
                                width:      parent.width
                                spacing:    ScreenTools.defaultFontPixelWidth
374

Don Gagne's avatar
Don Gagne committed
375 376 377 378 379
                                QGCLabel {
                                    id:                 activeJoystickLabel
                                    anchors.baseline:   joystickCombo.baseline
                                    text:               qsTr("Active joystick:")
                                }
380

Don Gagne's avatar
Don Gagne committed
381 382 383 384 385 386 387 388 389
                                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)
Gus Grubba's avatar
Gus Grubba committed
390
                                        if (index === -1) {
Don Gagne's avatar
Don Gagne committed
391 392 393 394
                                            console.warn(qsTr("Active joystick name not in combo"), joystickManager.activeJoystickName)
                                        } else {
                                            joystickCombo.currentIndex = index
                                        }
395
                                    }
Jacob Walser's avatar
Jacob Walser committed
396 397 398 399 400

                                    Connections {
                                        target: joystickManager
                                        onAvailableJoysticksChanged: {
                                            var index = joystickCombo.find(joystickManager.activeJoystickName)
401
                                            if (index >= 0) {
Jacob Walser's avatar
Jacob Walser committed
402 403 404 405
                                                joystickCombo.currentIndex = index
                                            }
                                        }
                                    }
406
                                }
407 408
                            }

Don Gagne's avatar
Don Gagne committed
409 410
                            Column {
                                spacing: ScreenTools.defaultFontPixelHeight / 3
411
                                visible: activeVehicle.supportsThrottleModeCenterZero
412

Don Gagne's avatar
Don Gagne committed
413 414
                                QGCRadioButton {
                                    text:           qsTr("Center stick is zero throttle")
Gus Grubba's avatar
Gus Grubba committed
415
                                    checked:        _activeJoystick ? _activeJoystick.throttleMode === 0 : false
416

Don Gagne's avatar
Don Gagne committed
417 418
                                    onClicked: _activeJoystick.throttleMode = 0
                                }
419

420
                                Row {
Gregory Dymarek's avatar
Gregory Dymarek committed
421
                                    x:          20
422 423
                                    width:      parent.width
                                    spacing:    ScreenTools.defaultFontPixelWidth
Gus Grubba's avatar
Gus Grubba committed
424
                                    visible:    _activeJoystick ? _activeJoystick.throttleMode === 0 : false
425 426 427

                                    QGCCheckBox {
                                        id:         accumulator
428
                                        checked:    _activeJoystick ? _activeJoystick.accumulator : false
Gregory Dymarek's avatar
Gregory Dymarek committed
429
                                        text:       qsTr("Spring loaded throttle smoothing")
430 431 432 433 434

                                        onClicked:  _activeJoystick.accumulator = checked
                                    }
                                }

Don Gagne's avatar
Don Gagne committed
435 436
                                QGCRadioButton {
                                    text:           qsTr("Full down stick is zero throttle")
Gus Grubba's avatar
Gus Grubba committed
437
                                    checked:        _activeJoystick ? _activeJoystick.throttleMode === 1 : false
438

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

                                QGCCheckBox {
443
                                    visible:        activeVehicle.supportsNegativeThrust
444 445
                                    id:             negativeThrust
                                    text:           qsTr("Allow negative Thrust")
446
                                    enabled:        _activeJoystick.negativeThrust = activeVehicle.supportsNegativeThrust
447
                                    checked:        _activeJoystick ? _activeJoystick.negativeThrust : false
448
                                    onClicked:      _activeJoystick.negativeThrust = checked
449
                                }
450 451
                            }

Don Gagne's avatar
Don Gagne committed
452 453
                            Column {
                                spacing: ScreenTools.defaultFontPixelHeight / 3
454

455 456 457 458 459 460 461 462 463 464 465
                                QGCLabel {
                                    id:                 expoSliderLabel
                                    text:               qsTr("Exponential:")
                                }

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

nanthony21's avatar
nanthony21 committed
466 467
                                        Component.onCompleted: value=-_activeJoystick.exponential
                                        onValueChanged: _activeJoystick.exponential=-value
468 469 470 471 472
                                     }

                                    QGCLabel {
                                        id:     expoSliderIndicator
                                        text:   expoSlider.value.toFixed(2)
473
                                    }
Don Gagne's avatar
Don Gagne committed
474
                                }
475 476
                            }

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

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

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

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

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

506
                                    onActivated: activeVehicle.joystickMode = index
Don Gagne's avatar
Don Gagne committed
507
                                }
508
                            }
509

510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
                            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)
                                    }
                                }
                            }

528 529 530 531 532 533
                            Row {
                                width:      parent.width
                                spacing:    ScreenTools.defaultFontPixelWidth
                                visible:    advancedSettings.checked
                                QGCCheckBox {
                                    id:         joystickCircleCorrection
Gus Grubba's avatar
Gus Grubba committed
534
                                    checked:    activeVehicle.joystickMode !== 0
535 536 537 538 539 540 541 542 543
                                    text:       qsTr("Enable circle correction")

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

544 545 546 547 548 549 550 551 552 553 554 555 556
                            Row {
                                width:      parent.width
                                spacing:    ScreenTools.defaultFontPixelWidth
                                visible:    advancedSettings.checked

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

                                    onClicked:  controller.deadbandToggle = checked
                                }
                            }
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571
                            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
                                }
                            }
572
                        }
Don Gagne's avatar
Don Gagne committed
573
                    } // Column - left column
574

Don Gagne's avatar
Don Gagne committed
575 576 577 578
                    // Right column settings
                    Column {
                        width:      parent.width / 2
                        spacing:    ScreenTools.defaultFontPixelHeight
579

Don Gagne's avatar
Don Gagne committed
580 581
                        Connections {
                            target: _activeJoystick
582

Don Gagne's avatar
Don Gagne committed
583 584 585 586 587 588 589
                            onRawButtonPressedChanged: {
                                if (buttonActionRepeater.itemAt(index)) {
                                    buttonActionRepeater.itemAt(index).pressed = pressed
                                }
                                if (jsButtonActionRepeater.itemAt(index)) {
                                    jsButtonActionRepeater.itemAt(index).pressed = pressed
                                }
590
                            }
591 592
                        }

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

Don Gagne's avatar
Don Gagne committed
595 596 597
                        Column {
                            width:      parent.width
                            spacing:    ScreenTools.defaultFontPixelHeight / 3
598

Don Gagne's avatar
Don Gagne committed
599 600
                            Repeater {
                                id:     buttonActionRepeater
dheideman's avatar
dheideman committed
601
                                model:  _activeJoystick ? Math.min(_activeJoystick.totalButtonCount, _maxButtons) : 0
602

Don Gagne's avatar
Don Gagne committed
603 604
                                Row {
                                    spacing: ScreenTools.defaultFontPixelWidth
605
                                    visible: !activeVehicle.supportsJSButton
606

Don Gagne's avatar
Don Gagne committed
607
                                    property bool pressed
608

Don Gagne's avatar
Don Gagne committed
609 610
                                    QGCCheckBox {
                                        anchors.verticalCenter:     parent.verticalCenter
Gus Grubba's avatar
Gus Grubba committed
611
                                        checked:                    _activeJoystick ? _activeJoystick.buttonActions[modelData] !== "" : false
612

Don Gagne's avatar
Don Gagne committed
613 614
                                        onClicked: _activeJoystick.setButtonAction(modelData, checked ? buttonActionCombo.textAt(buttonActionCombo.currentIndex) : "")
                                    }
615

Don Gagne's avatar
Don Gagne committed
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631
                                    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
                                        }
632 633
                                    }

Don Gagne's avatar
Don Gagne committed
634 635 636
                                    QGCComboBox {
                                        id:             buttonActionCombo
                                        width:          ScreenTools.defaultFontPixelWidth * 20
637
                                        model:          _activeJoystick ? _activeJoystick.actions : 0
638

Don Gagne's avatar
Don Gagne committed
639 640 641
                                        onActivated:            _activeJoystick.setButtonAction(modelData, textAt(index))
                                        Component.onCompleted:  currentIndex = find(_activeJoystick.buttonActions[modelData])
                                    }
642
                                }
Don Gagne's avatar
Don Gagne committed
643
                            } // Repeater
644 645 646

                            Row {
                                spacing: ScreenTools.defaultFontPixelWidth
647
                                visible: activeVehicle.supportsJSButton
648

Don Gagne's avatar
Don Gagne committed
649 650 651 652
                                QGCLabel {
                                    horizontalAlignment:    Text.AlignHCenter
                                    width:                  ScreenTools.defaultFontPixelHeight * 1.5
                                    text:                   qsTr("#")
653 654
                                }

Don Gagne's avatar
Don Gagne committed
655 656 657
                                QGCLabel {
                                    width:                  ScreenTools.defaultFontPixelWidth * 15
                                    text:                   qsTr("Function: ")
658 659
                                }

Don Gagne's avatar
Don Gagne committed
660 661 662
                                QGCLabel {
                                    width:                  ScreenTools.defaultFontPixelWidth * 15
                                    text:                   qsTr("Shift Function: ")
663 664
                                }
                            } // Row
665

Don Gagne's avatar
Don Gagne committed
666 667
                            Repeater {
                                id:     jsButtonActionRepeater
dheideman's avatar
dheideman committed
668
                                model:  _activeJoystick ? Math.min(_activeJoystick.totalButtonCount, _maxButtons) : 0
Don Gagne's avatar
Don Gagne committed
669 670 671

                                Row {
                                    spacing: ScreenTools.defaultFontPixelWidth
672
                                    visible: activeVehicle.supportsJSButton
Don Gagne's avatar
Don Gagne committed
673 674 675 676 677 678 679 680 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

                                    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
715
            Column {
Don Gagne's avatar
Don Gagne committed
716 717 718
                id:             rightColumn
                anchors.top:    parent.top
                anchors.right:  parent.right
719
                width:          Math.min(joystickPage.ScreenTools.defaultFontPixelWidth * 35, availableWidth * 0.4)
720 721 722 723 724 725 726 727 728 729 730 731
                spacing:        ScreenTools.defaultFontPixelHeight / 2

                Row {
                    spacing: ScreenTools.defaultFontPixelWidth

                    QGCLabel {
                        text: "TX Mode:"
                    }

                    QGCRadioButton {
                        text:           "1"
                        checked:        controller.transmitterMode == 1
732
                        enabled:        !controller.calibrating
733 734 735 736 737 738 739

                        onClicked: controller.transmitterMode = 1
                    }

                    QGCRadioButton {
                        text:           "2"
                        checked:        controller.transmitterMode == 2
740
                        enabled:        !controller.calibrating
741 742 743 744 745 746 747

                        onClicked: controller.transmitterMode = 2
                    }

                    QGCRadioButton {
                        text:           "3"
                        checked:        controller.transmitterMode == 3
748
                        enabled:        !controller.calibrating
749 750 751 752 753 754 755

                        onClicked: controller.transmitterMode = 3
                    }

                    QGCRadioButton {
                        text:           "4"
                        checked:        controller.transmitterMode == 4
756
                        enabled:        !controller.calibrating
757 758 759 760

                        onClicked: controller.transmitterMode = 4
                    }
                }
Don Gagne's avatar
Don Gagne committed
761 762

                Image {
763
                    width:      parent.width
Don Gagne's avatar
Don Gagne committed
764 765 766 767
                    fillMode:   Image.PreserveAspectFit
                    smooth:     true
                    source:     controller.imageHelp
                }
768

Don Gagne's avatar
Don Gagne committed
769 770 771 772
                // Axis monitor
                Column {
                    width:      parent.width
                    spacing:    5
773

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

Don Gagne's avatar
Don Gagne committed
776 777 778 779 780 781 782
                    Connections {
                        target: controller

                        onAxisValueChanged: {
                            if (axisMonitorRepeater.itemAt(axis)) {
                                axisMonitorRepeater.itemAt(axis).loader.item.axisValue = value
                            }
783
                        }
784 785 786 787 788 789

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

Don Gagne's avatar
Don Gagne committed
792 793
                    Repeater {
                        id:     axisMonitorRepeater
794
                        model:  _activeJoystick ? _activeJoystick.axisCount : 0
Don Gagne's avatar
Don Gagne committed
795
                        width:  parent.width
796

Don Gagne's avatar
Don Gagne committed
797 798
                        Row {
                            spacing:    5
799

Don Gagne's avatar
Don Gagne committed
800 801
                            // Need this to get to loader from Connections above
                            property Item loader: theLoader
802

Don Gagne's avatar
Don Gagne committed
803 804 805 806
                            QGCLabel {
                                id:     axisLabel
                                text:   modelData
                            }
807

Don Gagne's avatar
Don Gagne committed
808 809 810 811 812 813
                            Loader {
                                id:                     theLoader
                                anchors.verticalCenter: axisLabel.verticalCenter
                                height:                 ScreenTools.defaultFontPixelHeight
                                width:                  200
                                sourceComponent:        axisMonitorDisplayComponent
814
                                Component.onCompleted:  item.narrowIndicator = true
Don Gagne's avatar
Don Gagne committed
815 816 817

                                property bool mapped:               true
                                readonly property bool reversed:    false
818 819 820


                                MouseArea {
821 822 823 824
                                    id:                 deadbandMouseArea
                                    anchors.fill:       parent.item
                                    enabled:            controller.deadbandToggle
                                    preventStealing:    true
825

826 827
                                    property real startX
                                    property real direction
828 829

                                    onPressed: {
830 831
                                        startX = mouseX
                                        direction = startX > width/2 ? 1 : -1
832
                                        parent.item.deadbandColor = "#3C6315"
833 834
                                    }
                                    onPositionChanged: {
835 836
                                        var mouseToDeadband = 32768/(width/2) // Factor to have deadband follow the mouse movement
                                        var newValue = parent.item.deadbandValue + direction*(mouseX - startX)*mouseToDeadband
837
                                        if ((newValue > 0) && (newValue <32768)){parent.item.deadbandValue=newValue;}
838
                                        startX = mouseX
839 840 841
                                    }
                                    onReleased: {
                                        controller.setDeadbandValue(modelData,parent.item.deadbandValue)
842
                                        parent.item.deadbandColor = "#8c161a"
843 844
                                    }
                                }
Don Gagne's avatar
Don Gagne committed
845
                            }
846

847 848
                        }
                    }
Don Gagne's avatar
Don Gagne committed
849
                } // Column - Axis Monitor
850

Don Gagne's avatar
Don Gagne committed
851 852 853 854
                // Button monitor
                Column {
                    width:      parent.width
                    spacing:    ScreenTools.defaultFontPixelHeight
855

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

Don Gagne's avatar
Don Gagne committed
858 859
                    Connections {
                        target: _activeJoystick
860

Don Gagne's avatar
Don Gagne committed
861 862 863 864
                        onRawButtonPressedChanged: {
                            if (buttonMonitorRepeater.itemAt(index)) {
                                buttonMonitorRepeater.itemAt(index).pressed = pressed
                            }
865 866 867
                        }
                    }

Don Gagne's avatar
Don Gagne committed
868 869 870
                    Flow {
                        width:      parent.width
                        spacing:    -1
871

Don Gagne's avatar
Don Gagne committed
872 873
                        Repeater {
                            id:     buttonMonitorRepeater
874
                            model:  _activeJoystick ? _activeJoystick.totalButtonCount : 0
875

Don Gagne's avatar
Don Gagne committed
876 877 878 879 880 881
                            Rectangle {
                                width:          ScreenTools.defaultFontPixelHeight * 1.2
                                height:         width
                                border.width:   1
                                border.color:   qgcPal.text
                                color:          pressed ? qgcPal.buttonHighlight : qgcPal.button
882

Don Gagne's avatar
Don Gagne committed
883
                                property bool pressed
884

Don Gagne's avatar
Don Gagne committed
885 886 887 888 889 890 891
                                QGCLabel {
                                    anchors.fill:           parent
                                    color:                  pressed ? qgcPal.buttonHighlightText : qgcPal.buttonText
                                    horizontalAlignment:    Text.AlignHCenter
                                    verticalAlignment:      Text.AlignVCenter
                                    text:                   modelData
                                }
892
                            }
Don Gagne's avatar
Don Gagne committed
893 894 895 896 897 898 899
                        } // Repeater
                    } // Row
                } // Column - Axis Monitor
            } // Column - Right Column
        } // Item
    } // Component - pageComponent
} // SetupPage
Gregory Dymarek's avatar
Gregory Dymarek committed
900 901