laäuft soweit
This commit is contained in:
parent
59a9763f79
commit
c5c4aa2627
38
gui/main.py
38
gui/main.py
@ -101,11 +101,14 @@ class PHControllerGUI(QMainWindow):
|
||||
calibration_layout = QHBoxLayout()
|
||||
self.cal_ph4_btn = QPushButton("Kalibrieren pH4")
|
||||
self.cal_ph7_btn = QPushButton("Kalibrieren pH7")
|
||||
self.debug_btn = QPushButton("Debug Info")
|
||||
self.cal_ph4_btn.clicked.connect(lambda: self.send_calibration_command(4))
|
||||
self.cal_ph7_btn.clicked.connect(lambda: self.send_calibration_command(7))
|
||||
self.debug_btn.clicked.connect(self.send_debug_command)
|
||||
|
||||
calibration_layout.addWidget(self.cal_ph4_btn)
|
||||
calibration_layout.addWidget(self.cal_ph7_btn)
|
||||
calibration_layout.addWidget(self.debug_btn)
|
||||
|
||||
# Auto Mode
|
||||
auto_mode_layout = QHBoxLayout()
|
||||
@ -201,6 +204,16 @@ class PHControllerGUI(QMainWindow):
|
||||
QMessageBox.critical(self, "Fehler", f"Verbindungsfehler: {str(e)}")
|
||||
|
||||
def close_connection(self):
|
||||
# Turn off pump before closing connection for safety
|
||||
if self.serial_connection and self.serial_connection.is_open:
|
||||
try:
|
||||
self.send_command("<12>") # Pump off for safety
|
||||
# Give Arduino time to process the command
|
||||
import time
|
||||
time.sleep(0.1)
|
||||
except:
|
||||
pass # Ignore errors during shutdown
|
||||
|
||||
if self.serial_connection and self.serial_connection.is_open:
|
||||
self.serial_connection.close()
|
||||
self.serial_connection = None
|
||||
@ -231,6 +244,7 @@ class PHControllerGUI(QMainWindow):
|
||||
self.tube_combo.setEnabled(enabled)
|
||||
self.cal_ph4_btn.setEnabled(enabled)
|
||||
self.cal_ph7_btn.setEnabled(enabled)
|
||||
self.debug_btn.setEnabled(enabled)
|
||||
self.auto_dose_btn.setEnabled(enabled)
|
||||
self.volume_spin.setEnabled(enabled)
|
||||
self.reset_volume_checkbox.setEnabled(enabled)
|
||||
@ -316,6 +330,11 @@ class PHControllerGUI(QMainWindow):
|
||||
QMessageBox.information(self, "Kalibrierung",
|
||||
"pH7 Kalibrierung gestartet. Sensor in pH6.86-Lösung tauchen und warten bis der Wert stabil ist.")
|
||||
|
||||
def send_debug_command(self):
|
||||
"""Send debug command to get calibration values"""
|
||||
self.send_command("<19>") # Request debug info
|
||||
self.status_bar.showMessage("Debug-Informationen angefragt...")
|
||||
|
||||
def start_auto_dose(self):
|
||||
volume = self.volume_spin.value()
|
||||
# Calculate pump run time based on tube size and volume
|
||||
@ -362,10 +381,29 @@ class PHControllerGUI(QMainWindow):
|
||||
self.update_total_volume(flow_rate)
|
||||
except ValueError:
|
||||
pass
|
||||
elif data.startswith('DEBUG'): # Debug information
|
||||
# Show debug info in a message box
|
||||
QMessageBox.information(self, "Debug Information",
|
||||
f"Kalibrierungsdaten:\n{data}")
|
||||
elif data.startswith('CAL'): # Calibration confirmation with details
|
||||
# Show calibration info in status bar and message box
|
||||
self.status_bar.showMessage(f"Kalibrierung abgeschlossen: {data}")
|
||||
QMessageBox.information(self, "Kalibrierung",
|
||||
f"Kalibrierung erfolgreich:\n{data}")
|
||||
except Exception as e:
|
||||
self.status_bar.showMessage(f"Lesefehler: {str(e)}")
|
||||
|
||||
def closeEvent(self, event):
|
||||
# Safety: Turn off pump before closing
|
||||
if self.serial_connection and self.serial_connection.is_open:
|
||||
try:
|
||||
self.send_command("<12>") # Ensure pump is off
|
||||
# Give Arduino time to process the command
|
||||
import time
|
||||
time.sleep(0.1)
|
||||
except:
|
||||
pass # Ignore errors during shutdown
|
||||
|
||||
# Stop all timers
|
||||
self.read_timer.stop()
|
||||
self.ph_request_timer.stop()
|
||||
|
||||
@ -199,7 +199,15 @@ void setup(){
|
||||
for (int PhThisReading = 0; PhThisReading < NumReadings; PhThisReading++) // initialize all the Ph readings to 0:
|
||||
PhReadings[PhThisReading] = 0;
|
||||
|
||||
PhRatio = (Ph4Reading - Ph7Reading) / (Ph7Buffer - Ph4Buffer); // Calculate Ph Ratio
|
||||
PhRatio = (double)(Ph4Reading - Ph7Reading) / (Ph7Buffer - Ph4Buffer); // Calculate Ph Ratio
|
||||
|
||||
// Debug output at startup
|
||||
Serial.print("Setup - Ph4Reading: ");
|
||||
Serial.print(Ph4Reading);
|
||||
Serial.print(", Ph7Reading: ");
|
||||
Serial.print(Ph7Reading);
|
||||
Serial.print(", PhRatio: ");
|
||||
Serial.println(PhRatio, 4);
|
||||
|
||||
Serial.begin(9600);
|
||||
while(Serial.available()) Serial.read(); // empty RX buffer
|
||||
@ -262,15 +270,29 @@ if ( RxCmd[1] == '1' ){
|
||||
case '5':{// pH4 Kalibrierung starten
|
||||
Ph4Reading = (int) PhAverage;
|
||||
EEPROM.put(addrph4, Ph4Reading);
|
||||
PhRatio = (Ph4Reading - Ph7Reading) / (Ph7Buffer - Ph4Buffer); // Recalculate ratio
|
||||
Serial.println("<CAL4>"); // Bestätigung
|
||||
PhRatio = (double)(Ph4Reading - Ph7Reading) / (Ph7Buffer - Ph4Buffer); // Recalculate ratio
|
||||
Serial.print("<CAL4>");
|
||||
Serial.print(" Ph4R:");
|
||||
Serial.print(Ph4Reading);
|
||||
Serial.print(" Ph7R:");
|
||||
Serial.print(Ph7Reading);
|
||||
Serial.print(" Ratio:");
|
||||
Serial.print(PhRatio, 4);
|
||||
Serial.println(">");
|
||||
break;
|
||||
}
|
||||
case '6':{// pH7 Kalibrierung starten
|
||||
Ph7Reading = (int) PhAverage;
|
||||
EEPROM.put(addrph7, Ph7Reading);
|
||||
PhRatio = (Ph4Reading - Ph7Reading) / (Ph7Buffer - Ph4Buffer); // Recalculate ratio
|
||||
Serial.println("<CAL7>"); // Bestätigung
|
||||
PhRatio = (double)(Ph4Reading - Ph7Reading) / (Ph7Buffer - Ph4Buffer); // Recalculate ratio
|
||||
Serial.print("<CAL7>");
|
||||
Serial.print(" Ph4R:");
|
||||
Serial.print(Ph4Reading);
|
||||
Serial.print(" Ph7R:");
|
||||
Serial.print(Ph7Reading);
|
||||
Serial.print(" Ratio:");
|
||||
Serial.print(PhRatio, 4);
|
||||
Serial.println(">");
|
||||
break;
|
||||
}
|
||||
case '7':{
|
||||
@ -300,6 +322,21 @@ if ( RxCmd[1] == '1' ){
|
||||
Serial.println(">");
|
||||
break;
|
||||
}
|
||||
case '9':{// Debug: Kalibrierungswerte anzeigen
|
||||
Serial.print("<DEBUG>");
|
||||
Serial.print(" PhAvg:");
|
||||
Serial.print(PhAverage);
|
||||
Serial.print(" Ph4R:");
|
||||
Serial.print(Ph4Reading);
|
||||
Serial.print(" Ph7R:");
|
||||
Serial.print(Ph7Reading);
|
||||
Serial.print(" Ratio:");
|
||||
Serial.print(PhRatio, 4);
|
||||
Serial.print(" PhVal:");
|
||||
Serial.print(PhValue, 2);
|
||||
Serial.println(">");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user