From 046d1f55ced71ba0636d409d2bc4d25785e314a6 Mon Sep 17 00:00:00 2001 From: Yury Shuvakin Date: Fri, 26 Aug 2022 09:30:07 +0300 Subject: [PATCH] Cell balancing calculation added. Fixed rounding of real numbers to the second decimal place --- qml/Screens/AkbMonitorScreen.qml | 17 +++++++++-------- qml/Screens/CellMonitorScreen.qml | 16 +++++++++++++--- qml/Screens/StatusPopup.qml | 4 +--- qml/Utils/MathHelper.qml | 8 ++++++++ qml/Utils/Palette.qml | 1 + qml/Utils/qmldir | 1 + qml/qml_items.qrc | 1 + 7 files changed, 34 insertions(+), 14 deletions(-) create mode 100644 qml/Utils/MathHelper.qml diff --git a/qml/Screens/AkbMonitorScreen.qml b/qml/Screens/AkbMonitorScreen.qml index 39b0810..bd17835 100644 --- a/qml/Screens/AkbMonitorScreen.qml +++ b/qml/Screens/AkbMonitorScreen.qml @@ -3,6 +3,7 @@ import QtQuick.Layouts 1.12 import Controls 1.0 as Controls import Cubo 1.0 +import Utils 1.0 Item { ColumnLayout { @@ -299,27 +300,27 @@ Item { target: BmsInterface.commands() onValuesReceived: { batteryChargeLevelLabel.text = values.soC - batteryVoltageLabel.text = values.packVoltage + batteryVoltageLabel.text = MathHelper.roundDouble(values.packVoltage) - batteryTemperatureLabel.text = values.tempBattHigh - bmsTemperatureLabel.text = values.tempBMSHigh + batteryTemperatureLabel.text = MathHelper.roundDouble(values.tempBattHigh) + bmsTemperatureLabel.text = MathHelper.roundDouble(values.tempBMSHigh) - maximumCellVoltageLabel.text = values.cVHigh - minimumCellVoltageLabel.text = values.cVLow + maximumCellVoltageLabel.text = MathHelper.roundDouble(values.cVHigh) + minimumCellVoltageLabel.text = MathHelper.roundDouble(values.cVLow) - currentLabel.text = values.packCurrent + currentLabel.text = MathHelper.roundDouble(values.packCurrent) } } Connections { target: BmsInterface.bmsConfig() onUpdated: { - serialNumberField.text = BmsInterface.bmsConfig().getParamDouble("notUsedCurrentThreshold") // TODO + serialNumberField.text = MathHelper.roundDouble(BmsInterface.bmsConfig().getParamDouble("notUsedCurrentThreshold")) // TODO numberOfModulesLabel.text = BmsInterface.bmsConfig().getParamInt("cellMonitorICCount") numberOfCellsLabel.text = BmsInterface.bmsConfig().getParamInt("noOfCellsSeries") - nominalCapacityLabel.text = BmsInterface.bmsConfig().getParamDouble("batteryCapacity") + nominalCapacityLabel.text = MathHelper.roundDouble(BmsInterface.bmsConfig().getParamDouble("batteryCapacity")) actualCapacityLabel.text = nominalCapacityLabel.text // TODO } } diff --git a/qml/Screens/CellMonitorScreen.qml b/qml/Screens/CellMonitorScreen.qml index 4a97b2d..1da3318 100644 --- a/qml/Screens/CellMonitorScreen.qml +++ b/qml/Screens/CellMonitorScreen.qml @@ -70,7 +70,7 @@ Item { } Controls.SubtitleLabel { - text: index + 1 + id: indexLabel color: Palette.tableHeaderTextColor Layout.preferredWidth: 25 Layout.alignment: Qt.AlignCenter @@ -97,6 +97,10 @@ Item { Item { Layout.preferredWidth: parent.width / 6 - 20 } + + Component.onCompleted: { + indexLabel.text = index + ListView.view.indexOffset + } } } @@ -113,6 +117,9 @@ Item { clip: true model: [] spacing: 0 + boundsBehavior: Flickable.StopAtBounds + + property int indexOffset: 1 header: cellListHeader delegate: cellListDelegate @@ -132,6 +139,9 @@ Item { clip: true model: [] spacing: 0 + boundsBehavior: Flickable.StopAtBounds + + property int indexOffset: 17 header: cellListHeader delegate: cellListDelegate @@ -149,7 +159,7 @@ Item { var firstModel = [] for (var i = 0; i < Math.min(cellCount, 16); ++i) { - firstModel.push({"voltage": cellVoltageArray[i], "balancing": true}) + firstModel.push({"voltage": MathHelper.roundDouble(cellVoltageArray[i]), "balancing": cellVoltageArray[i] < 0}) } firstCellGroup.model = firstModel @@ -158,7 +168,7 @@ Item { var secondModel = [] for (var j = 16; j < Math.min(cellCount, 32); ++j) { - secondModel.push({"voltage": cellVoltageArray[j], "balancing": true}) + secondModel.push({"voltage": MathHelper.roundDouble(cellVoltageArray[j]), "balancing": cellVoltageArray[i] < 0}) } secondCellGroup.model = secondModel } diff --git a/qml/Screens/StatusPopup.qml b/qml/Screens/StatusPopup.qml index 5f5db03..bf21bce 100644 --- a/qml/Screens/StatusPopup.qml +++ b/qml/Screens/StatusPopup.qml @@ -23,9 +23,7 @@ Popup { background: Rectangle { radius: 6 - color: good ? Palette.alternativeBackgroundColor : Palette.invalidColor - border.width: 1 - border.color: Palette.borderColor + color: good ? Palette.informationColor : Palette.invalidColor } enter: Transition { diff --git a/qml/Utils/MathHelper.qml b/qml/Utils/MathHelper.qml new file mode 100644 index 0000000..777cc05 --- /dev/null +++ b/qml/Utils/MathHelper.qml @@ -0,0 +1,8 @@ +pragma Singleton +import QtQuick 2.12 + +QtObject { + function roundDouble(value) { + return Math.round((value + Number.EPSILON) * 100) / 100 + } +} diff --git a/qml/Utils/Palette.qml b/qml/Utils/Palette.qml index f13b725..7f0a590 100644 --- a/qml/Utils/Palette.qml +++ b/qml/Utils/Palette.qml @@ -22,5 +22,6 @@ QtObject { property color hoveredButtonColor: "#03AC61" property color pressedButtonColor: "#057845" + property color informationColor: "#4C68ED" property color invalidColor: "#A31C00" } diff --git a/qml/Utils/qmldir b/qml/Utils/qmldir index df3af39..c25a209 100644 --- a/qml/Utils/qmldir +++ b/qml/Utils/qmldir @@ -1,2 +1,3 @@ module utils singleton Palette 1.0 Palette.qml +singleton MathHelper 1.0 MathHelper.qml diff --git a/qml/qml_items.qrc b/qml/qml_items.qrc index 5cd7ea5..2f39209 100644 --- a/qml/qml_items.qrc +++ b/qml/qml_items.qrc @@ -37,5 +37,6 @@ Controls/DialogBackground.qml Screens/MessageDialog.qml Screens/StatusPopup.qml + Utils/MathHelper.qml