Files
firestar5683 a82935f326 User interfaces and Android Auto
Integrate onroad views, configurable widgets, local settings, steering-profile contracts, Bluetooth and Android Auto with their device and runtime services.

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
Co-authored-by: Daniel Koepping <elkoled@gmail.com>
Co-authored-by: Danny <dannyirwin31@yahoo.com>
Co-authored-by: DimitriChrysafis <Dimitri.chrysafis@gmail.com>
Co-authored-by: Dom <168790843+firestar5683@users.noreply.github.com>
Co-authored-by: Harald Schäfer <harald.the.engineer@gmail.com>
Co-authored-by: Prabhaav Pillai <prabhaav@msu.edu>
Co-authored-by: Shane Smiskol <shane@smiskol.com>
Co-authored-by: dirwin31 <83434411+dirwin31@users.noreply.github.com>
Co-authored-by: firestarsdog <229254897+firestarsdog@users.noreply.github.com>
Co-authored-by: stef <19478336+stefpi@users.noreply.github.com>
Co-authored-by: whoisdomi <dcantu83@gmail.com>

Co-authored-by: Intelli <contact@intelli.software>
Co-authored-by: pharmacomaniac <blittle65@gmail.com>

Co-authored-by: prabhaavp <prabhaav@msu.edu>
2026-10-14 20:02:39 -05:00

62 lines
2.3 KiB
Python

"""Display-only V-ASM warning subscription for the native side-camera preview."""
from collections.abc import Callable
from typing import Any
import openpilot.cereal.messaging as messaging
def _new_reader() -> Any:
# Keep the camera inference package out of the normal UI startup path.
from openpilot.starpilot.spot_monitor.observation import ObservationReader
return ObservationReader()
class PiPWarningSource:
"""Keep one nonblocking full-Event subscription while the preview is eligible."""
def __init__(self, *, subscribe: Callable[[], Any] | None = None,
receive: Callable[[Any], Any] | None = None,
reader: Any = None):
self._subscribe = subscribe or (lambda: messaging.sub_sock("spotMonitorState", conflate=True))
self._receive = receive or messaging.recv_one_or_none
self._reader = reader
self._socket: Any = None
self._active = False
def close(self) -> None:
if not self._active:
return
self._active = False
socket, self._socket = self._socket, None
self._reader = None
if socket is not None:
close = getattr(socket, "close", None)
if callable(close):
try:
close()
except Exception:
pass # Losing an optional visual feed cannot interrupt the UI.
def sample(self, *, enabled: bool, settings_fingerprint: str,
now_mono_ns: int, now_boot_ns: int) -> tuple[bool, bool]:
if not enabled or not isinstance(settings_fingerprint, str) or len(settings_fingerprint) != 64:
self.close()
return False, False
try:
if self._socket is None:
self._socket = self._subscribe()
self._active = True
if self._reader is None:
self._reader = _new_reader()
event = self._receive(self._socket)
warning = (self._reader.read(event, now_mono_ns=now_mono_ns, now_boot_ns=now_boot_ns,
settings_fingerprint=settings_fingerprint) if event is not None else
self._reader.current_at(now_mono_ns=now_mono_ns, now_boot_ns=now_boot_ns,
settings_fingerprint=settings_fingerprint))
return bool(warning.display_left.warning), bool(warning.display_right.warning)
except Exception:
# An optional display feed cannot take down the onroad UI.
self.close()
return False, False