forked from vedderb/vesc_tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBMS.qml
359 lines (298 loc) · 13.9 KB
/
BMS.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
/*
Copyright 2020 Benjamin Vedder benjamin@vedder.se
This file is part of VESC Tool.
VESC Tool is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
VESC Tool is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.7
import QtQuick.Controls 2.10
import QtQuick.Layouts 1.3
import Vedder.vesc.vescinterface 1.0
import Vedder.vesc.commands 1.0
import Vedder.vesc.utility 1.0
Item {
id: bmsPageItem
property Commands mCommands: VescIf.commands()
property var mVal
property bool mValSet: false
property bool isHorizontal: width > height
GridLayout {
anchors.fill: parent
columns: isHorizontal ? 2 : 1
rows: isHorizontal ? 1 : 2
RowLayout {
Layout.fillHeight: true
Layout.fillWidth: true
Layout.column: isHorizontal ? 1 : 0
Layout.row: 0
Layout.preferredWidth: isHorizontal ? parent.width/2 : parent.width
Layout.preferredHeight: parent.height*2/3
spacing: 0
Rectangle {
color: Utility.getAppHexColor("lightestBackground")
width: 16
Layout.fillHeight: true
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
PageIndicator {
id: indicator
count: swipeView.count
currentIndex: swipeView.currentIndex
anchors.centerIn: parent
rotation: 90
}
}
SwipeView {
id: swipeView
enabled: true
clip: true
Layout.fillWidth: true
Layout.fillHeight: true
orientation: Qt.Vertical
Page {
Canvas {
id: cellCanvas
anchors.fill: parent
onPaint: {
var ctx = getContext("2d");
ctx.reset()
var xOfsLeft = valMetrics.width * 4.5
var xOfsRight = valMetrics.width * 8
var heightBars = (height - valMetrics.height * 1.2)
var cellWidth = width - xOfsLeft - xOfsRight
ctx.font = '%1pt %2'.arg(valText.font.pointSize).arg(valText.font.family)
var lineDivs = 6
var lineStep = cellWidth / lineDivs
ctx.beginPath()
for (var i = 0; i <= lineDivs;i++) {
ctx.moveTo(xOfsLeft + lineStep * i, 0)
ctx.lineTo(xOfsLeft + lineStep * i, heightBars)
}
ctx.strokeStyle = Utility.getAppHexColor("lightAccent")
ctx.lineWidth = 1.2
ctx.stroke()
ctx.fillStyle = Utility.getAppHexColor("lightAccent")
ctx.textBaseline = "top"
ctx.textAlign = "start";
ctx.fillText("V", valMetrics.width / 2, heightBars)
ctx.textAlign = "center"
for (i = 0; i <= lineDivs;i++) {
ctx.fillText(parseFloat(3 + i * (1.2 / lineDivs)).toFixed(1), xOfsLeft + lineStep * i, heightBars)
}
if (!mValSet) {
return
}
var vCells = mVal.v_cells
var isBal = mVal.is_balancing
// var vCells = [3.1, 2.7, 3.3, 3.4, 3.5, 3.4, 3.3, 4.4, 4.1, 4.2]
// var isBal = [false, false, false, false, true, true, false, false, false, true]
var cellNum = vCells.length
var cellHeight = (heightBars / cellNum) * 0.6
var cellDist = (heightBars / cellNum) * 0.4
ctx.textAlign = "start"
ctx.textBaseline = "middle"
for (i = 0;i < cellNum;i++) {
ctx.fillStyle = Utility.getAppHexColor("lightAccent")
var cellW = ((vCells[i] - 3.0) / 1.2) * cellWidth
if (cellW > cellWidth) {
cellW = cellWidth
}
if (cellW < 1.2) {
cellW = 1.2
}
var txtY = i * (cellHeight + cellDist) + cellDist / 2 + cellHeight / 2
ctx.fillText("C" + parseFloat(i + 1).toFixed(0),
valMetrics.width / 2, txtY)
ctx.fillText(parseFloat(vCells[i]).toFixed(3) + " V",
xOfsLeft + cellWidth + valMetrics.width / 2, txtY)
if (isBal[i]) {
ctx.fillStyle = Utility.getAppHexColor("orange")
} else {
ctx.fillStyle = Qt.rgba(0, 0.9, 0, 1)
}
ctx.fillRect(xOfsLeft, i * (cellHeight + cellDist) + cellDist / 2,
cellW, cellHeight)
}
}
}
}
Page {
Canvas {
id: tempCanvas
anchors.fill: parent
onPaint: {
var ctx = getContext("2d");
ctx.reset()
if (!mValSet) {
return
}
var temps = [mVal.temp_ic, mVal.temp_hum_sensor].concat(mVal.temps)
var tempNum = temps.length
var xOfsLeft = valMetrics.width * 4.5
var xOfsRight = valMetrics.width * 8
var cellHeight = (height / tempNum) * 0.7
var cellDist = (height / tempNum) * 0.3
var cellWidth = width - xOfsLeft - xOfsRight
for (var i = 0;i < tempNum;i++) {
ctx.fillStyle = Utility.getAppHexColor("lightAccent")
ctx.textAlign = "start";
ctx.textBaseline = "middle";
ctx.font = '%1pt %2'.arg(valText.font.pointSize).arg(valText.font.family)
var cellW = ((temps[i] + 10) / 70) * cellWidth
if (cellW > cellWidth) {
cellW = cellWidth
}
if (cellW < 0) {
cellW = 0
}
var txtY = i * (cellHeight + cellDist) + cellDist / 2 + cellHeight / 2
ctx.fillText("T" + parseFloat(i + 1).toFixed(0),
valMetrics.width / 2, txtY)
ctx.fillText(parseFloat(temps[i]).toFixed(2) + " °C",
xOfsLeft + cellW + valMetrics.width / 2, txtY)
ctx.fillStyle = Qt.rgba(0, 0, 1, 1)
ctx.fillRect(xOfsLeft, i * (cellHeight + cellDist) + cellDist / 2,
cellW, cellHeight)
}
}
}
}
Page {
}
}
}
ColumnLayout {
Layout.fillWidth: true
Layout.fillHeight: true
Layout.preferredWidth: isHorizontal ? parent.width/2 : parent.width
Layout.column:0
Layout.row: isHorizontal ? 0 : 1
Layout.preferredHeight: valMetrics.height * 12 + 20 + menuButton.implicitHeight
spacing: 0
Rectangle {
id: textRect
color: Utility.getAppHexColor("darkBackground")
Rectangle {
anchors.top: textRect.top
width: parent.width
height: 2
color: Utility.getAppHexColor("lightAccent")
}
Layout.fillWidth: true
Layout.preferredHeight: valMetrics.height * 12 + 20
Layout.alignment: Qt.AlignBottom
Text {
id: valText
color: Utility.getAppHexColor("lightText")
text: "No Data"
font.family: "DejaVu Sans Mono"
verticalAlignment: Text.AlignVCenter
anchors.fill: parent
anchors.leftMargin: 10
anchors.topMargin: 5
}
TextMetrics {
id: valMetrics
font: valText.font
text: "A"
}
}
RowLayout {
Layout.leftMargin: 10 + notchLeft
Layout.rightMargin: 10 + notchRight
Layout.fillWidth: true
Item {
Layout.fillWidth: true
Layout.preferredWidth: 150
}
Button {
id: menuButton
Layout.preferredWidth: 50
Layout.fillWidth: true
text: "..."
onClicked: menu.open()
Menu {
id: menu
bottomPadding: notchBot
leftPadding: notchLeft
rightPadding: notchRight
parent: bmsPageItem
y: parent.height - implicitHeight
width: parent.width
MenuItem {
text: "Balance On"
onTriggered: {
mCommands.bmsForceBalance(true)
}
}
MenuItem {
text: "Balance Off"
onTriggered: {
mCommands.bmsForceBalance(false)
}
}
MenuItem {
text: "Reset Ah Counter"
onTriggered: {
mCommands.bmsResetCounters(true, false)
}
}
MenuItem {
text: "Reset Wh Counter"
onTriggered: {
mCommands.bmsResetCounters(false, true)
}
}
MenuItem {
text: "Allow Charging"
onTriggered: {
mCommands.bmsSetChargeAllowed(true)
}
}
MenuItem {
text: "Disable Charging"
onTriggered: {
mCommands.bmsSetChargeAllowed(false)
}
}
MenuItem {
text: "Zero Current Offset"
onTriggered: {
mCommands.bmsZeroCurrentOffset()
}
}
}
}
}
}
}
Connections {
target: mCommands
function onBmsValuesRx(val) {
mVal = val
mValSet = true
valText.text =
"V Tot : " + parseFloat(val.v_tot).toFixed(2) + " V\n" +
"V Charge : " + parseFloat(val.v_charge).toFixed(2) + " V\n" +
"I In : " + parseFloat(val.i_in_ic).toFixed(2) + " A\n" +
"Ah Cnt : " + parseFloat(val.ah_cnt).toFixed(3) + " Ah\n" +
"Wh Cnt : " + parseFloat(val.wh_cnt).toFixed(2) + " Wh\n" +
"Power : " + parseFloat(val.v_tot * val.i_in_ic).toFixed(2) + " W\n" +
"Humidity : " + parseFloat(val.humidity).toFixed(1) + " %\n" +
"Pressure : " + parseFloat(val.pressure).toFixed(0) + " Pa\n" +
"Temp Hum : " + parseFloat(val.temp_hum_sensor).toFixed(1) + " \u00B0C\n" +
"Temp Max : " + parseFloat(val.temp_cells_highest).toFixed(1) + " \u00B0C\n" +
"SoC : " + parseFloat(val.soc * 100).toFixed(1) + " %\n" +
"Ah Chg Tot : " + parseFloat(val.ah_cnt_chg_total).toFixed(3) + " Ah"
cellCanvas.requestPaint()
tempCanvas.requestPaint()
}
}
}