Delocalized serial text output to ui worker thread
This commit is contained in:
@@ -81,7 +81,7 @@ def disconnect_serial(state: AppState) -> None:
|
||||
def lora_status_worker(state: AppState) -> None:
|
||||
while state.lora_thread_running:
|
||||
try:
|
||||
duration = state.lora_status_queue.get(timeout=0.1)
|
||||
duration = state.lora_status_queue.get_nowait()
|
||||
except Empty:
|
||||
continue
|
||||
dataflux.ui.routines.status.flash_status_connection_status(duration)
|
||||
@@ -102,11 +102,7 @@ def serial_reader_worker(state: AppState) -> None:
|
||||
|
||||
if line:
|
||||
text = line.decode("utf-8", errors="replace")
|
||||
|
||||
print(text, end="")
|
||||
|
||||
old = dpg.get_value(TEXT_SERIAL_CONSOLE)
|
||||
dpg.set_value(TEXT_SERIAL_CONSOLE, old + text)
|
||||
state.serial_data_queue.put(text)
|
||||
disconnect_serial(state)
|
||||
dataflux.ui.routines.update_global_connection_status(state)
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ def telemetry_worker(state: AppState):
|
||||
time.sleep(1)
|
||||
continue
|
||||
try:
|
||||
dataframe = state.packet_queue.get(timeout=0.1)
|
||||
dataframe = state.packet_queue.get_nowait()
|
||||
except Empty:
|
||||
continue
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ class AppState:
|
||||
|
||||
serial_port: Serial | None = None
|
||||
serial_thread: Thread | None = None
|
||||
serial_data_queue: Queue | None = field(default_factory=Queue)
|
||||
serial_thread_running: bool = False
|
||||
|
||||
telemetry_thread: Thread | None = None
|
||||
|
||||
12
src/dataflux/ui/routines/serial.py
Normal file
12
src/dataflux/ui/routines/serial.py
Normal file
@@ -0,0 +1,12 @@
|
||||
# Copyright (C) 2026 Hector van der Aa <hector@h3cx.dev>
|
||||
# Copyright (C) 2026 Association Exergie <association.exergie@gmail.com>
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import dearpygui.dearpygui as dpg
|
||||
|
||||
from dataflux.tags import TEXT_SERIAL_CONSOLE
|
||||
|
||||
|
||||
def append_text_to_console(text: str) -> None:
|
||||
old = dpg.get_value(TEXT_SERIAL_CONSOLE)
|
||||
dpg.set_value(TEXT_SERIAL_CONSOLE, old + text)
|
||||
@@ -2,6 +2,7 @@
|
||||
# Copyright (C) 2026 Association Exergie <association.exergie@gmail.com>
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from queue import Empty
|
||||
import dearpygui.dearpygui as dpg
|
||||
import datetime
|
||||
import time
|
||||
@@ -19,6 +20,7 @@ from dataflux.tags import (
|
||||
LIVE_DATA_VEHICLE_TIME_VALUE,
|
||||
LIVE_DATA_SPEED_VALUE,
|
||||
)
|
||||
from dataflux.ui.routines.serial import append_text_to_console
|
||||
|
||||
|
||||
def ui_worker(state: AppState):
|
||||
@@ -36,6 +38,14 @@ def ui_worker(state: AppState):
|
||||
dpg.set_value(LIVE_DATA_UTC_TIME_VALUE, formatted)
|
||||
last_datetime = formatted
|
||||
|
||||
if state.serial_thread_running:
|
||||
try:
|
||||
text = state.serial_data_queue.get_nowait()
|
||||
except Empty:
|
||||
pass
|
||||
else:
|
||||
append_text_to_console(text)
|
||||
|
||||
if state.lora_thread_running and state.telemetry_valid:
|
||||
x_common: list[float] | None = None
|
||||
speed_y: list[float] | None = None
|
||||
|
||||
Reference in New Issue
Block a user