QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
CalcVoltageDividerDialog.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Layouts
4
5import QGroundControl.FactControls
6import QGroundControl.Controls
7
8QGCPopupDialog {
9 id: popupDialog
10 title: qsTr("Calculate Voltage Divider")
11 buttons: Dialog.Close
12
13 property int batteryIndex: 1
14 property var _controller: controller
15 property var _batteryFactGroup: controller.vehicle.getFactGroup("battery" + (batteryIndex - 1))
16
17 BatteryParams {
18 id: batParams
19 controller: _controller
20 batteryIndex: popupDialog.batteryIndex
21 }
22
23 ColumnLayout {
24 spacing: ScreenTools.defaultFontPixelHeight
25
26 QGCLabel {
27 Layout.preferredWidth: gridLayout.width
28 wrapMode: Text.WordWrap
29 text: qsTr("Measure battery voltage using an external voltmeter and enter the value below. Click Calculate to set the new voltage multiplier.")
30 }
31
32 GridLayout {
33 id: gridLayout
34 columns: 2
35
36 QGCLabel { text: qsTr("Measured voltage:") }
37 QGCTextField { id: measuredVoltage; numericValuesOnly: true }
38
39 QGCLabel { text: qsTr("Vehicle voltage:") }
40 QGCLabel { text: _batteryFactGroup.voltage.valueString }
41
42 QGCLabel { text: qsTr("Voltage divider:") }
43 FactLabel { fact: batParams.battVoltageDivider }
44 }
45
46 QGCButton {
47 text: qsTr("Calculate")
48
49 onClicked: {
50 var measuredVoltageValue = parseFloat(measuredVoltage.text)
51 if (measuredVoltageValue === 0 || isNaN(measuredVoltageValue)) {
52 return
53 }
54 var newVoltageDivider = (measuredVoltageValue * batParams.battVoltageDivider.value) / _batteryFactGroup.voltage.value
55 if (newVoltageDivider > 0) {
56 batParams.battVoltageDivider.value = newVoltageDivider
57 }
58 }
59 }
60 }
61}