diff --git a/scripts/test_gui.py b/scripts/test_gui.py index 2a0c38c..85c454c 100644 --- a/scripts/test_gui.py +++ b/scripts/test_gui.py @@ -200,6 +200,8 @@ class PhotomagneticGUI: self.worker = SerialWorker(self) self._monitor_after_id = None + self._last_temp_time = 0.0 + self._temp_interval = 0.0 self._build_ui() @@ -312,6 +314,7 @@ class PhotomagneticGUI: self._disp_labels = {} entries = [ ("Temperature", "--- °C", "temp"), + ("Sample Rate", "---", "sample_rate"), ("Heating State", "---", "heat_state"), ("Heating Temp.", "--- °C", "heat_temp"), ("Device ID", "---", "dev_id"), @@ -341,6 +344,11 @@ class PhotomagneticGUI: log_frame = ttk.LabelFrame(right, text="Log", padding=4) log_frame.pack(fill=tk.BOTH, expand=True, pady=(4, 0)) + log_toolbar = ttk.Frame(log_frame) + log_toolbar.pack(fill=tk.X, pady=(0, 2)) + ttk.Button(log_toolbar, text="Clear", width=6, + command=self._clear_log).pack(side=tk.RIGHT) + self._log_text = scrolledtext.ScrolledText(log_frame, height=12, font=("Consolas", 9), wrap=tk.WORD, state=tk.DISABLED) self._log_text.pack(fill=tk.BOTH, expand=True) @@ -520,6 +528,13 @@ class PhotomagneticGUI: # ── 0x00 TEMP: 设备主动推送, 只更新 live value, 不输出 log ── if cmd == Cmd.TEMP: t = temp_from_data(data) + now = time.time() + if self._last_temp_time > 0: + self._temp_interval = now - self._last_temp_time + hz = 1.0 / self._temp_interval if self._temp_interval > 0 else 0 + self._disp_labels["sample_rate"].configure( + text=f"{self._temp_interval*1000:.0f}ms ({hz:.1f}Hz)") + self._last_temp_time = now self._disp_labels["temp"].configure(text=f"{t:.2f} °C") elif cmd == Cmd.GET_ID: @@ -569,6 +584,11 @@ class PhotomagneticGUI: if 0 <= idx < len(self._ntc_labels): self._ntc_labels[idx].configure(text=f"{idx}:{temp:.1f}") + def _clear_log(self): + self._log_text.configure(state=tk.NORMAL) + self._log_text.delete(1.0, tk.END) + self._log_text.configure(state=tk.DISABLED) + def _append_log(self, msg: str): self._log_text.configure(state=tk.NORMAL) self._log_text.insert(tk.END, msg + "\n")