Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions leads_vec/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ def switch() -> None:
return switch


def get_proxy_canvas(context_manager: ContextManager, key: str) -> ProxyCanvas:
r = context_manager[key]
assert isinstance(r, ProxyCanvas)
return r


def main() -> int:
cfg = require_config()
ctx = LEADS(data_seq_size=cfg.data_seq_size, num_laps_timed=cfg.num_laps_timed)
Expand Down Expand Up @@ -80,21 +86,15 @@ def do(self) -> None:

def render(manager: ContextManager) -> None:
m1_widgets = (
Typography(root, theme_key="CTkButton", variable=var_lap_times,
font=("Arial", cfg.font_size_small)),
Typography(root, theme_key="CTkButton", variable=var_gps,
font=("Arial", cfg.font_size_small)),
Base64Photo(root, theme_key="CTkButton", variable=var_rear_view_base64),
Typography(root, theme_key="CTkButton", variable=var_info,
font=("Arial", cfg.font_size_small - 4))
) if has_device(REAR_VIEW_CAMERA) else (
Typography(root, theme_key="CTkButton", variable=var_lap_times,
font=("Arial", cfg.font_size_small)),
Typography(root, theme_key="CTkButton", variable=var_gps,
font=("Arial", cfg.font_size_small)),
Typography(root, theme_key="CTkButton", variable=var_info,
font=("Arial", cfg.font_size_small - 4))
)
if has_device(REAR_VIEW_CAMERA):
m1_widgets += (Base64Photo(root, theme_key="CTkButton", variable=var_rear_view_base64),)
manager["m1"] = ProxyCanvas(root, "CTkButton", *m1_widgets).lock_ratio(cfg.m_ratio)
manager["m2"] = Speedometer(root, variable=var_speed).lock_ratio(cfg.m_ratio)
manager["m3"] = ProxyCanvas(root, "CTkButton",
Expand Down Expand Up @@ -159,6 +159,10 @@ def on_receive(self, service: Service, msg: bytes) -> None:
ctx.time_lap()
case b"hazard":
ctx.hazard(not ctx.hazard())
case b"m1":
get_proxy_canvas(uim, "m1").next_mode()
case b"m3":
get_proxy_canvas(uim, "m3").next_mode()

w.runtime_data().comm = start_server(create_server(cfg.comm_port, CommCallback()), True)

Expand All @@ -167,8 +171,11 @@ class CustomListener(EventListener):
def pre_push(self, e: DataPushedEvent) -> None:
self.super(e)
d = e.data.to_dict()
m1, m3 = get_proxy_canvas(uim, "m1"), get_proxy_canvas(uim, "m3")
d["speed_trend"] = ctx.speed_trend()
d["lap_times"] = ctx.lap_times()
d["m1_mode"] = m1.mode()
d["m3_mode"] = m3.mode()
w.runtime_data().comm_notify(d)

@_override
Expand Down
12 changes: 12 additions & 0 deletions leads_vec_rc/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,16 @@ async def hazard() -> str:
return "done"


@app.get("/m1")
async def m1() -> str:
callback.client.send(b"m1")
return "done"


@app.get("/m3")
async def m3() -> str:
callback.client.send(b"m3")
return "done"


register(csv.close)