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 title: qsTr("Calculate Voltage Divider")
10 buttons: Dialog.Close
11
12 property int batteryIndex: 1
13 property var _controller: controller
14 property var _batteryFactGroup: controller.vehicle.getFactGroup("battery" + (batteryIndex - 1))
15
16 BatteryParams {
17 id: batParams
18 controller: _controller
19 batteryIndex: parent.batteryIndex
20 }
21
22 ColumnLayout {
23 spacing: ScreenTools.defaultFontPixelHeight
24
25 QGCLabel {
26 Layout.preferredWidth: gridLayout.width
27 wrapMode: Text.WordWrap
28 text: qsTr("Measure battery voltage using an external voltmeter and enter the value below. Click Calculate to set the new voltage multiplier.")
29 }
30
31 GridLayout {
32 id: gridLayout
33 columns: 2
34
35 QGCLabel { text: qsTr("Measured voltage:") }
36 QGCTextField { id: measuredVoltage; numericValuesOnly: true }
37
38 QGCLabel { text: qsTr("Vehicle voltage:") }
39 QGCLabel { text: _batteryFactGroup.voltage.valueString }
40
41 QGCLabel { text: qsTr("Voltage divider:") }
42 FactLabel { fact: batParams.battVoltageDivider }
43 }
44
45 QGCButton {
46 text: qsTr("Calculate")
47
48 onClicked: {
49 var measuredVoltageValue = parseFloat(measuredVoltage.text)
50 if (measuredVoltageValue === 0 || isNaN(measuredVoltageValue)) {
51 return
52 }
53 var newVoltageDivider = (measuredVoltageValue * batParams.battVoltageDivider.value) / _batteryFactGroup.voltage.value
54 if (newVoltageDivider > 0) {
55 batParams.battVoltageDivider.value = newVoltageDivider
56 }
57 }
58 }
59 }
60}