schlauch und flowrate ok
This commit is contained in:
parent
05236edd70
commit
e3cf7c363a
43
gui/main.py
43
gui/main.py
@ -47,8 +47,14 @@ class PHControllerGUI(QMainWindow):
|
||||
self.pump_status.setFont(QFont('Arial', 16))
|
||||
self.pump_status.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
|
||||
self.flow_rate_label = QLabel("ml/sec: --")
|
||||
self.flow_rate_label.setFont(QFont('Arial', 14))
|
||||
self.flow_rate_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||
self.flow_rate_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_group.setLayout(status_layout)
|
||||
|
||||
# Control Group
|
||||
@ -134,6 +140,13 @@ class PHControllerGUI(QMainWindow):
|
||||
self.tube_request_timer = QTimer()
|
||||
self.tube_request_timer.timeout.connect(self.request_tube_id)
|
||||
|
||||
# Timer for flow rate requests (when pump is running)
|
||||
self.flow_rate_timer = QTimer()
|
||||
self.flow_rate_timer.timeout.connect(self.request_flow_rate)
|
||||
|
||||
# Track pump state
|
||||
self.pump_is_running = False
|
||||
|
||||
# Enable/disable controls based on connection
|
||||
self.set_controls_enabled(False)
|
||||
|
||||
@ -183,11 +196,16 @@ class PHControllerGUI(QMainWindow):
|
||||
# Stop tube ID polling
|
||||
self.tube_request_timer.stop()
|
||||
|
||||
# Stop flow rate polling
|
||||
self.flow_rate_timer.stop()
|
||||
|
||||
self.connect_btn.setText("Verbinden")
|
||||
self.status_bar.showMessage("Getrennt")
|
||||
self.set_controls_enabled(False)
|
||||
self.ph_label.setText("pH: --")
|
||||
self.pump_status.setText("Pumpe: --")
|
||||
self.flow_rate_label.setVisible(False)
|
||||
self.pump_is_running = False
|
||||
|
||||
def set_controls_enabled(self, enabled):
|
||||
self.pump_on_btn.setEnabled(enabled)
|
||||
@ -223,21 +241,31 @@ class PHControllerGUI(QMainWindow):
|
||||
if self.serial_connection and self.serial_connection.is_open:
|
||||
self.send_command("<13>") # Request current tube size
|
||||
|
||||
def request_flow_rate(self):
|
||||
"""Request flow rate from Arduino when pump is running"""
|
||||
if self.serial_connection and self.serial_connection.is_open and self.pump_is_running:
|
||||
self.send_command("<18>") # Request current 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.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)
|
||||
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:
|
||||
# Simple approach: send <1XX> where XX is 20+index
|
||||
# This should trigger the default case in Arduino
|
||||
# command_number = 120 + index # 120-145 for tubes 0-25
|
||||
self.send_command(f"<17{index}>")
|
||||
# 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}>")
|
||||
self.status_bar.showMessage(f"Schlauchgröße {self.tube_combo.itemText(index)} ausgewählt")
|
||||
|
||||
def send_calibration_command(self, ph):
|
||||
@ -288,6 +316,12 @@ class PHControllerGUI(QMainWindow):
|
||||
self.status_bar.showMessage(f"Schlauchgröße {self.tube_combo.currentText()} geladen")
|
||||
except ValueError:
|
||||
pass
|
||||
elif data.startswith('F'): # Flow rate (ml/sec)
|
||||
try:
|
||||
flow_rate = float(data[1:])
|
||||
self.flow_rate_label.setText(f"ml/sec: {flow_rate:.4f}")
|
||||
except ValueError:
|
||||
pass
|
||||
except Exception as e:
|
||||
self.status_bar.showMessage(f"Lesefehler: {str(e)}")
|
||||
|
||||
@ -296,6 +330,7 @@ class PHControllerGUI(QMainWindow):
|
||||
self.read_timer.stop()
|
||||
self.ph_request_timer.stop()
|
||||
self.tube_request_timer.stop()
|
||||
self.flow_rate_timer.stop()
|
||||
self.close_connection()
|
||||
event.accept()
|
||||
|
||||
|
||||
@ -293,18 +293,32 @@ if ( RxCmd[1] == '1' ){
|
||||
}
|
||||
break;
|
||||
}
|
||||
case '8':{ // Schlauchdaten anfordern
|
||||
Serial.print('<');
|
||||
Serial.print('#');
|
||||
double mlpersec =( ml[tubid]*korrf*2)/6; // tube * 20 Um/min * korecturfaktor durch 60 sec
|
||||
mlpersec = mlpersec*100000;
|
||||
Serial.print(mlpersec); //
|
||||
Serial.println('>');
|
||||
case '8':{// Flow Rate anfordern (ml/sec)
|
||||
Serial.print("<F");
|
||||
double mlpersec = (ml[tubid] * korrf * 20) / 60; // tube * korrektur * 20 rpm / 60 sec
|
||||
Serial.print(mlpersec, 4); // 4 decimal places
|
||||
Serial.println(">");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user