From c25c49d8c1e0e4f3611f47f582453743c1ec1f0a Mon Sep 17 00:00:00 2001 From: atse Date: Tue, 27 Aug 2024 18:24:56 +0800 Subject: [PATCH] Split PID handler UI up --- pytec/pytec/gui/view/ctrl_panel.py | 26 +++++++++++++++++++++++ pytec/tec_qt.py | 34 ++++++------------------------ 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/pytec/pytec/gui/view/ctrl_panel.py b/pytec/pytec/gui/view/ctrl_panel.py index 5dc8884..654cdc9 100644 --- a/pytec/pytec/gui/view/ctrl_panel.py +++ b/pytec/pytec/gui/view/ctrl_panel.py @@ -100,6 +100,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 change_params_title(self, channel, path, title): self.params[channel].child(*path).setOpts(title=title) @@ -230,6 +231,31 @@ class CtrlPanel(QObject): postfilter_params["rate"] ) + def update_pid_autotune(self, ch, state): + match state: + case PIDAutotuneState.STATE_OFF: + self.change_params_title( + ch, ("pid", "pid_autotune", "run_pid"), "Run" + ) + case ( + PIDAutotuneState.STATE_READY + | PIDAutotuneState.STATE_RELAY_STEP_UP + | PIDAutotuneState.STATE_RELAY_STEP_DOWN + ): + self.change_params_title( + ch, ("pid", "pid_autotune", "run_pid"), "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 b7658e6..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", "pid_autotune", "run_pid"), "Run" - ) - case ( - PIDAutotuneState.STATE_READY - | PIDAutotuneState.STATE_RELAY_STEP_UP - | PIDAutotuneState.STATE_RELAY_STEP_DOWN - ): - self.ctrl_panel_view.change_params_title( - ch, ("pid", "pid_autotune", "run_pid"), "Stop" - ) - ch_tuning.append(ch) - - case PIDAutotuneState.STATE_SUCCEEDED: - self.info_box.display_info_box( - "PID Autotune Success", - f"Channel {ch} PID Settings 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.")