gepumpe menge angezeigt

This commit is contained in:
jens 2025-07-10 21:26:27 +02:00
parent e3cf7c363a
commit 3733c95147
2 changed files with 33 additions and 22 deletions

View File

@ -52,9 +52,15 @@ class PHControllerGUI(QMainWindow):
self.flow_rate_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.flow_rate_label.setVisible(False) # Initially hidden
self.total_volume_label = QLabel("Gesamt: 0.0 ml")
self.total_volume_label.setFont(QFont('Arial', 12))
self.total_volume_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.total_volume_label.setVisible(False) # Initially hidden
status_layout.addWidget(self.ph_label)
status_layout.addWidget(self.pump_status)
status_layout.addWidget(self.flow_rate_label)
status_layout.addWidget(self.total_volume_label)
status_group.setLayout(status_layout)
# Control Group
@ -147,6 +153,10 @@ class PHControllerGUI(QMainWindow):
# Track pump state
self.pump_is_running = False
# Volume tracking
self.total_volume = 0.0 # Total volume pumped in ml
self.last_flow_rate = 0.0 # Last known flow rate
# Enable/disable controls based on connection
self.set_controls_enabled(False)
@ -205,7 +215,10 @@ class PHControllerGUI(QMainWindow):
self.ph_label.setText("pH: --")
self.pump_status.setText("Pumpe: --")
self.flow_rate_label.setVisible(False)
self.total_volume_label.setVisible(False)
self.pump_is_running = False
self.total_volume = 0.0
self.last_flow_rate = 0.0
def set_controls_enabled(self, enabled):
self.pump_on_btn.setEnabled(enabled)
@ -246,26 +259,40 @@ class PHControllerGUI(QMainWindow):
if self.serial_connection and self.serial_connection.is_open and self.pump_is_running:
self.send_command("<18>") # Request current flow rate
def update_total_volume(self, flow_rate):
"""Update the total volume based on current flow rate"""
if self.pump_is_running:
# Add volume from the last second (flow_rate is ml/sec)
self.total_volume += flow_rate * 1.0 # 1 second interval
self.total_volume_label.setText(f"Gesamt: {self.total_volume:.2f} ml")
self.last_flow_rate = flow_rate
def send_pump_command(self, state):
if state == 1:
self.send_command("<11>") # Pump on
self.pump_status.setText("Pumpe: Ein")
self.pump_is_running = True
self.flow_rate_label.setVisible(True)
self.total_volume_label.setVisible(True)
# Reset volume counter and start timing
self.total_volume = 0.0
self.total_volume_label.setText("Gesamt: 0.0 ml")
self.flow_rate_timer.start(1000) # Request flow rate every second
else:
self.send_command("<12>") # Pump off
self.pump_status.setText("Pumpe: Aus")
self.pump_is_running = False
self.flow_rate_label.setVisible(False)
# Keep total_volume_label visible to show final amount
self.flow_rate_timer.stop()
def send_tube_command(self, index):
# Only send command if not updating from Arduino response
if not self.updating_tube_combo:
# Send command in format <120> to <145> for tube indices 0-25
command_number = 120 + index # 120-145 for tubes 0-25
self.send_command(f"<{command_number}>")
# Send command in format <17{tubid}> for tube selection
self.send_command(f"<17{index}>")
self.status_bar.showMessage(f"Schlauchgröße {self.tube_combo.itemText(index)} ausgewählt")
def send_calibration_command(self, ph):
@ -320,6 +347,8 @@ class PHControllerGUI(QMainWindow):
try:
flow_rate = float(data[1:])
self.flow_rate_label.setText(f"ml/sec: {flow_rate:.4f}")
# Update total volume
self.update_total_volume(flow_rate)
except ValueError:
pass
except Exception as e:

View File

@ -302,27 +302,9 @@ if ( RxCmd[1] == '1' ){
}
}
} else {
// Handle other commands like tube selection <120> to <145>
if (RxCmd[0] == '<' && RxCmd[1] == '1') {
// Parse 3-digit commands starting with 1
int cmd = (RxCmd[1] - '0') * 100 + (RxCmd[2] - '0') * 10 + (RxCmd[3] - '0');
if (cmd >= 120 && cmd <= 145) {
// Tube selection: 120-145 maps to tube indices 0-25
int new_tubid = cmd - 120;
if (new_tubid >= 0 && new_tubid <= MAXTUB) {
tubid = new_tubid;
EEPROM.put(ee_tubid, tubid);
Serial.print("<T");
Serial.print(tubid);
Serial.println(">"); // Bestätigung
}
}
}
}
if (CurrentMode == 0){ // Nomral Display Mode
reading(); // Reading LM35 and PH Data for display