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


11 12
import QtQuick                      2.3
import QtQuick.Controls             1.2
13
import QtQuick.Controls.Styles      1.4
14
import QtQuick.Layouts              1.2
15 16 17 18 19 20 21 22
import QtGraphicalEffects           1.0

import QGroundControl               1.0
import QGroundControl.FactSystem    1.0
import QGroundControl.FactControls  1.0
import QGroundControl.Controls      1.0
import QGroundControl.ScreenTools   1.0

23 24 25
SetupPage {
    id:             cameraPage
    pageComponent:  pageComponent
26

27 28
    Component {
        id: pageComponent
29

30 31 32
        Item {
            width:  Math.max(availableWidth, innerColumn.width)
            height: innerColumn.height
33

34
            FactPanelController { id: controller; factPanel: cameraPage.viewPanel }
35

36
            property real _margins:         ScreenTools.defaultFontPixelHeight
37
            property real _editFieldWidth:  ScreenTools.defaultFontPixelWidth * 25
38

39 40 41 42
            property Fact _camTriggerMode:      controller.getParameterFact(-1, "TRIG_MODE")
            property Fact _camTriggerInterface: controller.getParameterFact(-1, "TRIG_INTERFACE", false /* reportMissing */)
            property Fact _camTriggerPol:       controller.getParameterFact(-1, "TRIG_POLARITY", false /* reportMissing */)
            property Fact _auxPins:             controller.getParameterFact(-1, "TRIG_PINS", false /* reportMissing */)
43

44 45
            property bool _rebooting:       false
            property var  _auxChannels:     [ 0, 0, 0, 0, 0, 0]
46

47 48 49
            function clearAuxArray() {
                for(var i = 0; i < 6; i++) {
                    _auxChannels[i] = 0
dogmaphobic's avatar
dogmaphobic committed
50
                }
51 52
            }

53 54 55 56 57 58 59 60 61
            function setAuxPins() {
                if(_auxPins) {
                    var values = ""
                    for(var i = 0; i < 6; i++) {
                        if(_auxChannels[i]) {
                            values += ((i+1).toString())
                        }
                    }
                    _auxPins.value = parseInt(values)
62 63 64
                }
            }

65 66 67 68 69 70 71 72 73 74 75
            Component.onCompleted: {
                if(_auxPins) {
                    clearAuxArray()
                    var values  = _auxPins.value.toString()
                    for(var i = 0; i < values.length; i++) {
                        var b = parseInt(values[i]) - 1
                        if(b >= 0 && b < 6) {
                            _auxChannels[b] = 1
                        }
                    }
                }
76
            }
77

78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
            ColumnLayout {
                id:                         innerColumn
                anchors.horizontalCenter:   parent.horizontalCenter

                RowLayout {
                    id:         applyAndRestart
                    spacing:    _margins
                    visible:    false

                    QGCLabel {
                        text: qsTr("Vehicle must be restarted for changes to take effect.")
                    }
                    QGCButton {
                        text: qsTr("Apply and Restart")
                        onClicked:      {
                            //-- This will reboot the vehicle! We're set not to allow changes if armed.
                            QGroundControl.multiVehicleManager.activeVehicle.rebootVehicle()
                            applyAndRestart.visible = false
                            _rebooting = true
                        }
98
                    }
99
                }
100

101 102 103 104 105 106 107 108 109 110
                QGCGroupBox {
                    title:              qsTr("Camera Trigger Settings")
                    Layout.fillWidth:   true

                    GridLayout {
                        id:             cameraTrggerGrid
                        rows:           4
                        columns:        3
                        columnSpacing:  ScreenTools.defaultFontPixelWidth

111
                        QGCColoredImage {
112 113 114 115 116 117 118 119 120
                            id:                 triggerImage
                            color:              qgcPal.text
                            height:             ScreenTools.defaultFontPixelWidth * 10
                            width:              ScreenTools.defaultFontPixelWidth * 20
                            sourceSize.width:   width
                            mipmap:             true
                            fillMode:           Image.PreserveAspectFit
                            source:             "/qmlimages/CameraTrigger.svg"
                            Layout.rowSpan:     4
121
                        }
122 123 124 125 126 127 128 129 130 131 132 133 134

                        QGCLabel {
                            anchors.baseline:   camTrigCombo.baseline
                            text:               qsTr("Trigger mode")
                        }
                        FactComboBox {
                            id:                 camTrigCombo
                            fact:               _camTriggerMode
                            indexModel:         false
                            enabled:            !_rebooting
                            Layout.minimumWidth: _editFieldWidth
                            onActivated: {
                                applyAndRestart.visible = true
135
                            }
136 137 138 139 140 141 142 143 144 145 146 147 148 149
                        }

                        QGCLabel {
                            anchors.baseline:   camInterfaceCombo.baseline
                            text:               qsTr("Trigger interface")
                        }
                        FactComboBox {
                            id:                 camInterfaceCombo
                            fact:               _camTriggerInterface
                            indexModel:         false
                            enabled:            !_rebooting && (_camTriggerInterface ? true : false)
                            Layout.minimumWidth: _editFieldWidth
                            onActivated: {
                                applyAndRestart.visible = true
150 151
                            }
                        }
152 153 154 155 156

                        QGCLabel {
                            text:               qsTr("Time Interval")
                            anchors.baseline:   timeIntervalField.baseline
                            color:              qgcPal.text
157
                            visible:            timeIntervalField.visible
158 159 160 161 162 163
                        }
                        FactTextField {
                            id:                 timeIntervalField
                            fact:               controller.getParameterFact(-1, "TRIG_INTERVAL", false)
                            showUnits:          true
                            Layout.minimumWidth: _editFieldWidth
164
                            visible:            _camTriggerMode.value === 2
165 166 167 168 169 170
                        }

                        QGCLabel {
                            text:               qsTr("Distance Interval")
                            anchors.baseline:   trigDistField.baseline
                            color:              qgcPal.text
171
                            visible:            trigDistField.visible
172 173 174 175 176 177
                        }
                        FactTextField {
                            id:                 trigDistField
                            fact:               controller.getParameterFact(-1, "TRIG_DISTANCE", false)
                            showUnits:          true
                            Layout.minimumWidth: _editFieldWidth
178
                            visible:            _camTriggerMode.value === 3
179
                        }
180
                    }
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
                } // QGCGroupBox - Camera Trigger

                QGCGroupBox {
                    title:              qsTr("Hardware Settings")
                    visible:            _auxPins
                    Layout.fillWidth:   true

                    RowLayout {
                        spacing: _margins

                        // Aux pin assignment
                        ColumnLayout {
                            spacing: _margins

                            QGCLabel {
                                horizontalAlignment:    Text.AlignHCenter
                                text:                   qsTr("AUX Pin Assignment")
                                Layout.minimumWidth:    triggerImage.width
                            }

                            Row {
                                spacing:                    _margins
                                anchors.horizontalCenter:   parent.horizontalCenter

                                GridLayout {
                                    rows: 2
                                    columns: 6

209
                                    Repeater {
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
                                        model: _auxChannels

                                        QGCLabel {
                                            horizontalAlignment:    Text.AlignHCenter
                                            text:                   model.index + 1
                                        }
                                    }
                                    Repeater {
                                        model: _auxChannels

                                        Rectangle {
                                            id:             auxPin
                                            width:          ScreenTools.defaultFontPixelWidth * 2
                                            height:         ScreenTools.defaultFontPixelWidth * 2
                                            border.color:   qgcPal.text
                                            color:  {
                                                if(_auxPins) {
                                                    var pins = _auxPins.value.toString()
                                                    var pin  = (model.index + 1).toString()
                                                    if(pins.indexOf(pin) < 0)
                                                        return qgcPal.windowShadeDark
                                                    else
                                                        return "green"
                                                } else {
                                                    return qgcPal.windowShade
dogmaphobic's avatar
dogmaphobic committed
235
                                                }
236 237 238 239 240 241 242
                                            }
                                            MouseArea {
                                                anchors.fill: parent
                                                onClicked: {
                                                    _auxChannels[model.index] = 1 - _auxChannels[model.index]
                                                    auxPin.color = _auxChannels[model.index] ? "green" : qgcPal.windowShadeDark
                                                    setAuxPins()
243 244 245 246 247 248
                                                }
                                            }
                                        }
                                    }
                                }
                            }
249 250 251 252 253 254 255 256 257
                        } // ColumnLayout - Aux pins

                        // Trigger Pin Setup
                        ColumnLayout {
                            visible:    !_camTriggerInterface || (_camTriggerInterface.value === 1)
                            spacing:    _margins * 0.5

                            QGCLabel { text: qsTr("Trigger Pin Polarity") }

258 259 260 261 262 263
                            Row {
                                Item { height: 1; width: _margins; }
                                Column {
                                    spacing:            _margins * 0.5
                                    ExclusiveGroup { id: polarityGroup }
                                    QGCRadioButton {
dogmaphobic's avatar
dogmaphobic committed
264
                                        checked:        _camTriggerPol && _camTriggerPol.value === 0
265 266
                                        exclusiveGroup: polarityGroup
                                        text:           "Low (0V)"
dogmaphobic's avatar
dogmaphobic committed
267 268 269 270 271
                                        onClicked: {
                                            if(_camTriggerPol) {
                                                _camTriggerPol.value = 0
                                            }
                                        }
272 273
                                    }
                                    QGCRadioButton {
dogmaphobic's avatar
dogmaphobic committed
274
                                        checked:        _camTriggerPol && _camTriggerPol.value > 0
275 276
                                        exclusiveGroup: polarityGroup
                                        text:           "High (3.3V)"
dogmaphobic's avatar
dogmaphobic committed
277 278 279 280 281
                                        onClicked: {
                                            if(_camTriggerPol) {
                                                _camTriggerPol.value = 1
                                            }
                                        }
282 283 284
                                    }
                                }
                            }
285

286
                            Row {
287 288
                                spacing: ScreenTools.defaultFontPixelWidth

289 290 291
                                QGCLabel {
                                    text:               qsTr("Trigger Period")
                                    anchors.baseline:   trigPeriodField.baseline
292
                                    color:              qgcPal.text
293 294 295
                                }
                                FactTextField {
                                    id:                 trigPeriodField
dogmaphobic's avatar
dogmaphobic committed
296
                                    fact:               controller.getParameterFact(-1, "TRIG_ACT_TIME", false)
297 298 299 300 301 302
                                    showUnits:          true
                                    width:              _editFieldWidth
                                }
                            }
                        }
                    }
303 304 305 306 307 308 309 310 311 312 313
                } // QGCGroupBox - Hardware Settings

                QGCGroupBox {
                    title:              qsTr("Camera Test")
                    Layout.fillWidth:   true

                    QGCButton {
                        anchors.horizontalCenter:   parent.horizontalCenter
                        text:                       qsTr("Trigger Camera")
                        onClicked:                  controller.vehicle.triggerCamera()
                    }
314 315 316 317 318
                }
            }
        }
    }
}