correct amount of temperature sensors
This commit is contained in:
		
							
								
								
									
										43
									
								
								test.py
									
									
									
									
									
								
							
							
						
						
									
										43
									
								
								test.py
									
									
									
									
									
								
							@ -17,6 +17,8 @@ from PyQt5.QtWidgets import (
 | 
			
		||||
    QGridLayout,
 | 
			
		||||
    QLabel,
 | 
			
		||||
    QGroupBox,
 | 
			
		||||
    QFrame,
 | 
			
		||||
    QSizePolicy,
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -83,7 +85,7 @@ class AccumulatorData:
 | 
			
		||||
                random.uniform(1, 5) for i in range(CELLS_PER_SLAVE)
 | 
			
		||||
            ]
 | 
			
		||||
            self.slaves[i].cell_temps = [
 | 
			
		||||
                random.uniform(25, 60) for i in range(CELLS_PER_SLAVE)
 | 
			
		||||
                random.uniform(25, 60) for i in range(TEMP_SENSORS_PER_SLAVE)
 | 
			
		||||
            ]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -154,6 +156,21 @@ class StackGuiElement:
 | 
			
		||||
        self.detail_popup.show()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class QVSeperationLine(QFrame):
 | 
			
		||||
    """
 | 
			
		||||
    a vertical seperation line
 | 
			
		||||
    """
 | 
			
		||||
 | 
			
		||||
    def __init__(self):
 | 
			
		||||
        super().__init__()
 | 
			
		||||
        self.setFixedWidth(20)
 | 
			
		||||
        self.setMinimumHeight(1)
 | 
			
		||||
        self.setFrameShape(QFrame.VLine)
 | 
			
		||||
        self.setFrameShadow(QFrame.Sunken)
 | 
			
		||||
        self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Preferred)
 | 
			
		||||
        return
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class StackPopup(QWidget):
 | 
			
		||||
    stack_id: int
 | 
			
		||||
    voltage_labels: list[QLabel]
 | 
			
		||||
@ -171,24 +188,35 @@ class StackPopup(QWidget):
 | 
			
		||||
 | 
			
		||||
        for i in range(len(data.slaves[stack_id].cell_voltages)):
 | 
			
		||||
            l1 = QLabel(f"Voltage Cell {i}")
 | 
			
		||||
            l2 = QLabel(f"Temperature Cell {i}")
 | 
			
		||||
            l1.setAlignment(Qt.AlignLeft)
 | 
			
		||||
            l2.setAlignment(Qt.AlignLeft)
 | 
			
		||||
 | 
			
		||||
            l_v = QLabel()
 | 
			
		||||
            l_v.setNum(data.slaves[stack_id].cell_voltages[i])
 | 
			
		||||
            l_v.setAlignment(Qt.AlignLeft)
 | 
			
		||||
            self.voltage_labels.append(l_v)
 | 
			
		||||
 | 
			
		||||
            grid.addWidget(l1, i, 0)
 | 
			
		||||
            grid.addWidget(l_v, i, 1)
 | 
			
		||||
 | 
			
		||||
        # vertical separators between rows in popup
 | 
			
		||||
        separator_vertical = QVSeperationLine()
 | 
			
		||||
        grid.addWidget(separator_vertical, 0, 2, CELLS_PER_SLAVE, 1)
 | 
			
		||||
        num_temp_cols = len(data.slaves[stack_id].cell_temps) // CELLS_PER_SLAVE
 | 
			
		||||
        for i in range(num_temp_cols):
 | 
			
		||||
            separator_vertical = QVSeperationLine()
 | 
			
		||||
            grid.addWidget(separator_vertical, 0, 5 + i * 3, CELLS_PER_SLAVE, 1)
 | 
			
		||||
 | 
			
		||||
        for i in range(len(data.slaves[stack_id].cell_temps)):
 | 
			
		||||
            l2 = QLabel(f"Temp. Sensor {i}")
 | 
			
		||||
            l2.setAlignment(Qt.AlignLeft)
 | 
			
		||||
 | 
			
		||||
            l_t = QLabel()
 | 
			
		||||
            l_t.setNum(data.slaves[stack_id].cell_temps[i])
 | 
			
		||||
            l_t.setAlignment(Qt.AlignLeft)
 | 
			
		||||
            self.temp_labels.append(l_t)
 | 
			
		||||
 | 
			
		||||
            grid.addWidget(l1, i, 0)
 | 
			
		||||
            grid.addWidget(l2, i, 2)
 | 
			
		||||
            grid.addWidget(l_v, i, 1)
 | 
			
		||||
            grid.addWidget(l_t, i, 3)
 | 
			
		||||
            grid.addWidget(l2, i % CELLS_PER_SLAVE, 3 + (i // CELLS_PER_SLAVE) * 3)
 | 
			
		||||
            grid.addWidget(l_t, i % CELLS_PER_SLAVE, 4 + (i // CELLS_PER_SLAVE) * 3)
 | 
			
		||||
 | 
			
		||||
        groupbox.setTitle(f"Stack {stack_id}")
 | 
			
		||||
        groupbox.setLayout(grid)
 | 
			
		||||
@ -200,6 +228,7 @@ class StackPopup(QWidget):
 | 
			
		||||
    def update_data(self):
 | 
			
		||||
        for i in range(len(data.slaves[self.stack_id].cell_voltages)):
 | 
			
		||||
            self.voltage_labels[i].setNum(data.slaves[self.stack_id].cell_voltages[i])
 | 
			
		||||
        for i in range(len(data.slaves[self.stack_id].cell_temps)):
 | 
			
		||||
            self.temp_labels[i].setNum(data.slaves[self.stack_id].cell_temps[i])
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user