74 lines
2.0 KiB
Python
74 lines
2.0 KiB
Python
# pyright: reportGeneralTypeIssues=false
|
|
|
|
import math
|
|
import threading
|
|
import time
|
|
|
|
import dearpygui.dearpygui as dpg
|
|
|
|
import dpg_gauges as dpgg
|
|
|
|
|
|
def main() -> None:
|
|
latest = {"rpm": 0.0, "speed": 0.0}
|
|
lock = threading.Lock()
|
|
stop = threading.Event()
|
|
|
|
def producer() -> None:
|
|
started = time.monotonic()
|
|
while not stop.is_set():
|
|
elapsed = time.monotonic() - started
|
|
with lock:
|
|
latest["rpm"] = 4000 + math.sin(elapsed * 9.0) * 3500
|
|
latest["speed"] = 120 + math.sin(elapsed * 3.0) * 80
|
|
time.sleep(1 / 240)
|
|
|
|
def gui_update() -> None:
|
|
with lock:
|
|
rpm = latest["rpm"]
|
|
speed = latest["speed"]
|
|
dpgg.set_value("rpm", rpm)
|
|
dpgg.set_value("speed", speed)
|
|
dpg.set_frame_callback(dpg.get_frame_count() + 1, gui_update)
|
|
|
|
dpg.create_context()
|
|
thread = threading.Thread(target=producer, daemon=True)
|
|
try:
|
|
with dpg.window(label="High Rate", width=620, height=360):
|
|
dpgg.analog_gauge(
|
|
tag="rpm",
|
|
label="RPM",
|
|
value=0,
|
|
max_value=8000,
|
|
redline_start=6500,
|
|
width=240,
|
|
height=240,
|
|
animation=False,
|
|
smoothing=dpgg.SmoothingConfig(enabled=True, alpha=0.22, max_step=500),
|
|
)
|
|
dpgg.digital_gauge(
|
|
tag="speed",
|
|
label="Speed",
|
|
value=0,
|
|
max_value=240,
|
|
unit="km/h",
|
|
width=260,
|
|
height=90,
|
|
animation=dpgg.AnimationConfig(enabled=True, duration=0.12),
|
|
)
|
|
|
|
dpg.create_viewport(title="dpg-gauges high rate", width=660, height=400)
|
|
dpg.setup_dearpygui()
|
|
thread.start()
|
|
dpg.set_frame_callback(1, gui_update)
|
|
dpg.show_viewport()
|
|
dpg.start_dearpygui()
|
|
finally:
|
|
stop.set()
|
|
thread.join(timeout=1.0)
|
|
dpg.destroy_context()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|