FirmwareUpgrade.qml 17.1 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.Dialogs 1.2
15

Don Gagne's avatar
Don Gagne committed
16 17 18 19 20 21 22
import QGroundControl               1.0
import QGroundControl.Controls      1.0
import QGroundControl.FactSystem    1.0
import QGroundControl.FactControls  1.0
import QGroundControl.Palette       1.0
import QGroundControl.Controllers   1.0
import QGroundControl.ScreenTools   1.0
23

24
QGCView {
25 26 27
    id:         qgcView
    viewPanel:  panel

Tomaz Canabrava's avatar
Tomaz Canabrava committed
28 29 30 31
    // Those user visible strings are hard to translate because we can't send the
    // HTML strings to translation as this can create a security risk. we need to find
    // a better way to hightlight them, or use less hightlights.

32
    // User visible strings
Don Gagne's avatar
Don Gagne committed
33
    readonly property string title:             "FIRMWARE"
dogmaphobic's avatar
dogmaphobic committed
34
    readonly property string highlightPrefix:   "<font color=\"" + qgcPal.warningText + "\">"
35
    readonly property string highlightSuffix:   "</font>"
36
    readonly property string welcomeText:       qsTr("%1 can upgrade the firmware on Pixhawk devices, SiK Radios and PX4 Flow Smart Cameras.").arg(QGroundControl.appName)
37
    readonly property string plugInText:        "<big>" + highlightPrefix + "Plug in your device" + highlightSuffix + " via USB to " + highlightPrefix + "start" + highlightSuffix + " firmware upgrade.</big>"
38 39
    readonly property string flashFailText:     "If upgrade failed, make sure to connect " + highlightPrefix + "directly" + highlightSuffix + " to a powered USB port on your computer, not through a USB hub. " +
                                                "Also make sure you are only powered via USB " + highlightPrefix + "not battery" + highlightSuffix + "."
40
    readonly property string qgcUnplugText1:    qsTr("All %1 connections to vehicles must be ").arg(QGroundControl.appName) + highlightPrefix + " disconnected " + highlightSuffix + "prior to firmware upgrade."
Don Gagne's avatar
Don Gagne committed
41
    readonly property string qgcUnplugText2:    highlightPrefix + "<big>Please unplug your Pixhawk and/or Radio from USB.</big>" + highlightSuffix
42 43

    property string firmwareWarningMessage
44 45 46 47
    property bool   controllerCompleted:      false
    property bool   initialBoardSearch:       true
    property string firmwareName

48 49
    property bool _singleFirmwareMode: QGroundControl.corePlugin.options.firmwareUpgradeSingleURL.length != 0   ///< true: running in special single firmware download mode

50
    function cancelFlash() {
Tomaz Canabrava's avatar
Tomaz Canabrava committed
51
        statusTextArea.append(highlightPrefix + qsTr("Upgrade cancelled") + highlightSuffix)
52 53 54
        statusTextArea.append("------------------------------------------")
        controller.cancel()
    }
55

Don Gagne's avatar
Don Gagne committed
56
    QGCPalette { id: qgcPal; colorGroupEnabled: true }
57

58 59 60 61
    FirmwareUpgradeController {
        id:             controller
        progressBar:    progressBar
        statusLog:      statusTextArea
62

63 64
        property var activeVehicle: QGroundControl.multiVehicleManager.activeVehicle

65 66 67 68 69 70 71 72
        Component.onCompleted: {
            controllerCompleted = true
            if (qgcView.completedSignalled) {
                // We can only start the board search when the Qml and Controller are completely done loading
                controller.startBoardSearch()
            }
        }

73 74 75 76 77 78
        onActiveVehicleChanged: {
            if (!activeVehicle) {
                statusTextArea.append(plugInText)
            }
        }

79 80
        onNoBoardFound: {
            initialBoardSearch = false
81 82 83
            if (!QGroundControl.multiVehicleManager.activeVehicleAvailable) {
                statusTextArea.append(plugInText)
            }
84
        }
dogmaphobic's avatar
dogmaphobic committed
85

86 87
        onBoardGone: {
            initialBoardSearch = false
88 89 90
            if (!QGroundControl.multiVehicleManager.activeVehicleAvailable) {
                statusTextArea.append(plugInText)
            }
91
        }
dogmaphobic's avatar
dogmaphobic committed
92

93 94 95
        onBoardFound: {
            if (initialBoardSearch) {
                // Board was found right away, so something is already plugged in before we've started upgrade
Don Gagne's avatar
Don Gagne committed
96 97
                statusTextArea.append(qgcUnplugText1)
                statusTextArea.append(qgcUnplugText2)
98
                QGroundControl.multiVehicleManager.activeVehicle.autoDisconnect = true
99 100
            } else {
                // We end up here when we detect a board plugged in after we've started upgrade
Tomaz Canabrava's avatar
Tomaz Canabrava committed
101
                statusTextArea.append(highlightPrefix + qsTr("Found device") + highlightSuffix + ": " + controller.boardType)
102
                if (controller.pixhawkBoard || controller.px4FlowBoard) {
103
                    showDialog(pixhawkFirmwareSelectDialogComponent, title, qgcView.showDialogDefaultWidth, StandardButton.Ok | StandardButton.Cancel)
104 105 106
                }
            }
        }
107 108 109

        onError: {
            hideDialog()
110
            statusTextArea.append(flashFailText)
111
        }
112
    }
Don Gagne's avatar
Don Gagne committed
113

114 115 116 117 118 119
    onCompleted: {
        if (controllerCompleted) {
            // We can only start the board search when the Qml and Controller are completely done loading
            controller.startBoardSearch()
        }
    }
120

121
    Component {
122
        id: pixhawkFirmwareSelectDialogComponent
123

124
        QGCViewDialog {
125 126 127 128
            id:             pixhawkFirmwareSelectDialog
            anchors.fill:   parent

            property bool showFirmwareTypeSelection:    _advanced.checked
129
            property bool px4Flow:                      controller.px4FlowBoard
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146

            function updatePX4VersionDisplay() {
                var versionString = ""
                if (_advanced.checked) {
                    switch (controller.selectedFirmwareType) {
                    case FirmwareUpgradeController.StableFirmware:
                        versionString = controller.px4StableVersion
                        break
                    case FirmwareUpgradeController.BetaFirmware:
                        versionString = controller.px4BetaVersion
                        break
                    }
                } else {
                    versionString = controller.px4StableVersion
                }
                px4FlightStack.text = qsTr("PX4 Flight Stack ") + versionString
            }
dogmaphobic's avatar
dogmaphobic committed
147

148
            Component.onCompleted: updatePX4VersionDisplay()
149

150 151
            function accept() {
                hideDialog()
152 153 154 155 156 157 158
                if (_singleFirmwareMode) {
                    controller.flashSingleFirmwareMode()
                } else {
                    var stack = apmFlightStack.checked ? FirmwareUpgradeController.AutoPilotStackAPM : FirmwareUpgradeController.AutoPilotStackPX4
                    if (px4Flow) {
                        stack = FirmwareUpgradeController.PX4Flow
                    }
159

160 161 162 163 164 165
                    var firmwareType = firmwareVersionCombo.model.get(firmwareVersionCombo.currentIndex).firmwareType
                    var vehicleType = FirmwareUpgradeController.DefaultVehicleFirmware
                    if (apmFlightStack.checked) {
                        vehicleType = controller.vehicleTypeFromVersionIndex(vehicleTypeSelectionCombo.currentIndex)
                    }
                    controller.flash(stack, firmwareType, vehicleType)
166
                }
167
            }
dogmaphobic's avatar
dogmaphobic committed
168

169 170
            function reject() {
                hideDialog()
171
                cancelFlash()
172
            }
dogmaphobic's avatar
dogmaphobic committed
173

174 175 176
            ExclusiveGroup {
                id: firmwareGroup
            }
dogmaphobic's avatar
dogmaphobic committed
177

178
            ListModel {
179
                id: firmwareTypeList
180 181

                ListElement {
Tomaz Canabrava's avatar
Tomaz Canabrava committed
182
                    text:           qsTr("Standard Version (stable)")
183
                    firmwareType:   FirmwareUpgradeController.StableFirmware
184 185
                }
                ListElement {
Tomaz Canabrava's avatar
Tomaz Canabrava committed
186
                    text:           qsTr("Beta Testing (beta)")
187
                    firmwareType:   FirmwareUpgradeController.BetaFirmware
188 189
                }
                ListElement {
Tomaz Canabrava's avatar
Tomaz Canabrava committed
190
                    text:           qsTr("Developer Build (master)")
191
                    firmwareType:   FirmwareUpgradeController.DeveloperFirmware
192 193
                }
                ListElement {
Tomaz Canabrava's avatar
Tomaz Canabrava committed
194
                    text:           qsTr("Custom firmware file...")
195
                    firmwareType:   FirmwareUpgradeController.CustomFirmware
196
                }
197
            }
dogmaphobic's avatar
dogmaphobic committed
198

199 200 201 202
            ListModel {
                id: px4FlowTypeList

                ListElement {
Tomaz Canabrava's avatar
Tomaz Canabrava committed
203
                    text:           qsTr("Standard Version (stable)")
204
                    firmwareType:   FirmwareUpgradeController.StableFirmware
205 206
                }
                ListElement {
Tomaz Canabrava's avatar
Tomaz Canabrava committed
207
                    text:           qsTr("Custom firmware file...")
208
                    firmwareType:   FirmwareUpgradeController.CustomFirmware
209
                }
210
            }
dogmaphobic's avatar
dogmaphobic committed
211

212 213 214 215 216 217 218 219 220 221 222 223 224
            ListModel {
                id: singleFirmwareModeTypeList

                ListElement {
                    text:           qsTr("Standard Version")
                    firmwareType:   FirmwareUpgradeController.StableFirmware
                }
                ListElement {
                    text:           qsTr("Custom firmware file...")
                    firmwareType:   FirmwareUpgradeController.CustomFirmware
                }
            }

225 226 227 228 229 230 231
            Column {
                anchors.fill:   parent
                spacing:        defaultTextHeight

                QGCLabel {
                    width:      parent.width
                    wrapMode:   Text.WordWrap
232 233 234 235 236
                    text:       _singleFirmwareMode ? _singleFirmwareLabel : (px4Flow ? _px4FlowLabel : _pixhawkLabel)

                    readonly property string _px4FlowLabel:          qsTr("Detected PX4 Flow board. You can select from the following firmware:")
                    readonly property string _pixhawkLabel:          qsTr("Detected Pixhawk board. You can select from the following flight stacks:")
                    readonly property string _singleFirmwareLabel:   qsTr("Press Ok to upgrade your vehicle.")
237
                }
238

239 240 241 242 243 244 245 246 247 248
                function firmwareVersionChanged(model) {
                    firmwareVersionWarningLabel.visible = false
                    // All of this bizarre, setting model to null and index to 1 and then to 0 is to work around
                    // strangeness in the combo box implementation. This sequence of steps correctly changes the combo model
                    // without generating any warnings and correctly updates the combo text with the new selection.
                    firmwareVersionCombo.model = null
                    firmwareVersionCombo.model = model
                    firmwareVersionCombo.currentIndex = 1
                    firmwareVersionCombo.currentIndex = 0
                }
249

250 251 252 253
                QGCRadioButton {
                    id:             px4FlightStack
                    checked:        true
                    exclusiveGroup: firmwareGroup
254
                    text:           qsTr("PX4 Flight Stack ")
255
                    visible:        !_singleFirmwareMode && !px4Flow
256

257
                    onClicked: parent.firmwareVersionChanged(firmwareTypeList)
258 259 260 261 262
                }

                QGCRadioButton {
                    id:             apmFlightStack
                    exclusiveGroup: firmwareGroup
Tomaz Canabrava's avatar
Tomaz Canabrava committed
263
                    text:           qsTr("ArduPilot Flight Stack")
264
                    visible:        !_singleFirmwareMode && !px4Flow
265

266
                    onClicked: parent.firmwareVersionChanged(firmwareTypeList)
267
                }
268

269
                QGCComboBox {
Don Gagne's avatar
Don Gagne committed
270 271 272 273 274
                    id:             vehicleTypeSelectionCombo
                    anchors.left:   parent.left
                    anchors.right:  parent.right
                    visible:        apmFlightStack.checked
                    model:          controller.apmAvailableVersions
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
                }

                Row {
                    width:      parent.width
                    spacing:    ScreenTools.defaultFontPixelWidth / 2
                    visible:    !px4Flow

                    Rectangle {
                        height: 1
                        width:      ScreenTools.defaultFontPixelWidth * 5
                        color:      qgcPal.text
                        anchors.verticalCenter: _advanced.verticalCenter
                    }

                    QGCCheckBox {
                        id:         _advanced
Tomaz Canabrava's avatar
Tomaz Canabrava committed
291
                        text:       qsTr("Advanced settings")
292 293 294 295 296
                        checked:    px4Flow ? true : false

                        onClicked: {
                            firmwareVersionCombo.currentIndex = 0
                            firmwareVersionWarningLabel.visible = false
297
                            updatePX4VersionDisplay()
298 299 300 301 302 303 304 305 306 307 308
                        }
                    }

                    Rectangle {
                        height:     1
                        width:      ScreenTools.defaultFontPixelWidth * 5
                        color:      qgcPal.text
                        anchors.verticalCenter: _advanced.verticalCenter
                    }
                }

309 310 311
                QGCLabel {
                    width:      parent.width
                    wrapMode:   Text.WordWrap
312
                    visible:    showFirmwareTypeSelection
Tomaz Canabrava's avatar
Tomaz Canabrava committed
313
                    text:       px4Flow ? qsTr("Select which version of the firmware you would like to install:") : qsTr("Select which version of the above flight stack you would like to install:")
314
                }
315

316 317
                QGCComboBox {
                    id:             firmwareVersionCombo
Don Gagne's avatar
Don Gagne committed
318 319
                    anchors.left:   parent.left
                    anchors.right:  parent.right
320
                    visible:        showFirmwareTypeSelection
321
                    model:          _singleFirmwareMode ? singleFirmwareModeTypeList: (px4Flow ? px4FlowTypeList : firmwareTypeList)
322 323 324 325 326 327
                    currentIndex:   controller.selectedFirmwareType

                    onActivated: {
                        controller.selectedFirmwareType = index
                        if (model.get(index).firmwareType == FirmwareUpgradeController.BetaFirmware) {
                            firmwareVersionWarningLabel.visible = true
Tomaz Canabrava's avatar
Tomaz Canabrava committed
328 329 330 331
                            firmwareVersionWarningLabel.text = qsTr("WARNING: BETA FIRMWARE. ") +
                                    qsTr("This firmware version is ONLY intended for beta testers. ") +
                                    qsTr("Although it has received FLIGHT TESTING, it represents actively changed code. ") +
                                    qsTr("Do NOT use for normal operation.")
332 333
                        } else if (model.get(index).firmwareType == FirmwareUpgradeController.DeveloperFirmware) {
                            firmwareVersionWarningLabel.visible = true
Tomaz Canabrava's avatar
Tomaz Canabrava committed
334 335 336 337
                            firmwareVersionWarningLabel.text = qsTr("WARNING: CONTINUOUS BUILD FIRMWARE. ") +
                                    qsTr("This firmware has NOT BEEN FLIGHT TESTED. ") +
                                    qsTr("It is only intended for DEVELOPERS. ") +
                                    qsTr("Run bench tests without props first. ") +
Ricardo de Almeida Gonzaga's avatar
Ricardo de Almeida Gonzaga committed
338
                                    qsTr("Do NOT fly this without additional safety precautions. ") +
Tomaz Canabrava's avatar
Tomaz Canabrava committed
339
                                    qsTr("Follow the mailing list actively when using it.")
340 341
                        } else {
                            firmwareVersionWarningLabel.visible = false
342
                        }
343
                        updatePX4VersionDisplay()
344 345
                    }
                }
346 347 348 349 350 351 352

                QGCLabel {
                    id:         firmwareVersionWarningLabel
                    width:      parent.width
                    wrapMode:   Text.WordWrap
                    visible:    false
                }
353
            } // Column
354
        } // QGCViewDialog
355
    } // Component - pixhawkFirmwareSelectDialogComponent
356 357 358 359 360 361

    Component {
        id: firmwareWarningDialog

        QGCViewMessage {
            message: firmwareWarningMessage
362

363 364 365
            function accept() {
                hideDialog()
                controller.doFirmwareUpgrade();
366
            }
367 368 369 370 371 372
        }
    }

    QGCViewPanel {
        id:             panel
        anchors.fill:   parent
373

374 375 376
        QGCLabel {
            id:             titleLabel
            text:           title
377
            font.pointSize: ScreenTools.mediumFontPointSize
378
        }
379

380 381 382 383 384 385
        ProgressBar {
            id:                 progressBar
            anchors.topMargin:  ScreenTools.defaultFontPixelHeight
            anchors.top:        titleLabel.bottom
            width:              parent.width
        }
386

387 388 389 390 391 392 393 394
        TextArea {
            id:                 statusTextArea
            anchors.topMargin:  ScreenTools.defaultFontPixelHeight
            anchors.top:        progressBar.bottom
            anchors.bottom:     parent.bottom
            width:              parent.width
            readOnly:           true
            frameVisible:       false
395
            font.pointSize:     ScreenTools.defaultFontPointSize
396 397 398 399 400 401
            textFormat:         TextEdit.RichText
            text:               welcomeText

            style: TextAreaStyle {
                textColor:          qgcPal.text
                backgroundColor:    qgcPal.windowShade
402
            }
403 404
        }
    } // QGCViewPabel
405
} // QGCView