ui: implement driver camera preview in settings (#35480)

* implement driver camera preview in settings

rebase master

* rename to dialog
pull/35494/head
Dean Lee 2 weeks ago committed by GitHub
parent e93a7234bc
commit 0c6856cf03
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 10
      selfdrive/ui/layouts/settings/device.py
  2. 23
      selfdrive/ui/onroad/driver_camera_dialog.py

@ -2,6 +2,7 @@ import os
import json
from openpilot.system.ui.lib.application import gui_app, Widget
from openpilot.system.ui.lib.list_view import ListView, text_item, button_item
from openpilot.selfdrive.ui.onroad.driver_camera_dialog import DriverCameraDialog
from openpilot.common.params import Params
from openpilot.system.ui.widgets.option_dialog import MultiOptionDialog
from openpilot.system.hardware import TICI
@ -32,7 +33,7 @@ class DeviceLayout(Widget):
text_item("Dongle ID", dongle_id),
text_item("Serial", serial),
button_item("Pair Device", "PAIR", DESCRIPTIONS['pair_device'], self._on_pair_device),
button_item("Driver Camera", "PREVIEW", DESCRIPTIONS['driver_camera'], self._on_driver_camera),
button_item("Driver Camera", "PREVIEW", DESCRIPTIONS['driver_camera'], callback=self._on_driver_camera),
button_item("Reset Calibration", "RESET", DESCRIPTIONS['reset_calibration'], self._on_reset_calibration),
button_item("Review Training Guide", "REVIEW", DESCRIPTIONS['review_guide'], self._on_review_training_guide),
]
@ -44,6 +45,7 @@ class DeviceLayout(Widget):
self._list_widget = ListView(items)
self._select_language_dialog: MultiOptionDialog | None = None
self._driver_camera: DriverCameraDialog | None = None
def _render(self, rect):
self._list_widget.render(rect)
@ -66,9 +68,13 @@ class DeviceLayout(Widget):
self._select_language_dialog = None
def _on_driver_camera(self):
if not self._driver_camera:
self._driver_camera = DriverCameraDialog()
gui_app.set_modal_overlay(self._driver_camera, callback=lambda result: setattr(self, '_driver_camera', None))
def _on_pair_device(self): pass
def _on_driver_camera(self): pass
def _on_reset_calibration(self): pass
def _on_review_training_guide(self): pass
def _on_regulatory(self): pass

@ -8,14 +8,17 @@ from openpilot.system.ui.lib.application import gui_app, FontWeight
from openpilot.system.ui.lib.label import gui_label
class DriverCameraView(CameraView):
def __init__(self, stream_type: VisionStreamType):
super().__init__("camerad", stream_type)
class DriverCameraDialog(CameraView):
def __init__(self):
super().__init__("camerad", VisionStreamType.VISION_STREAM_DRIVER)
self.driver_state_renderer = DriverStateRenderer()
def _render(self, rect):
super()._render(rect)
if rl.is_mouse_button_pressed(rl.MouseButton.MOUSE_BUTTON_LEFT):
return 1
if not self.frame:
gui_label(
rect,
@ -24,13 +27,15 @@ class DriverCameraView(CameraView):
font_weight=FontWeight.BOLD,
alignment=rl.GuiTextAlignment.TEXT_ALIGN_CENTER,
)
return
return -1
self._draw_face_detection(rect)
self.driver_state_renderer.render(rect)
self._draw_face_detection(rect, ui_state.sm)
self.driver_state_renderer.draw(rect, ui_state.sm)
return -1
def _draw_face_detection(self, rect: rl.Rectangle, sm) -> None:
driver_state = sm["driverStateV2"]
def _draw_face_detection(self, rect: rl.Rectangle) -> None:
driver_state = ui_state.sm["driverStateV2"]
is_rhd = driver_state.wheelOnRightProb > 0.5
driver_data = driver_state.rightDriverData if is_rhd else driver_state.leftDriverData
face_detect = driver_data.faceProb > 0.7
@ -84,7 +89,7 @@ class DriverCameraView(CameraView):
if __name__ == "__main__":
gui_app.init_window("Driver Camera View")
driver_camera_view = DriverCameraView(VisionStreamType.VISION_STREAM_DRIVER)
driver_camera_view = DriverCameraDialog()
try:
for _ in gui_app.render():
ui_state.update()
Loading…
Cancel
Save