CameraComponent.qml 17.9 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34


import QtQuick                      2.5
import QtQuick.Controls             1.2
import QtQuick.Controls.Styles      1.2
import QtQuick.Layouts              1.2
import QtGraphicalEffects           1.0

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


QGCView {
    id:             _cameraView
    viewPanel:      panel
    anchors.fill:   parent

    FactPanelController { id: controller; factPanel: panel }

    QGCPalette { id: palette; colorGroupEnabled: enabled }

    property real _margins:         ScreenTools.defaultFontPixelHeight
35 36
    property real _middleRowWidth:  ScreenTools.defaultFontPixelWidth * 16
    property real _editFieldWidth:  ScreenTools.defaultFontPixelWidth * 16
37 38

    property Fact _camTriggerMode:  controller.getParameterFact(-1, "TRIG_MODE")
39
    property Fact _camTriggerInterface:  controller.getParameterFact(-1, "TRIG_INTERFACE", false)
dogmaphobic's avatar
dogmaphobic committed
40 41
    property Fact _camTriggerPol:   controller.getParameterFact(-1, "TRIG_POLARITY", false) // Don't bitch about missing as these only exist if trigger mode is enabled
    property Fact _auxPins:         controller.getParameterFact(-1, "TRIG_PINS",     false) // Ditto
42 43 44 45 46 47 48 49 50 51 52

    property bool _rebooting:       false
    property var  _auxChannels:     [ 0, 0, 0, 0, 0, 0]

    function clearAuxArray() {
        for(var i = 0; i < 6; i++) {
            _auxChannels[i] = 0
        }
    }

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

    Component.onCompleted: {
dogmaphobic's avatar
dogmaphobic committed
65
        if(_auxPins) {
66
            clearAuxArray()
dogmaphobic's avatar
dogmaphobic committed
67
            var values  = _auxPins.value.toString()
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
            for(var i = 0; i < values.length; i++) {
                var b = parseInt(values[i]) - 1
                if(b >= 0 && b < 6) {
                    _auxChannels[b] = 1
                }
            }
        }
    }

    QGCViewPanel {
        id:             panel
        anchors.fill:   parent
        Item {
            id:                     applyAndRestart
            visible:                false
            anchors.top:            parent.top
            anchors.left:           parent.left
            anchors.right:          parent.right
            anchors.leftMargin:     ScreenTools.defaultFontPixelWidth * 10
            anchors.rightMargin:    ScreenTools.defaultFontPixelWidth * 10
            height:                 applyButton.height
            QGCLabel {
                anchors.left:       parent.left
                text:               qsTr("Vehicle must be restarted for changes to take effect. ")
            }
            QGCButton {
                id:                 applyButton
                anchors.right:      parent.right
                text:               qsTr("Apply and Restart")
                onClicked:      {
dogmaphobic's avatar
dogmaphobic committed
98
                    //-- This will reboot the vehicle! We're set not to allow changes if armed.
99 100 101 102 103 104 105 106 107 108
                    QGroundControl.multiVehicleManager.activeVehicle.rebootVehicle()
                    applyAndRestart.visible = false
                    _rebooting = true
                }
            }
        }
        QGCFlickable {
            clip:                                       true
            anchors.top:                                applyAndRestart.visible ? applyAndRestart.bottom : parent.top
            anchors.bottom:                             parent.bottom
dogmaphobic's avatar
dogmaphobic committed
109 110
            anchors.left:                               parent.left
            anchors.right:                              parent.right
111 112 113 114 115
            contentHeight:                              mainCol.height
            flickableDirection:                         Flickable.VerticalFlick
            Column {
                id:                                     mainCol
                spacing:                                _margins
dogmaphobic's avatar
dogmaphobic committed
116
                anchors.horizontalCenter:               parent.horizontalCenter
117 118 119 120 121
                /*
                   **** Camera Trigger ****
                */
                QGCLabel {
                    text:                               qsTr("Camera Trigger Settings")
122
                    font.family:                        ScreenTools.demiboldFontFamily
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
                }
                Rectangle {
                    id:                                 camTrigRect
                    color:                              palette.windowShade
                    width:                              camTrigRow.width  + _margins * 2
                    height:                             camTrigRow.height + _margins * 2
                    Row {
                        id:                             camTrigRow
                        spacing:                        _margins
                        anchors.verticalCenter:         parent.verticalCenter
                        Item { width: _margins * 0.5; height: 1; }
                        QGCColoredImage {
                            color:                      palette.text
                            height:                     ScreenTools.defaultFontPixelWidth * 10
                            width:                      ScreenTools.defaultFontPixelWidth * 20
dogmaphobic's avatar
dogmaphobic committed
138
                            sourceSize.width:           width
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
                            mipmap:                     true
                            fillMode:                   Image.PreserveAspectFit
                            source:                     "/qmlimages/CameraTrigger.svg"
                            anchors.verticalCenter:     parent.verticalCenter
                        }
                        Item { width: _margins * 0.5; height: 1; }
                        Column {
                            spacing:                    _margins * 0.5
                            anchors.verticalCenter:     parent.verticalCenter
                            Row {
                                QGCLabel {
                                    anchors.baseline:   camTrigCombo.baseline
                                    width:              _middleRowWidth
                                    text:               qsTr("Trigger mode:")
                                }
                                FactComboBox {
                                    id:                 camTrigCombo
                                    width:              _editFieldWidth
                                    fact:               _camTriggerMode
                                    indexModel:         false
                                    enabled:            !_rebooting
                                    onActivated: {
                                        applyAndRestart.visible = true
                                    }
                                }
                            }
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
                            Row {
                                visible: _camTriggerInterface ? true : false
                                QGCLabel {
                                    anchors.baseline:   camInterfaceCombo.baseline
                                    width:              _middleRowWidth
                                    text:               qsTr("Trigger interface:")
                                }
                                FactComboBox {
                                    id:                 camInterfaceCombo
                                    width:              _editFieldWidth
                                    fact:               _camTriggerInterface
                                    indexModel:         false
                                    enabled:            !_rebooting
                                    onActivated: {
                                        applyAndRestart.visible = true
                                    }
                                }
                            }
183 184 185 186 187 188 189 190 191
                            Row {
                                QGCLabel {
                                    text:               qsTr("Time Interval")
                                    width:              _middleRowWidth
                                    anchors.baseline:   timeIntervalField.baseline
                                    color:              palette.text
                                }
                                FactTextField {
                                    id:                 timeIntervalField
dogmaphobic's avatar
dogmaphobic committed
192
                                    fact:               controller.getParameterFact(-1, "TRIG_INTERVAL", false)
193 194
                                    showUnits:          true
                                    width:              _editFieldWidth
dogmaphobic's avatar
dogmaphobic committed
195
                                    enabled:            _auxPins && _camTriggerMode.value === 2
196 197 198 199 200 201 202 203 204 205 206
                                }
                            }
                            Row {
                                QGCLabel {
                                    text:               qsTr("Distance Interval")
                                    width:              _middleRowWidth
                                    anchors.baseline:   trigDistField.baseline
                                    color:              palette.text
                                }
                                FactTextField {
                                    id:                 trigDistField
dogmaphobic's avatar
dogmaphobic committed
207
                                    fact:               controller.getParameterFact(-1, "TRIG_DISTANCE", false)
208 209
                                    showUnits:          true
                                    width:              _editFieldWidth
dogmaphobic's avatar
dogmaphobic committed
210
                                    enabled:            _auxPins && _camTriggerMode.value === 3
211 212 213 214 215 216 217 218 219 220 221
                                }
                            }
                        }
                    }
                }
                /*
                   **** Camera Hardware ****
                */
                Item { width: 1; height: _margins * 0.5; }
                QGCLabel {
                    text:                               qsTr("Hardware Settings")
222
                    font.family:                        ScreenTools.demiboldFontFamily
dogmaphobic's avatar
dogmaphobic committed
223
                    visible:                            _auxPins
224 225 226 227 228
                }
                Rectangle {
                    color:                              palette.windowShade
                    width:                              camTrigRect.width
                    height:                             camHardwareRow.height + _margins * 2
dogmaphobic's avatar
dogmaphobic committed
229
                    visible:                            _auxPins
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
                    Row {
                        id:                             camHardwareRow
                        spacing:                        _margins
                        anchors.verticalCenter:         parent.verticalCenter
                        Item { width: _margins * 0.5; height: 1; }
                        Item {
                            height:                     ScreenTools.defaultFontPixelWidth * 10
                            width:                      ScreenTools.defaultFontPixelWidth * 20
                            Column {
                                spacing:                ScreenTools.defaultFontPixelHeight
                                anchors.centerIn:       parent
                                QGCLabel {
                                    text:               "AUX Pin Assignment"
                                    anchors.horizontalCenter: parent.horizontalCenter
                                }
                                Row {
                                    spacing:            ScreenTools.defaultFontPixelWidth
                                    anchors.horizontalCenter: parent.horizontalCenter
                                    Repeater {
                                        model:          _auxChannels
                                        Column {
                                            spacing:            ScreenTools.defaultFontPixelWidth * 0.5
                                            QGCLabel {
                                                text:           model.index + 1
                                                color:          palette.text
                                                anchors.horizontalCenter: parent.horizontalCenter
                                            }
                                            Rectangle {
                                                id:             auxPin
                                                width:          ScreenTools.defaultFontPixelWidth * 2
                                                height:         ScreenTools.defaultFontPixelWidth * 2
                                                border.color:   palette.text
dogmaphobic's avatar
dogmaphobic committed
262 263 264 265 266 267 268 269 270 271 272 273
                                                color:  {
                                                    if(_auxPins) {
                                                        var pins = _auxPins.value.toString()
                                                        var pin  = (model.index + 1).toString()
                                                        if(pins.indexOf(pin) < 0)
                                                            return palette.windowShadeDark
                                                        else
                                                            return "green"
                                                    } else {
                                                        return palette.windowShade
                                                    }
                                                }
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
                                                MouseArea {
                                                    anchors.fill: parent
                                                    onClicked: {
                                                        _auxChannels[model.index] = 1 - _auxChannels[model.index]
                                                        auxPin.color = _auxChannels[model.index] ? "green" : palette.windowShadeDark
                                                        setAuxPins()
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        Item { width: _margins * 0.5; height: 1; }
                        Column {
290
                            visible:                    !_camTriggerInterface || (_camTriggerInterface.value === 1)
291 292 293 294 295 296 297 298 299 300 301 302
                            spacing:                    _margins * 0.5
                            anchors.verticalCenter:     parent.verticalCenter
                            QGCLabel {
                                id:                     returnHomeLabel
                                text:                   "Trigger Pin Polarity:"
                            }
                            Row {
                                Item { height: 1; width: _margins; }
                                Column {
                                    spacing:            _margins * 0.5
                                    ExclusiveGroup { id: polarityGroup }
                                    QGCRadioButton {
dogmaphobic's avatar
dogmaphobic committed
303
                                        checked:        _camTriggerPol && _camTriggerPol.value === 0
304 305
                                        exclusiveGroup: polarityGroup
                                        text:           "Low (0V)"
dogmaphobic's avatar
dogmaphobic committed
306 307 308 309 310
                                        onClicked: {
                                            if(_camTriggerPol) {
                                                _camTriggerPol.value = 0
                                            }
                                        }
311 312
                                    }
                                    QGCRadioButton {
dogmaphobic's avatar
dogmaphobic committed
313
                                        checked:        _camTriggerPol && _camTriggerPol.value > 0
314 315
                                        exclusiveGroup: polarityGroup
                                        text:           "High (3.3V)"
dogmaphobic's avatar
dogmaphobic committed
316 317 318 319 320
                                        onClicked: {
                                            if(_camTriggerPol) {
                                                _camTriggerPol.value = 1
                                            }
                                        }
321 322 323
                                    }
                                }
                            }
dogmaphobic's avatar
dogmaphobic committed
324
                            Item { width: 1; height: _margins * 0.5; }
325 326 327 328 329 330 331 332 333
                            Row {
                                QGCLabel {
                                    text:               qsTr("Trigger Period")
                                    width:              _middleRowWidth
                                    anchors.baseline:   trigPeriodField.baseline
                                    color:              palette.text
                                }
                                FactTextField {
                                    id:                 trigPeriodField
dogmaphobic's avatar
dogmaphobic committed
334
                                    fact:               controller.getParameterFact(-1, "TRIG_ACT_TIME", false)
335 336 337 338 339 340 341 342 343 344 345 346
                                    showUnits:          true
                                    width:              _editFieldWidth
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}