From 2d4faa70f3ab69065c6cb76591626526366968a7 Mon Sep 17 00:00:00 2001 From: Raphael <68374617+raphaelscholle@users.noreply.github.com> Date: Mon, 13 May 2024 00:20:08 +0200 Subject: [PATCH] add custom battery type --- qml/ui/widgets/GroundPowerWidget.qml | 247 ++++++++++++++++++--------- 1 file changed, 163 insertions(+), 84 deletions(-) diff --git a/qml/ui/widgets/GroundPowerWidget.qml b/qml/ui/widgets/GroundPowerWidget.qml index 2636875d6..2dbebdd72 100644 --- a/qml/ui/widgets/GroundPowerWidget.qml +++ b/qml/ui/widgets/GroundPowerWidget.qml @@ -31,50 +31,56 @@ BaseWidget { BaseWidgetDefaultUiControlElements { id: idBaseWidgetDefaultUiControlElements - Item { - width: 230 - height: 32 - Text { - text: qsTr("Show single cell voltage") - color: "white" - height: parent.height - font.bold: true - font.pixelSize: detailPanelFontPixels - anchors.left: parent.left - verticalAlignment: Text.AlignVCenter - } - Switch { - width: 32 - height: parent.height - anchors.rightMargin: 6 - anchors.right: parent.right - checked: settings.ground_battery_show_single_cell - onCheckedChanged: settings.ground_battery_show_single_cell = checked - } - } - Item { - width: 230 - height: 32 - Text { - text: qsTr("Battery Type") - color: "white" - height: parent.height - font.bold: true - font.pixelSize: detailPanelFontPixels - anchors.left: parent.left - verticalAlignment: Text.AlignVCenter + ColumnLayout { + width: 230 // Set the width of the layout + spacing: 10 // Adjust spacing between elements if needed + Layout.alignment: Qt.AlignHCenter // Center the layout horizontally + + Item { + width: 230 + height: 32 + Text { + text: qsTr("Show single cell voltage") + color: "white" + height: parent.height + font.bold: true + font.pixelSize: detailPanelFontPixels + anchors.left: parent.left + verticalAlignment: Text.AlignVCenter + } + Switch { + width: 32 + height: parent.height + anchors.rightMargin: 6 + anchors.right: parent.right + checked: settings.ground_battery_show_single_cell + onCheckedChanged: settings.ground_battery_show_single_cell = checked + } } - ComboBox { - id: batteryComboBox - width: 100 - height: parent.height - anchors.rightMargin: 6 - anchors.right: parent.right - model: ["Lipo", "LiIon", "LiFe"] - onCurrentIndexChanged: { - switch (batteryComboBox.currentIndex) { + Item { + Layout.fillWidth: true // Expand to fill the width of the layout + height: 32 + + Text { + text: qsTr("Battery Type") + color: "white" + height: parent.height + font.bold: true + font.pixelSize: detailPanelFontPixels + Layout.alignment: Qt.AlignLeft + verticalAlignment: Text.AlignVCenter + } + + ComboBox { + id: batteryComboBox + width: 100 + height: parent.height + Layout.alignment: Qt.AlignRight | Qt.AlignVCenter // Align to the right and vertically center + model: ["Lipo", "LiIon", "LiFe", "Custom"] + onCurrentIndexChanged: { + switch (batteryComboBox.currentIndex) { case 0: settings.ground_battery_type = 0; settings.ground_battery_low = 33; @@ -93,19 +99,92 @@ BaseWidget { settings.ground_battery_mid = 35; settings.ground_battery_full = 37; break; + case 3: + customType.visible=true; + break; + } } } } + Text { + id:customType + text: qsTr("Battery Low") + visible: false + color: "white" + height: 32 + font.bold: true + font.pixelSize: detailPanelFontPixels + Layout.topMargin: 25 + Layout.alignment: Qt.AlignLeft + verticalAlignment: Text.AlignVCenter + } + TextField { + id: battery_low + visible: customType.visible + color: "white" + width: 200 + height: 40 + placeholderText: (settings.ground_battery_low/10) + } + + Text { + text: qsTr("Battery Mid") + visible: customType.visible + color: "white" + height: 32 + font.bold: true + font.pixelSize: detailPanelFontPixels + Layout.alignment: Qt.AlignLeft + verticalAlignment: Text.AlignVCenter + } + TextField { + id: battery_mid + visible: customType.visible + color: "white" + width: 200 + height: 40 + placeholderText: (settings.ground_battery_mid/10) + } + + Text { + text: qsTr("Battery Full") + visible: customType.visible + color: "white" + height: 32 + font.bold: true + font.pixelSize: detailPanelFontPixels + Layout.alignment: Qt.AlignLeft + verticalAlignment: Text.AlignVCenter + } + TextField { + id: battery_full + visible: customType.visible + color: "white" + width: 200 + height: 40 + placeholderText: (settings.ground_battery_full/10) + } + Button { + text: "Save" + visible: customType.visible + Layout.alignment: Qt.AlignHCenter // Center the button horizontally + onClicked: { + settings.ground_battery_type = 3; + settings.ground_battery_low = (battery_low.text*10); + settings.ground_battery_mid = (battery_mid.text*10); + settings.ground_battery_full = (battery_full.text*10); + } + } } } } function calculateBatteryPercentage(currentVoltage) { - var currentVoltage2 = ((currentVoltage/settings.ground_battery_cells) / 100).toFixed(0); - var fullVoltage = settings.ground_battery_full; - var midVoltage = settings.ground_battery_mid; - var emptyVoltage = settings.ground_battery_low; - var percentage; + var currentVoltage2 = ((currentVoltage/settings.ground_battery_cells) / 100).toFixed(0); + var fullVoltage = settings.ground_battery_full; + var midVoltage = settings.ground_battery_mid; + var emptyVoltage = settings.ground_battery_low; + var percentage; if (currentVoltage2 >= fullVoltage) { percentage = 100; @@ -122,9 +201,9 @@ BaseWidget { percentage = 0; } } - return percentage; // Ensure the percentage is within [0, 100] + return percentage; // Ensure the percentage is within [0, 100] - } + } Item { @@ -178,17 +257,17 @@ BaseWidget { onTriggered: { var currentVoltage = _ohdSystemGround.ina219_voltage_millivolt; if (_ohdSystemGround.ina219_current_milliamps===1338) { - var percentage = _ohdSystemGround.ina219_voltage_millivolt; - battery_volt_text.visible= false; - battery_amp_text.visible=false; + var percentage = _ohdSystemGround.ina219_voltage_millivolt; + battery_volt_text.visible= false; + battery_amp_text.visible=false; } else if (_ohdSystemGround.ina219_current_milliamps===1337) { - var percentage = _ohdSystemGround.ina219_voltage_millivolt; - battery_volt_text.visible= false; - battery_amp_text.visible= false; + var percentage = _ohdSystemGround.ina219_voltage_millivolt; + battery_volt_text.visible= false; + battery_amp_text.visible= false; } else { - var percentage = calculateBatteryPercentage(currentVoltage); + var percentage = calculateBatteryPercentage(currentVoltage); } settings.ground_voltage_in_percent = percentage; } @@ -252,37 +331,37 @@ BaseWidget { } opacity: bw_current_opacity text: { - var percent = settings.ground_voltage_in_percent; - - // Define symbols based on battery level - var symbol; - if (_ohdSystemGround.ina219_current_milliamps===1337) { - symbol = "\uF084"; // Charging - } - else if (percent < 10) { - symbol = "\uf07a"; // Change the symbol for battery level below 10% - } else if (percent < 20) { - symbol = "\uf07b"; // Change the symbol for battery level below 20% - } else if (percent < 30) { - symbol = "\uf07c"; // Change the symbol for battery level below 30% - } else if (percent < 40) { - symbol = "\uf07d"; // Change the symbol for battery level below 40% - } else if (percent < 50) { - symbol = "\uf07e"; // Change the symbol for battery level below 50% - } else if (percent < 60) { - symbol = "\uf07f"; // Change the symbol for battery level below 60% - } else if (percent < 70) { - symbol = "\uf080"; // Change the symbol for battery level below 70% - } else if (percent < 80) { - symbol = "\uf081"; // Change the symbol for battery level below 80% - } else if (percent < 90) { - symbol = "\uf082"; // Change the symbol for battery level below 90% - } else { - symbol = "\uf079"; // Default symbol for battery level above or equal to 100% - } + var percent = settings.ground_voltage_in_percent; - return symbol; + // Define symbols based on battery level + var symbol; + if (_ohdSystemGround.ina219_current_milliamps===1337) { + symbol = "\uF084"; // Charging } + else if (percent < 10) { + symbol = "\uf07a"; // Change the symbol for battery level below 10% + } else if (percent < 20) { + symbol = "\uf07b"; // Change the symbol for battery level below 20% + } else if (percent < 30) { + symbol = "\uf07c"; // Change the symbol for battery level below 30% + } else if (percent < 40) { + symbol = "\uf07d"; // Change the symbol for battery level below 40% + } else if (percent < 50) { + symbol = "\uf07e"; // Change the symbol for battery level below 50% + } else if (percent < 60) { + symbol = "\uf07f"; // Change the symbol for battery level below 60% + } else if (percent < 70) { + symbol = "\uf080"; // Change the symbol for battery level below 70% + } else if (percent < 80) { + symbol = "\uf081"; // Change the symbol for battery level below 80% + } else if (percent < 90) { + symbol = "\uf082"; // Change the symbol for battery level below 90% + } else { + symbol = "\uf079"; // Default symbol for battery level above or equal to 100% + } + + return symbol; + } anchors.left: parent.left anchors.leftMargin: 12 fontSizeMode: Text.VerticalFit