5import QGroundControl.FactControls
6import QGroundControl.Controls
10 title: qsTr("Calculate Amps per Volt")
13 property int batteryIndex: 0
14 property var _controller: controller
15 property var _batteryFactGroup: controller.vehicle.getFactGroup("battery" + batteryIndex)
19 controller: _controller
20 batteryIndex: popupDialog.batteryIndex
24 spacing: ScreenTools.defaultFontPixelHeight
27 Layout.preferredWidth: gridLayout.width
28 wrapMode: Text.WordWrap
29 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.")
33 Layout.preferredWidth: gridLayout.width
34 wrapMode: Text.WordWrap
35 visible: !_batteryFactGroup || _batteryFactGroup.current.value === 0
36 text: qsTr("Vehicle current telemetry is not available. Connect to a vehicle with a powered battery to enable automatic calculation.")
37 color: qgcPal.warningText
44 QGCLabel { text: qsTr("Measured current:") }
45 QGCTextField { id: measuredCurrent; numericValuesOnly: true }
48 text: qsTr("Vehicle current:")
49 visible: _batteryFactGroup && _batteryFactGroup.current.value !== 0
52 text: _batteryFactGroup ? _batteryFactGroup.current.valueString : ""
53 visible: _batteryFactGroup && _batteryFactGroup.current.value !== 0
56 QGCLabel { text: qsTr("Amps per volt:") }
57 FactLabel { fact: batParams.battAmpPerVolt }
61 text: qsTr("Calculate And Set")
62 enabled: _batteryFactGroup && _batteryFactGroup.current.value !== 0
65 let measuredCurrentValue = parseFloat(measuredCurrent.text)
66 if (measuredCurrentValue === 0 || isNaN(measuredCurrentValue)) {
69 let newAmpsPerVolt = (measuredCurrentValue * batParams.battAmpPerVolt.value) / _batteryFactGroup.current.value
70 if (newAmpsPerVolt !== 0) {
71 batParams.battAmpPerVolt.value = newAmpsPerVolt