Simple serial monitor implementation

This commit is contained in:
2026-05-12 20:02:42 +02:00
parent d61ad11428
commit 5c840538fb
13 changed files with 337 additions and 88 deletions

View File

@@ -5,12 +5,25 @@
import dearpygui.dearpygui as dpg
from dataflux.state import AppState
from dataflux.tags import MENU_FILE_CONNECT, MENU_FILE_DISCONNECT
from dataflux.tags import (
MENU_IO_CONNECT_LORA,
MENU_IO_CONNECT_SERIAL,
MENU_IO_DISCONNECT_LORA,
MENU_IO_DISCONNECT_SERIAL,
)
def update_menu_file_connection_status(state: AppState) -> None:
if state.serial_port is None:
dpg.enable_item(MENU_FILE_CONNECT)
dpg.disable_item(MENU_FILE_DISCONNECT)
if state.lora_port is None:
dpg.enable_item(MENU_IO_CONNECT_LORA)
dpg.disable_item(MENU_IO_DISCONNECT_LORA)
else:
dpg.disable_item(MENU_FILE_CONNECT)
dpg.enable_item(MENU_FILE_DISCONNECT)
dpg.disable_item(MENU_IO_CONNECT_LORA)
dpg.enable_item(MENU_IO_DISCONNECT_LORA)
if state.serial_port is None:
dpg.enable_item(MENU_IO_CONNECT_SERIAL)
dpg.disable_item(MENU_IO_DISCONNECT_SERIAL)
else:
dpg.disable_item(MENU_IO_CONNECT_SERIAL)
dpg.enable_item(MENU_IO_DISCONNECT_SERIAL)

View File

@@ -4,10 +4,26 @@
import dearpygui.dearpygui as dpg
from dataflux.state import AppState
from dataflux.tags import STATUS_SERIAL_STATUS_BOX, STATUS_SERIAL_STATUS_TEXT, THEME_STATUS_CONNECTED, THEME_STATUS_CONNECTED_BRIGHT, THEME_STATUS_DISCONNECTED
from dataflux.tags import (
STATUS_LORA_STATUS_BOX,
STATUS_LORA_STATUS_TEXT,
STATUS_SERIAL_STATUS_BOX,
STATUS_SERIAL_STATUS_TEXT,
THEME_STATUS_CONNECTED,
THEME_STATUS_CONNECTED_BRIGHT,
THEME_STATUS_DISCONNECTED,
)
from time import sleep
def update_status_connection_status(state: AppState):
if state.lora_port is None:
dpg.bind_item_theme(STATUS_LORA_STATUS_BOX, THEME_STATUS_DISCONNECTED)
dpg.set_value(STATUS_LORA_STATUS_TEXT, "LoRa: Disconnected")
else:
dpg.bind_item_theme(STATUS_LORA_STATUS_BOX, THEME_STATUS_CONNECTED)
dpg.set_value(STATUS_LORA_STATUS_TEXT, "LoRa: Connected")
if state.serial_port is None:
dpg.bind_item_theme(STATUS_SERIAL_STATUS_BOX, THEME_STATUS_DISCONNECTED)
dpg.set_value(STATUS_SERIAL_STATUS_TEXT, "Serial: Disconnected")
@@ -15,7 +31,8 @@ def update_status_connection_status(state: AppState):
dpg.bind_item_theme(STATUS_SERIAL_STATUS_BOX, THEME_STATUS_CONNECTED)
dpg.set_value(STATUS_SERIAL_STATUS_TEXT, "Serial: Connected")
def flash_status_connection_status(duration: float) -> None:
dpg.bind_item_theme(STATUS_SERIAL_STATUS_BOX, THEME_STATUS_CONNECTED_BRIGHT)
sleep(duration)
dpg.bind_item_theme(STATUS_SERIAL_STATUS_BOX, THEME_STATUS_CONNECTED)
dpg.bind_item_theme(STATUS_LORA_STATUS_BOX, THEME_STATUS_CONNECTED_BRIGHT)
sleep(duration)
dpg.bind_item_theme(STATUS_LORA_STATUS_BOX, THEME_STATUS_CONNECTED)

View File

@@ -5,21 +5,47 @@ import dearpygui.dearpygui as dpg
import dataflux.config
from dataflux.services.serial import list_serial_ports
from dataflux.tags import PAGE_LAP_RECAP, PAGE_LIVE_DATA, SUB_PAGE_DATA_GRAPHS, SUB_PAGE_MAP, WINDOW_CONNECTION_MENU_COMBO
from dataflux.state import AppState
from dataflux.tags import (
PAGE_LAP_RECAP,
PAGE_LIVE_DATA,
PAGE_SERIAL_CONSOLE,
SUB_PAGE_DATA_GRAPHS,
SUB_PAGE_MAP,
WINDOW_LORA_CONNECTION_MENU_COMBO,
WINDOW_SERIAL_CONNECTION_MENU_COMBO,
)
def update_window_connection_menu_combo() -> None:
def update_window_lora_connection_menu_combo(state: AppState) -> None:
ports: list[str] = list_serial_ports()
dpg.configure_item(WINDOW_CONNECTION_MENU_COMBO, items=ports)
if state.serial_port is not None and state.serial_thread_running:
port_name = state.serial_port.name
if port_name in ports:
ports.remove(port_name)
dpg.configure_item(WINDOW_LORA_CONNECTION_MENU_COMBO, items=ports)
def update_window_serial_connection_menu_combo(state: AppState) -> None:
ports: list[str] = list_serial_ports()
if state.lora_port is not None and state.lora_thread_running:
port_name = state.lora_port.name
if port_name in ports:
ports.remove(port_name)
dpg.configure_item(WINDOW_SERIAL_CONNECTION_MENU_COMBO, items=ports)
def hide_all_but(tag: str) -> None:
arr = [PAGE_LIVE_DATA, PAGE_LAP_RECAP]
arr = [PAGE_LIVE_DATA, PAGE_LAP_RECAP, PAGE_SERIAL_CONSOLE]
for item in arr:
if tag == item:
dpg.show_item(item)
else:
dpg.hide_item(item)
def toggle_window(tag: str) -> None:
if tag == SUB_PAGE_DATA_GRAPHS:
dpg.show_item(SUB_PAGE_DATA_GRAPHS)
@@ -31,6 +57,3 @@ def toggle_window(tag: str) -> None:
hide_all_but(PAGE_LIVE_DATA)
else:
hide_all_but(tag)