Added gauges on connector connect
This commit is contained in:
@@ -13,9 +13,12 @@ import sys
|
|||||||
|
|
||||||
from dynalab.data.json import json_thread_main
|
from dynalab.data.json import json_thread_main
|
||||||
from dynalab.state import AppState
|
from dynalab.state import AppState
|
||||||
|
from dynalab.tags import MENU_WINDOW_DATA_INPUT
|
||||||
import dynalab.ui.windows
|
import dynalab.ui.windows
|
||||||
from dynalab.ui.windows import build_loading, build_windows
|
from dynalab.ui.windows import build_loading, build_windows
|
||||||
|
|
||||||
|
import dpg_gauges as dpgg
|
||||||
|
|
||||||
|
|
||||||
def _setup_logging(level: int = logging.INFO) -> None:
|
def _setup_logging(level: int = logging.INFO) -> None:
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
@@ -160,6 +163,24 @@ def run() -> None:
|
|||||||
except Exception:
|
except Exception:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
|
try:
|
||||||
|
new_signal = state.new_signal_queue.get_nowait()
|
||||||
|
except Empty:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
dpgg.analog_gauge(
|
||||||
|
tag=f"{new_signal.id}",
|
||||||
|
label=f"{new_signal.name}",
|
||||||
|
parent=MENU_WINDOW_DATA_INPUT,
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
removed_signal = state.removed_signal_queue.get_nowait()
|
||||||
|
except Empty:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
dpgg.delete_gauge(f"{removed_signal.id}")
|
||||||
|
|
||||||
# Render frame
|
# Render frame
|
||||||
dpg.render_dearpygui_frame()
|
dpg.render_dearpygui_frame()
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
@@ -79,6 +79,9 @@ async def _handle_connector(
|
|||||||
)
|
)
|
||||||
await write_message(writer, handshake_accepted)
|
await write_message(writer, handshake_accepted)
|
||||||
|
|
||||||
|
for signal in connector_hello.signals:
|
||||||
|
state.new_signal_queue.put(signal)
|
||||||
|
|
||||||
heartbeat_task = asyncio.create_task(_heartbeat_loop(writer))
|
heartbeat_task = asyncio.create_task(_heartbeat_loop(writer))
|
||||||
timeout_event = asyncio.Event()
|
timeout_event = asyncio.Event()
|
||||||
timeout_task = asyncio.create_task(
|
timeout_task = asyncio.create_task(
|
||||||
@@ -103,6 +106,8 @@ async def _handle_connector(
|
|||||||
return
|
return
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
for signal in connector_hello.signals:
|
||||||
|
state.removed_signal_queue.put(signal)
|
||||||
heartbeat_task.cancel()
|
heartbeat_task.cancel()
|
||||||
timeout_task.cancel()
|
timeout_task.cancel()
|
||||||
print(f"Connector disconnected {peer}")
|
print(f"Connector disconnected {peer}")
|
||||||
|
|||||||
@@ -2,12 +2,17 @@
|
|||||||
# 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 dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
|
from queue import Queue
|
||||||
import threading
|
import threading
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
|
from dynalab_protocol.models import SignalDescriptor
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class AppState:
|
class AppState:
|
||||||
stop_event = threading.Event()
|
stop_event = threading.Event()
|
||||||
data_json_thread: threading.Thread | None = None
|
data_json_thread: threading.Thread | None = None
|
||||||
last_heartbeat: dict[UUID, int] = field(default_factory=dict)
|
last_heartbeat: dict[UUID, int] = field(default_factory=dict)
|
||||||
|
new_signal_queue: Queue[SignalDescriptor] = Queue()
|
||||||
|
removed_signal_queue: Queue[SignalDescriptor] = Queue()
|
||||||
|
|||||||
@@ -25,5 +25,14 @@ def build_windows() -> None:
|
|||||||
with dpg.child_window(
|
with dpg.child_window(
|
||||||
tag="content_area", autosize_x=True, height=0, border=False
|
tag="content_area", autosize_x=True, height=0, border=False
|
||||||
):
|
):
|
||||||
with dpg.group(tag=MENU_WINDOW_DATA_INPUT):
|
# with dpg.group(tag=MENU_WINDOW_DATA_INPUT):
|
||||||
dpgg.status_light(label="JSON", show_value=False)
|
with dpgg.gauge_panel(
|
||||||
|
label="Autobreak narrow panel", width=430, height=285
|
||||||
|
):
|
||||||
|
with dpgg.gauge_grid(
|
||||||
|
columns="auto", min_column_width=180, tag=MENU_WINDOW_DATA_INPUT
|
||||||
|
):
|
||||||
|
dpgg.analog_gauge(
|
||||||
|
tag="test_gauge",
|
||||||
|
label="new_gauge",
|
||||||
|
)
|
||||||
|
|||||||
@@ -40,7 +40,34 @@ async def main() -> None:
|
|||||||
signals: list[SignalDescriptor] = [
|
signals: list[SignalDescriptor] = [
|
||||||
SignalDescriptor(
|
SignalDescriptor(
|
||||||
id=uuid.uuid4(), name="lambda", type="number", min_value=0, max_value=5
|
id=uuid.uuid4(), name="lambda", type="number", min_value=0, max_value=5
|
||||||
)
|
),
|
||||||
|
SignalDescriptor(
|
||||||
|
id=uuid.uuid4(), name="torque", type="number", min_value=0, max_value=10
|
||||||
|
),
|
||||||
|
SignalDescriptor(
|
||||||
|
id=uuid.uuid4(), name="RPM", type="number", min_value=0, max_value=6000
|
||||||
|
),
|
||||||
|
SignalDescriptor(
|
||||||
|
id=uuid.uuid4(),
|
||||||
|
name="temperature",
|
||||||
|
type="number",
|
||||||
|
min_value=0,
|
||||||
|
max_value=120,
|
||||||
|
),
|
||||||
|
SignalDescriptor(
|
||||||
|
id=uuid.uuid4(),
|
||||||
|
name="voltage",
|
||||||
|
type="number",
|
||||||
|
min_value=0,
|
||||||
|
max_value=20,
|
||||||
|
),
|
||||||
|
SignalDescriptor(
|
||||||
|
id=uuid.uuid4(),
|
||||||
|
name="current",
|
||||||
|
type="number",
|
||||||
|
min_value=0,
|
||||||
|
max_value=50,
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
connector_hello = ConnectorHello(
|
connector_hello = ConnectorHello(
|
||||||
|
|||||||
2
uv.lock
generated
2
uv.lock
generated
@@ -28,7 +28,7 @@ wheels = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dpg-gauges"
|
name = "dpg-gauges"
|
||||||
version = "0.1.0b1"
|
version = "1.1.0"
|
||||||
source = { editable = "../../dpg-gauges" }
|
source = { editable = "../../dpg-gauges" }
|
||||||
dependencies = [
|
dependencies = [
|
||||||
{ name = "dearpygui" },
|
{ name = "dearpygui" },
|
||||||
|
|||||||
Reference in New Issue
Block a user