diff --git a/pytec/pytec/gui/view/ctrl_panel.py b/pytec/pytec/gui/view/ctrl_panel.py index 0913004..76e49cf 100644 --- a/pytec/pytec/gui/view/ctrl_panel.py +++ b/pytec/pytec/gui/view/ctrl_panel.py @@ -101,6 +101,7 @@ class CtrlPanel(QObject): self.thermostat.thermistor_update.connect(self.update_thermistor) self.thermostat.pwm_update.connect(self.update_pwm) self.thermostat.postfilter_update.connect(self.update_postfilter) + self.autotuners.autotune_state_changed.connect(self.update_pid_autotune) def _setValue(self, value, blockSignal=None): """ @@ -256,6 +257,31 @@ class CtrlPanel(QObject): "Thermistor Config", "Postfilter Rate" ).setValue(postfilter_params["rate"]) + def update_pid_autotune(self, ch, state): + match state: + case PIDAutotuneState.STATE_OFF: + self.change_params_title( + ch, ("PID Config", "PID Auto Tune", "Run"), "Run" + ) + case ( + PIDAutotuneState.STATE_READY + | PIDAutotuneState.STATE_RELAY_STEP_UP + | PIDAutotuneState.STATE_RELAY_STEP_DOWN + ): + self.change_params_title( + ch, ("PID Config", "PID Auto Tune", "Run"), "Stop" + ) + case PIDAutotuneState.STATE_SUCCEEDED: + self.info_box.display_info_box( + "PID Autotune Success", + f"Channel {ch} PID Config has been loaded to Thermostat. Regulating temperature.", + ) + case PIDAutotuneState.STATE_FAILED: + self.info_box.display_info_box( + "PID Autotune Failed", + f"Channel {ch} PID Autotune has failed.", + ) + @asyncSlot(int) async def load_settings(self, ch): await self.thermostat.load_cfg(ch) diff --git a/pytec/tec_qt.py b/pytec/tec_qt.py index 41a03ae..4ce5440 100755 --- a/pytec/tec_qt.py +++ b/pytec/tec_qt.py @@ -209,34 +209,12 @@ class MainWindow(QtWidgets.QMainWindow): async def pid_autotune_handler(self, _ch, _state): ch_tuning = [] for ch in range(self.NUM_CHANNELS): - match self.autotuners.get_state(ch): - case PIDAutotuneState.STATE_OFF: - self.ctrl_panel_view.change_params_title( - ch, ("PID Config", "PID Auto Tune", "Run"), "Run" - ) - case ( - PIDAutotuneState.STATE_READY - | PIDAutotuneState.STATE_RELAY_STEP_UP - | PIDAutotuneState.STATE_RELAY_STEP_DOWN - ): - self.ctrl_panel_view.change_params_title( - ch, ("PID Config", "PID Auto Tune", "Run"), "Stop" - ) - ch_tuning.append(ch) - - case PIDAutotuneState.STATE_SUCCEEDED: - self.info_box.display_info_box( - "PID Autotune Success", - f"Channel {ch} PID Config has been loaded to Thermostat. Regulating temperature.", - ) - self.info_box.show() - - case PIDAutotuneState.STATE_FAILED: - self.info_box.display_info_box( - "PID Autotune Failed", - f"Channel {ch} PID Autotune has failed.", - ) - self.info_box.show() + if self.autotuners.get_state(ch) in { + PIDAutotuneState.STATE_READY, + PIDAutotuneState.STATE_RELAY_STEP_UP, + PIDAutotuneState.STATE_RELAY_STEP_DOWN, + }: + ch_tuning.append(ch) if len(ch_tuning) == 0: self.background_task_lbl.setText("Ready.")