dosierung ok
This commit is contained in:
parent
c5c4aa2627
commit
74e4b5f199
90
gui/main.py
90
gui/main.py
@ -165,6 +165,12 @@ class PHControllerGUI(QMainWindow):
|
||||
self.total_volume = 0.0 # Total volume pumped in ml
|
||||
self.last_flow_rate = 0.0 # Last known flow rate
|
||||
|
||||
# Auto dosing
|
||||
self.auto_dosing = False
|
||||
self.target_volume = 0.0
|
||||
self.auto_dose_timer = QTimer()
|
||||
self.auto_dose_timer.timeout.connect(self.check_auto_dose_progress)
|
||||
|
||||
# Enable/disable controls based on connection
|
||||
self.set_controls_enabled(False)
|
||||
|
||||
@ -227,6 +233,10 @@ class PHControllerGUI(QMainWindow):
|
||||
# Stop flow rate polling
|
||||
self.flow_rate_timer.stop()
|
||||
|
||||
# Stop auto dose timer
|
||||
self.auto_dose_timer.stop()
|
||||
self.auto_dosing = False
|
||||
|
||||
self.connect_btn.setText("Verbinden")
|
||||
self.status_bar.showMessage("Getrennt")
|
||||
self.set_controls_enabled(False)
|
||||
@ -237,6 +247,8 @@ class PHControllerGUI(QMainWindow):
|
||||
self.pump_is_running = False
|
||||
self.total_volume = 0.0
|
||||
self.last_flow_rate = 0.0
|
||||
self.auto_dosing = False
|
||||
self.auto_dose_timer.stop()
|
||||
|
||||
def set_controls_enabled(self, enabled):
|
||||
self.pump_on_btn.setEnabled(enabled)
|
||||
@ -296,8 +308,8 @@ class PHControllerGUI(QMainWindow):
|
||||
self.total_volume_label.setVisible(True)
|
||||
|
||||
# Check if volume should be reset or continue accumulating
|
||||
if self.reset_volume_checkbox.isChecked():
|
||||
# Reset volume counter
|
||||
if self.reset_volume_checkbox.isChecked() or self.auto_dosing:
|
||||
# Reset volume counter (always reset for auto dosing)
|
||||
self.total_volume = 0.0
|
||||
self.total_volume_label.setText("Gesamt: 0.0 ml")
|
||||
else:
|
||||
@ -313,6 +325,15 @@ class PHControllerGUI(QMainWindow):
|
||||
# Keep total_volume_label visible to show final amount
|
||||
self.flow_rate_timer.stop()
|
||||
|
||||
# Stop auto dosing if it was running
|
||||
if self.auto_dosing:
|
||||
self.auto_dosing = False
|
||||
self.auto_dose_timer.stop()
|
||||
self.auto_dose_btn.setText("Automatisch dosieren")
|
||||
self.auto_dose_btn.setEnabled(True)
|
||||
QMessageBox.information(self, "Automatische Dosierung",
|
||||
f"Dosierung abgeschlossen!\nGepumpte Menge: {self.total_volume:.2f} ml")
|
||||
|
||||
def send_tube_command(self, index):
|
||||
# Only send command if not updating from Arduino response
|
||||
if not self.updating_tube_combo:
|
||||
@ -336,12 +357,66 @@ class PHControllerGUI(QMainWindow):
|
||||
self.status_bar.showMessage("Debug-Informationen angefragt...")
|
||||
|
||||
def start_auto_dose(self):
|
||||
if self.auto_dosing:
|
||||
# Stop auto dosing
|
||||
self.auto_dosing = False
|
||||
self.auto_dose_timer.stop()
|
||||
self.send_pump_command(0) # Turn off pump
|
||||
self.auto_dose_btn.setText("Automatisch dosieren")
|
||||
return
|
||||
|
||||
volume = self.volume_spin.value()
|
||||
# Calculate pump run time based on tube size and volume
|
||||
# This would need to be implemented based on your specific setup
|
||||
QMessageBox.information(self, "Automatische Dosierung",
|
||||
f"Es werden {volume} ml dosiert. Bitte warten...")
|
||||
# Implementation would need to send appropriate commands to Arduino
|
||||
self.target_volume = volume
|
||||
self.auto_dosing = True
|
||||
|
||||
# Update button text and disable manual pump controls during auto dosing
|
||||
self.auto_dose_btn.setText("Stop Dosierung")
|
||||
self.pump_on_btn.setEnabled(False)
|
||||
self.pump_off_btn.setEnabled(False)
|
||||
|
||||
# Reset volume counter for accurate measurement
|
||||
self.total_volume = 0.0
|
||||
|
||||
# Start pumping
|
||||
self.send_pump_command(1)
|
||||
|
||||
# Start monitoring timer (check every 0.5 seconds for better precision)
|
||||
self.auto_dose_timer.start(500)
|
||||
|
||||
self.status_bar.showMessage(f"Automatische Dosierung läuft... Ziel: {volume} ml")
|
||||
|
||||
def check_auto_dose_progress(self):
|
||||
"""Check if target volume has been reached during auto dosing"""
|
||||
if not self.auto_dosing:
|
||||
return
|
||||
|
||||
# Check if we've reached or exceeded the target volume
|
||||
if self.total_volume >= self.target_volume:
|
||||
# Stop dosing
|
||||
self.auto_dosing = False
|
||||
self.auto_dose_timer.stop()
|
||||
self.send_pump_command(0) # Turn off pump
|
||||
|
||||
# Re-enable manual controls
|
||||
self.pump_on_btn.setEnabled(True)
|
||||
self.pump_off_btn.setEnabled(True)
|
||||
self.auto_dose_btn.setText("Automatisch dosieren")
|
||||
|
||||
# Show completion message
|
||||
actual_volume = self.total_volume
|
||||
difference = actual_volume - self.target_volume
|
||||
|
||||
message = f"Dosierung abgeschlossen!\n"
|
||||
message += f"Zielvolumen: {self.target_volume:.2f} ml\n"
|
||||
message += f"Tatsächliches Volumen: {actual_volume:.2f} ml\n"
|
||||
message += f"Abweichung: {difference:+.2f} ml"
|
||||
|
||||
QMessageBox.information(self, "Automatische Dosierung", message)
|
||||
self.status_bar.showMessage(f"Dosierung abgeschlossen: {actual_volume:.2f} ml von {self.target_volume:.2f} ml")
|
||||
else:
|
||||
# Update progress in status bar
|
||||
progress = (self.total_volume / self.target_volume) * 100
|
||||
self.status_bar.showMessage(f"Dosierung: {self.total_volume:.2f}/{self.target_volume:.2f} ml ({progress:.1f}%)")
|
||||
|
||||
def read_serial_data(self):
|
||||
if not self.serial_connection or not self.serial_connection.is_open:
|
||||
@ -409,6 +484,7 @@ class PHControllerGUI(QMainWindow):
|
||||
self.ph_request_timer.stop()
|
||||
self.tube_request_timer.stop()
|
||||
self.flow_rate_timer.stop()
|
||||
self.auto_dose_timer.stop()
|
||||
self.close_connection()
|
||||
event.accept()
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user