From 401f19d2371be53840ab6f314e8687f088e1bfc7 Mon Sep 17 00:00:00 2001 From: Jan Date: Wed, 9 Jul 2025 18:45:36 +0200 Subject: [PATCH] MainCode/adalm1000_logger.py aktualisiert Alles sollte funktionieren. (D) --- MainCode/adalm1000_logger.py | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/MainCode/adalm1000_logger.py b/MainCode/adalm1000_logger.py index dc9a031..a195842 100644 --- a/MainCode/adalm1000_logger.py +++ b/MainCode/adalm1000_logger.py @@ -218,37 +218,44 @@ class TestSequenceWorker(QObject): def run(self): """Main test sequence loop""" try: - while self._running and (self.continuous_mode or self.parent.cycle_count == 0): - # Reset stop request at start of each cycle + first_cycle = True # Ensure at least one cycle runs + + # Modified while condition to also check parent's continuous_mode state + while (self._running and + (self.parent.continuous_mode_check.isChecked() or first_cycle)): self.parent.request_stop = False self.parent.cycle_count += 1 + first_cycle = False # Only True for the first cycle + # Existing test phases... # 1. Charge phase (constant current) self.charge_phase() if not self._running or self.parent.request_stop: break - + # 2. Rest period after charge self.rest_phase("Post-Charge") if not self._running or self.parent.request_stop: break - + # 3. Discharge phase (capacity measurement) self.discharge_phase() if not self._running or self.parent.request_stop: break - + # 4. Rest period after discharge (only if not stopping) if self._running and not self.parent.request_stop: self.rest_phase("Post-Discharge") - + # Calculate Coulomb efficiency if not stopping if not self.parent.request_stop and self.parent.charge_capacity > 0: - self.parent.coulomb_efficiency = (self.parent.capacity_ah / self.parent.charge_capacity) * 100 - + self.parent.coulomb_efficiency = ( + self.parent.capacity_ah / self.parent.charge_capacity + ) * 100 + # Test completed self.test_completed.emit() - + except Exception as e: self.error_occurred.emit(f"Test sequence error: {str(e)}") finally: @@ -275,7 +282,7 @@ class BatteryTester(QMainWindow): self.interval = 0.1 self.log_dir = os.path.expanduser("~/adalm1000/logs") os.makedirs(self.log_dir, exist_ok=True) - + # Data buffers self.time_data = deque() self.voltage_data = deque() @@ -513,6 +520,7 @@ class BatteryTester(QMainWindow): self.continuous_mode_check.setChecked(True) self.continuous_mode_check.setStyleSheet(f"color: {self.fg_color};") button_layout.addWidget(self.continuous_mode_check) + self.continuous_mode_check.stateChanged.connect(self.handle_continuous_mode_change) controls_layout.addWidget(button_frame) self.main_layout.addWidget(controls_frame) @@ -542,6 +550,14 @@ class BatteryTester(QMainWindow): }} """) + def handle_continuous_mode_change(self, state): + """Handle changes to continuous mode checkbox during operation""" + if not state and self.test_running: # If unchecked during test + self.status_bar.showMessage("Continuous mode disabled - will complete current cycle") + # Optional visual feedback + self.continuous_mode_check.setStyleSheet(f"color: {self.warning_color};") + QTimer.singleShot(2000, lambda: self.continuous_mode_check.setStyleSheet(f"color: {self.fg_color};")) + def setup_plot(self): """Configure the matplotlib plot""" self.fig = Figure(figsize=(8, 5), dpi=100, facecolor=self.bg_color)