tubid now ok

This commit is contained in:
jens 2025-07-09 22:41:40 +02:00
parent eda8510721
commit 45d4f7e090
2 changed files with 17 additions and 21 deletions

View File

@ -199,6 +199,7 @@ class PHControllerGUI(QMainWindow):
self.volume_spin.setEnabled(enabled)
def send_command(self, command):
print(command)
if self.serial_connection and self.serial_connection.is_open:
try:
self.serial_connection.write(command.encode('utf-8'))
@ -235,8 +236,8 @@ class PHControllerGUI(QMainWindow):
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"<{command_number}>")
# command_number = 120 + index # 120-145 for tubes 0-25
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):

View File

@ -300,33 +300,28 @@ if ( RxCmd[1] == '1' ){
Serial.println("<CAL7>"); // Bestätigung
break;
}
default: {
// Handle tube selection commands (120-145 for tubes 0-25)
// Parse the complete command number
if (RxCmd[2] >= '0' && RxCmd[2] <= '9' && RxCmd[3] >= '0' && RxCmd[3] <= '9') {
// Two digit case: parse the full number
int tens = RxCmd[1] - '0'; // First digit after '<'
int hundreds = RxCmd[2] - '0'; // Second digit
int ones = RxCmd[3] - '0'; // Third digit
int command_number = tens * 100 + hundreds * 10 + ones;
// Check if it's a tube command (120-145)
if (command_number >= 120 && command_number <= 145) {
tubid = command_number - 120; // Convert to 0-25 range
// Validate and save tube ID
if (tubid >= 0 && tubid <= MAXTUB) {
case '7':{
int a = RxCmd[3]-'0';
Serial.println(a);
int b = RxCmd[4] -'3';
Serial.println(b);
// int c = RxCmd[5]-'0';
//Serial.println(c);
if (b>9){ // only one diget
tubid = a;
} else {
tubid = a* 10 + b;
}
if (tubid >= 0 && tubid <= MAXTUB) {
EEPROM.put(ee_tubid, tubid);
Serial.print("<T");
Serial.print(tubid);
Serial.println(">"); // Bestätigung
}
}
}
break;
}
}
}