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