5import QGroundControl.FactControls
6import QGroundControl.Controls
9 title: qsTr("Calculate Amps per Volt")
12 property int batteryIndex: 0
13 property var _controller: controller
14 property var _batteryFactGroup: controller.vehicle.getFactGroup("battery" + batteryIndex)
18 controller: _controller
19 batteryIndex: parent.batteryIndex
23 spacing: ScreenTools.defaultFontPixelHeight
26 Layout.preferredWidth: gridLayout.width
27 wrapMode: Text.WordWrap
28 text: qsTr("Measure current draw using an external current meter and enter the value below. Click Calculate to set the new amps per volt value.")
32 Layout.preferredWidth: gridLayout.width
33 wrapMode: Text.WordWrap
34 visible: !_batteryFactGroup || _batteryFactGroup.current.value === 0
35 text: qsTr("Vehicle current telemetry is not available. Connect to a vehicle with a powered battery to enable automatic calculation.")
36 color: qgcPal.warningText
43 QGCLabel { text: qsTr("Measured current:") }
44 QGCTextField { id: measuredCurrent; numericValuesOnly: true }
47 text: qsTr("Vehicle current:")
48 visible: _batteryFactGroup && _batteryFactGroup.current.value !== 0
51 text: _batteryFactGroup ? _batteryFactGroup.current.valueString : ""
52 visible: _batteryFactGroup && _batteryFactGroup.current.value !== 0
55 QGCLabel { text: qsTr("Amps per volt:") }
56 FactLabel { fact: batParams.battAmpPerVolt }
60 text: qsTr("Calculate And Set")
61 enabled: _batteryFactGroup && _batteryFactGroup.current.value !== 0
64 let measuredCurrentValue = parseFloat(measuredCurrent.text)
65 if (measuredCurrentValue === 0 || isNaN(measuredCurrentValue)) {
68 let newAmpsPerVolt = (measuredCurrentValue * batParams.battAmpPerVolt.value) / _batteryFactGroup.current.value
69 if (newAmpsPerVolt !== 0) {
70 batParams.battAmpPerVolt.value = newAmpsPerVolt