feat: forward UART parsed boot info to main log window
UartMonitorWindow now accepts on_log callback. When boot info (IP, version) is parsed from serial output, it: - Appears in the UART window's own log (prefix [UART]) - Forwards to main window's log panel via on_log callback - Unified [UART] prefix across both windows (was [BOOT] in UART window, [UART] Boot detected: in main log)
This commit is contained in:
@@ -1164,7 +1164,7 @@ class MainWindow(ctk.CTk):
|
|||||||
self._uart_monitor = UartMonitor(port, self._config.serial_baudrate)
|
self._uart_monitor = UartMonitor(port, self._config.serial_baudrate)
|
||||||
self._uart_monitor.on_line = lambda line: self._log_message(f" [UART] {line}")
|
self._uart_monitor.on_line = lambda line: self._log_message(f" [UART] {line}")
|
||||||
self._uart_monitor.on_boot_info = lambda info: (
|
self._uart_monitor.on_boot_info = lambda info: (
|
||||||
self._log_message(f" [UART] Boot detected: IP={info.ip_address}, Ver={info.version}")
|
self._log_message(f" [UART] IP={info.ip_address}, Ver={info.version}")
|
||||||
if info.ip_address or info.version else None
|
if info.ip_address or info.version else None
|
||||||
)
|
)
|
||||||
self._uart_monitor.on_error = lambda e: self._log_message(f" [UART] Error: {e}")
|
self._uart_monitor.on_error = lambda e: self._log_message(f" [UART] Error: {e}")
|
||||||
@@ -1216,7 +1216,10 @@ class MainWindow(ctk.CTk):
|
|||||||
"""Open the UART Monitor window."""
|
"""Open the UART Monitor window."""
|
||||||
port = self._port_var.get()
|
port = self._port_var.get()
|
||||||
baudrate = self._config.serial_baudrate if self._config else 115200
|
baudrate = self._config.serial_baudrate if self._config else 115200
|
||||||
self._uart_window = UartMonitorWindow(self, port=port, baudrate=baudrate)
|
self._uart_window = UartMonitorWindow(
|
||||||
|
self, port=port, baudrate=baudrate,
|
||||||
|
on_log=self._log_message,
|
||||||
|
)
|
||||||
|
|
||||||
def _test_serial_version(self) -> None:
|
def _test_serial_version(self) -> None:
|
||||||
"""Test serial port by sending 'ver()' command and parsing response."""
|
"""Test serial port by sending 'ver()' command and parsing response."""
|
||||||
|
|||||||
+9
-1
@@ -786,6 +786,7 @@ class UartMonitorWindow(ctk.CTkToplevel):
|
|||||||
master: ctk.CTk | ctk.CTkToplevel,
|
master: ctk.CTk | ctk.CTkToplevel,
|
||||||
port: str,
|
port: str,
|
||||||
baudrate: int = 115200,
|
baudrate: int = 115200,
|
||||||
|
on_log: Callable[[str], None] | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the UART monitor window.
|
"""Initialize the UART monitor window.
|
||||||
|
|
||||||
@@ -793,6 +794,7 @@ class UartMonitorWindow(ctk.CTkToplevel):
|
|||||||
master: Parent window (MainWindow).
|
master: Parent window (MainWindow).
|
||||||
port: Serial port device path (e.g., '/dev/ttyUSB0').
|
port: Serial port device path (e.g., '/dev/ttyUSB0').
|
||||||
baudrate: Baud rate for serial communication.
|
baudrate: Baud rate for serial communication.
|
||||||
|
on_log: Optional callback to forward parsed events to main log.
|
||||||
"""
|
"""
|
||||||
super().__init__(master)
|
super().__init__(master)
|
||||||
self.title("UART Monitor")
|
self.title("UART Monitor")
|
||||||
@@ -800,6 +802,8 @@ class UartMonitorWindow(ctk.CTkToplevel):
|
|||||||
self.minsize(480, 360)
|
self.minsize(480, 360)
|
||||||
self.protocol("WM_DELETE_WINDOW", self._on_close)
|
self.protocol("WM_DELETE_WINDOW", self._on_close)
|
||||||
|
|
||||||
|
self._on_log = on_log
|
||||||
|
|
||||||
self._port = port
|
self._port = port
|
||||||
self._baudrate = baudrate
|
self._baudrate = baudrate
|
||||||
self._monitor: UartMonitor | None = None
|
self._monitor: UartMonitor | None = None
|
||||||
@@ -996,7 +1000,11 @@ class UartMonitorWindow(ctk.CTkToplevel):
|
|||||||
if info.version:
|
if info.version:
|
||||||
parts.append(f"Ver={info.version}")
|
parts.append(f"Ver={info.version}")
|
||||||
if parts:
|
if parts:
|
||||||
self.after(0, lambda: self._log(f"[BOOT] {' '.join(parts)}\n"))
|
msg = f"[UART] {' '.join(parts)}"
|
||||||
|
self.after(0, lambda: self._log(f"{msg}\n"))
|
||||||
|
# Forward to main window log
|
||||||
|
if self._on_log:
|
||||||
|
self.after(0, lambda: self._on_log(msg))
|
||||||
|
|
||||||
def _on_error(self, error: str) -> None:
|
def _on_error(self, error: str) -> None:
|
||||||
self.after(0, lambda: self._log_error(error))
|
self.after(0, lambda: self._log_error(error))
|
||||||
|
|||||||
Reference in New Issue
Block a user