diff --git a/selfdrive/ui/layouts/settings/device.py b/selfdrive/ui/layouts/settings/device.py index 3bdacf8734..f7b011c1ea 100644 --- a/selfdrive/ui/layouts/settings/device.py +++ b/selfdrive/ui/layouts/settings/device.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 diff --git a/selfdrive/ui/onroad/driver_camera_view.py b/selfdrive/ui/onroad/driver_camera_dialog.py similarity index 84% rename from selfdrive/ui/onroad/driver_camera_view.py rename to selfdrive/ui/onroad/driver_camera_dialog.py index a05f1545f5..40c72f292b 100644 --- a/selfdrive/ui/onroad/driver_camera_view.py +++ b/selfdrive/ui/onroad/driver_camera_dialog.py @@ -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()