implement class for stack elements and add poetry dependency management

This commit is contained in:
Tobias Petrich 2022-07-19 03:18:17 +02:00
parent 39a7669fa7
commit a4733d3578
Signed by: t.petrich
GPG Key ID: 635C7BCB94426F96
3 changed files with 169 additions and 108 deletions

66
poetry.lock generated Normal file
View File

@ -0,0 +1,66 @@
[[package]]
name = "pyqt5"
version = "5.15.7"
description = "Python bindings for the Qt cross platform application toolkit"
category = "main"
optional = false
python-versions = ">=3.7"
[package.dependencies]
PyQt5-Qt5 = ">=5.15.0"
PyQt5-sip = ">=12.11,<13"
[[package]]
name = "pyqt5-qt5"
version = "5.15.2"
description = "The subset of a Qt installation needed by PyQt5."
category = "main"
optional = false
python-versions = "*"
[[package]]
name = "pyqt5-sip"
version = "12.11.0"
description = "The sip module support for PyQt5"
category = "main"
optional = false
python-versions = ">=3.7"
[metadata]
lock-version = "1.1"
python-versions = "^3.10"
content-hash = "ce4feb2a6a42610a01d5e986a40980aaf9f73c3fdc2368f55ec75e70f39c70cf"
[metadata.files]
pyqt5 = [
{file = "PyQt5-5.15.7-cp37-abi3-macosx_10_13_x86_64.whl", hash = "sha256:1a793748c60d5aff3850b7abf84d47c1d41edb11231b7d7c16bef602c36be643"},
{file = "PyQt5-5.15.7-cp37-abi3-manylinux1_x86_64.whl", hash = "sha256:e319c9d8639e0729235c1b09c99afdadad96fa3dbd8392ab561b5ab5946ee6ef"},
{file = "PyQt5-5.15.7-cp37-abi3-win32.whl", hash = "sha256:08694f0a4c7d4f3d36b2311b1920e6283240ad3b7c09b515e08262e195dcdf37"},
{file = "PyQt5-5.15.7-cp37-abi3-win_amd64.whl", hash = "sha256:232fe5b135a095cbd024cf341d928fc672c963f88e6a52b0c605be8177c2fdb5"},
{file = "PyQt5-5.15.7.tar.gz", hash = "sha256:755121a52b3a08cb07275c10ebb96576d36e320e572591db16cfdbc558101594"},
]
pyqt5-qt5 = [
{file = "PyQt5_Qt5-5.15.2-py3-none-macosx_10_13_intel.whl", hash = "sha256:76980cd3d7ae87e3c7a33bfebfaee84448fd650bad6840471d6cae199b56e154"},
{file = "PyQt5_Qt5-5.15.2-py3-none-manylinux2014_x86_64.whl", hash = "sha256:1988f364ec8caf87a6ee5d5a3a5210d57539988bf8e84714c7d60972692e2f4a"},
{file = "PyQt5_Qt5-5.15.2-py3-none-win32.whl", hash = "sha256:9cc7a768b1921f4b982ebc00a318ccb38578e44e45316c7a4a850e953e1dd327"},
{file = "PyQt5_Qt5-5.15.2-py3-none-win_amd64.whl", hash = "sha256:750b78e4dba6bdf1607febedc08738e318ea09e9b10aea9ff0d73073f11f6962"},
]
pyqt5-sip = [
{file = "PyQt5_sip-12.11.0-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:f1f9e312ff8284d6dfebc5366f6f7d103f84eec23a4da0be0482403933e68660"},
{file = "PyQt5_sip-12.11.0-cp310-cp310-manylinux1_x86_64.whl", hash = "sha256:4031547dfb679be309094bfa79254f5badc5ddbe66b9ad38e319d84a7d612443"},
{file = "PyQt5_sip-12.11.0-cp310-cp310-win32.whl", hash = "sha256:ad21ca0ee8cae2a41b61fc04949dccfab6fe008749627d94e8c7078cb7a73af1"},
{file = "PyQt5_sip-12.11.0-cp310-cp310-win_amd64.whl", hash = "sha256:3126c84568ab341c12e46ded2230f62a9a78752a70fdab13713f89a71cd44f73"},
{file = "PyQt5_sip-12.11.0-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:0f77655c62ec91d47c2c99143f248624d44dd2d8a12d016e7c020508ad418aca"},
{file = "PyQt5_sip-12.11.0-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:ec5e9ef78852e1f96f86d7e15c9215878422b83dde36d44f1539a3062942f19c"},
{file = "PyQt5_sip-12.11.0-cp37-cp37m-win32.whl", hash = "sha256:d12b81c3a08abf7657a2ebc7d3649852a1f327eb2146ebadf45930486d32e920"},
{file = "PyQt5_sip-12.11.0-cp37-cp37m-win_amd64.whl", hash = "sha256:b69a1911f768b489846335e31e49eb34795c6b5a038ca24d894d751e3b0b44da"},
{file = "PyQt5_sip-12.11.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:51e377789d59196213eddf458e6927f33ba9d217b614d17d20df16c9a8b2c41c"},
{file = "PyQt5_sip-12.11.0-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:4e5c1559311515291ea0ab0635529f14536954e3b973a7c7890ab7e4de1c2c23"},
{file = "PyQt5_sip-12.11.0-cp38-cp38-win32.whl", hash = "sha256:9bca450c5306890cb002fe36bbca18f979dd9e5b810b766dce8e3ce5e66ba795"},
{file = "PyQt5_sip-12.11.0-cp38-cp38-win_amd64.whl", hash = "sha256:f6b72035da4e8fecbb0bc4a972e30a5674a9ad5608dbddaa517e983782dbf3bf"},
{file = "PyQt5_sip-12.11.0-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:9356260d4feb60dbac0ab66f8a791a0d2cda1bf98c9dec8e575904a045fbf7c5"},
{file = "PyQt5_sip-12.11.0-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:205f3e1b3eea3597d8e878936c1a06e04bd23a59e8b179ee806465d72eea3071"},
{file = "PyQt5_sip-12.11.0-cp39-cp39-win32.whl", hash = "sha256:686071be054e5be6ca5aaaef7960931d4ba917277e839e2e978c7cbe3f43bb6e"},
{file = "PyQt5_sip-12.11.0-cp39-cp39-win_amd64.whl", hash = "sha256:42320e7a94b1085ed85d49794ed4ccfe86f1cae80b44a894db908a8aba2bc60e"},
{file = "PyQt5_sip-12.11.0.tar.gz", hash = "sha256:b4710fd85b57edef716cc55fae45bfd5bfac6fc7ba91036f1dcc3f331ca0eb39"},
]

15
pyproject.toml Normal file
View File

@ -0,0 +1,15 @@
[tool.poetry]
name = "charger-display"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
[tool.poetry.dependencies]
python = "^3.10"
PyQt5 = "^5.15.7"
[tool.poetry.dev-dependencies]
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

174
test.py
View File

@ -65,6 +65,60 @@ class AccumulatorData:
self.panic_errorcode = self.panic_errorarg = 0 self.panic_errorcode = self.panic_errorarg = 0
class StackGuiElement:
title: str
min_voltage_label: QLabel
max_voltage_label: QLabel
min_temp_label: QLabel
max_temp_label: QLabel
groupBox: QGroupBox
def __init__(self, title: str):
self.title = title
self.min_voltage_label = QLabel()
self.max_voltage_label = QLabel()
self.min_temp_label = QLabel()
self.max_temp_label = QLabel()
self.groupBox = QGroupBox()
self.__post__init__()
def __post__init__(self):
l1 = QLabel("Min Voltage [V]")
l2 = QLabel("Max Voltage [V]")
l3 = QLabel("Min Temperature [°C]")
l4 = QLabel("Max Temperature [°C]")
l1.setAlignment(Qt.AlignLeft)
l2.setAlignment(Qt.AlignLeft)
l3.setAlignment(Qt.AlignLeft)
l4.setAlignment(Qt.AlignLeft)
self.min_voltage_label.setAlignment(Qt.AlignLeft)
self.max_voltage_label.setAlignment(Qt.AlignLeft)
self.min_temp_label.setAlignment(Qt.AlignLeft)
self.max_temp_label.setAlignment(Qt.AlignLeft)
grid = QGridLayout()
grid.addWidget(l1, 0, 0)
grid.addWidget(l2, 1, 0)
grid.addWidget(l3, 0, 2)
grid.addWidget(l4, 1, 2)
grid.addWidget(self.min_voltage_label, 0, 1)
grid.addWidget(self.max_voltage_label, 1, 1)
grid.addWidget(self.min_temp_label, 0, 3)
grid.addWidget(self.max_temp_label, 1, 3)
self.groupBox.setTitle(self.title)
self.groupBox.setLayout(grid)
def update_data_from_slave(self, slave: SlaveData):
self.min_voltage_label.setNum(min(slave.cell_voltages))
self.max_voltage_label.setNum(max(slave.cell_voltages))
self.min_temp_label.setNum(min(slave.cell_temps))
self.max_temp_label.setNum(max(slave.cell_temps))
def fill_dummy_data(): def fill_dummy_data():
data.min_voltage = random.uniform(1, 3) data.min_voltage = random.uniform(1, 3)
data.max_voltage = random.uniform(3, 5) data.max_voltage = random.uniform(3, 5)
@ -193,90 +247,19 @@ class Window(QWidget):
### STACKS ### ### STACKS ###
### STACK 0 ### self.stack_gui_elements = []
for i in range(N_SLAVES):
self.l1_s0 = QLabel("Min Voltage [V]") sge = StackGuiElement(f"Stack {i}")
self.l1_s0.setAlignment(Qt.AlignLeft) sge.update_data_from_slave(data.slaves[i])
self.l_min_voltage_s0 = QLabel() self.stack_gui_elements.append(sge)
self.l_min_voltage_s0.setNum(min(data.slaves[0].cell_voltages))
self.l_min_voltage_s0.setAlignment(Qt.AlignLeft)
self.l2_s0 = QLabel("Max Voltage [V]")
self.l2_s0.setAlignment(Qt.AlignLeft)
self.l_max_voltage_s0 = QLabel()
self.l_max_voltage_s0.setNum(max(data.slaves[0].cell_voltages))
self.l_max_voltage_s0.setAlignment(Qt.AlignLeft)
self.l3_s0 = QLabel("Min Temperature [°C]")
self.l3_s0.setAlignment(Qt.AlignLeft)
self.l_min_temp_s0 = QLabel()
self.l_min_temp_s0.setNum(min(data.slaves[0].cell_temps))
self.l_min_temp_s0.setAlignment(Qt.AlignLeft)
self.l4_s0 = QLabel("Max Temperature [°C]")
self.l4_s0.setAlignment(Qt.AlignLeft)
self.l_max_temp_s0 = QLabel()
self.l_max_temp_s0.setNum(max(data.slaves[0].cell_temps))
self.l_max_temp_s0.setAlignment(Qt.AlignLeft)
grid_stack_s0 = QGridLayout()
grid_stack_s0.addWidget(self.l1_s0, 0, 0)
grid_stack_s0.addWidget(self.l2_s0, 1, 0)
grid_stack_s0.addWidget(self.l3_s0, 0, 2)
grid_stack_s0.addWidget(self.l4_s0, 1, 2)
grid_stack_s0.addWidget(self.l_min_voltage_s0, 0, 1)
grid_stack_s0.addWidget(self.l_max_voltage_s0, 1, 1)
grid_stack_s0.addWidget(self.l_min_temp_s0, 0, 3)
grid_stack_s0.addWidget(self.l_max_temp_s0, 1, 3)
groupBox_stack_s0 = QGroupBox("Stack 0")
groupBox_stack_s0.setLayout(grid_stack_s0)
### STACK 1 ###
self.l1_s1 = QLabel("Min Voltage [V]")
self.l1_s1.setAlignment(Qt.AlignLeft)
self.l_min_voltage_s1 = QLabel()
self.l_min_voltage_s1.setNum(min(data.slaves[1].cell_voltages))
self.l_min_voltage_s1.setAlignment(Qt.AlignLeft)
self.l2_s1 = QLabel("Max Voltage [V]")
self.l2_s1.setAlignment(Qt.AlignLeft)
self.l_max_voltage_s1 = QLabel()
self.l_max_voltage_s1.setNum(max(data.slaves[1].cell_voltages))
self.l_max_voltage_s1.setAlignment(Qt.AlignLeft)
self.l3_s1 = QLabel("Min Temperature [°C]")
self.l3_s1.setAlignment(Qt.AlignLeft)
self.l_min_temp_s1 = QLabel()
self.l_min_temp_s1.setNum(min(data.slaves[1].cell_temps))
self.l_min_temp_s1.setAlignment(Qt.AlignLeft)
self.l4_s1 = QLabel("Max Temperature [°C]")
self.l4_s1.setAlignment(Qt.AlignLeft)
self.l_max_temp_s1 = QLabel()
self.l_max_temp_s1.setNum(max(data.slaves[1].cell_temps))
self.l_max_temp_s1.setAlignment(Qt.AlignLeft)
grid_stack_s1 = QGridLayout()
grid_stack_s1.addWidget(self.l1_s1, 0, 0)
grid_stack_s1.addWidget(self.l2_s1, 1, 0)
grid_stack_s1.addWidget(self.l3_s1, 0, 2)
grid_stack_s1.addWidget(self.l4_s1, 1, 2)
grid_stack_s1.addWidget(self.l_min_voltage_s1, 0, 1)
grid_stack_s1.addWidget(self.l_max_voltage_s1, 1, 1)
grid_stack_s1.addWidget(self.l_min_temp_s1, 0, 3)
grid_stack_s1.addWidget(self.l_max_temp_s1, 1, 3)
groupBox_stack_s1 = QGroupBox("Stack 1")
groupBox_stack_s1.setLayout(grid_stack_s1)
### Layout Stacks ### ### Layout Stacks ###
n_slaves_half = N_SLAVES // 2
grid_stacks = QGridLayout() grid_stacks = QGridLayout()
grid_stacks.addWidget(groupBox_stack_s0, 0, 0) for i, sge in enumerate(self.stack_gui_elements):
grid_stacks.addWidget(groupBox_stack_s1, 0, 1) grid_stacks.addWidget(
sge.groupBox, 0 if i < n_slaves_half else 1, i % n_slaves_half
)
groupBox_stacks = QGroupBox("Individual Stacks") groupBox_stacks = QGroupBox("Individual Stacks")
groupBox_stacks.setLayout(grid_stacks) groupBox_stacks.setLayout(grid_stacks)
@ -286,33 +269,30 @@ class Window(QWidget):
self.setLayout(win) self.setLayout(win)
self.setWindowTitle("FT22 Charger Display") self.setWindowTitle("FT22 Charger Display")
def update(self):
def update_gui():
# Accumulator # Accumulator
gui.l_min_voltage.setNum(data.min_voltage) self.l_min_voltage.setNum(data.min_voltage)
gui.l_max_voltage.setNum(data.max_voltage) self.l_max_voltage.setNum(data.max_voltage)
gui.l_min_temp.setNum(data.min_temp) self.l_min_temp.setNum(data.min_temp)
gui.l_max_temp.setNum(data.max_temp) self.l_max_temp.setNum(data.max_temp)
gui.l_current.setNum(data.current) self.l_current.setNum(data.current)
gui.l_error.setText(str(data.panic)) self.l_error.setText(str(data.panic))
gui.l_errorcode.setText(str(data.panic_errorcode)) self.l_errorcode.setText(str(data.panic_errorcode))
gui.l_errorarg.setText(str(data.panic_errorarg)) self.l_errorarg.setText(str(data.panic_errorarg))
# Cells # Cells
gui.l_min_voltage_s0.setNum(min(data.slaves[0].cell_voltages)) for i, sge in enumerate(self.stack_gui_elements):
gui.l_max_voltage_s0.setNum(max(data.slaves[0].cell_voltages)) sge.update_data_from_slave(data.slaves[i])
gui.l_min_temp_s0.setNum(min(data.slaves[0].cell_temps))
gui.l_max_temp_s0.setNum(max(data.slaves[0].cell_temps))
if __name__ == "__main__":
data = AccumulatorData() data = AccumulatorData()
app = QApplication(sys.argv) app = QApplication(sys.argv)
gui = Window() gui = Window()
gui.show() gui.show()
timer = QTimer() timer = QTimer()
timer.timeout.connect(update_gui) timer.timeout.connect(gui.update)
timer.timeout.connect(fill_dummy_data) timer.timeout.connect(fill_dummy_data)
timer.start(1000) # every 1,000 milliseconds timer.start(1000) # every 1,000 milliseconds