QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
APMCalcVoltageDividerDialog.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 Multiplier")
11 buttons: Dialog.Close
12
13 property int batteryIndex: 0
14 property var _controller: controller
15 property var _batteryFactGroup: controller.vehicle.getFactGroup("battery" + batteryIndex)
16
17 APMBatteryParams {
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 adjusted voltage multiplier.")
30 }
31
32 QGCLabel {
33 Layout.preferredWidth: gridLayout.width
34 wrapMode: Text.WordWrap
35 visible: !_batteryFactGroup || _batteryFactGroup.voltage.value === 0
36 text: qsTr("Vehicle voltage telemetry is not available. Connect to a vehicle with a powered battery to enable automatic calculation.")
37 color: qgcPal.warningText
38 }
39
40 GridLayout {
41 id: gridLayout
42 columns: 2
43
44 QGCLabel { text: qsTr("Measured voltage:") }
45 QGCTextField { id: measuredVoltage; numericValuesOnly: true }
46
47 QGCLabel {
48 text: qsTr("Vehicle voltage:")
49 visible: _batteryFactGroup && _batteryFactGroup.voltage.value !== 0
50 }
51 QGCLabel {
52 text: _batteryFactGroup ? _batteryFactGroup.voltage.valueString : ""
53 visible: _batteryFactGroup && _batteryFactGroup.voltage.value !== 0
54 }
55
56 QGCLabel { text: qsTr("Voltage multiplier:") }
57 FactLabel { fact: batParams.battVoltMult }
58 }
59
60 QGCButton {
61 text: qsTr("Calculate And Set")
62 enabled: _batteryFactGroup && _batteryFactGroup.voltage.value !== 0
63
64 onClicked: {
65 let measuredVoltageValue = parseFloat(measuredVoltage.text)
66 if (measuredVoltageValue === 0 || isNaN(measuredVoltageValue)) {
67 return
68 }
69 let newVoltageMultiplier = (measuredVoltageValue * batParams.battVoltMult.value) / _batteryFactGroup.voltage.value
70 if (newVoltageMultiplier > 0) {
71 batParams.battVoltMult.value = newVoltageMultiplier
72 }
73 }
74 }
75 }
76}