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