From 464cb4620d7aa76e5f958d4d6b9144d0eaa277c9 Mon Sep 17 00:00:00 2001 From: FrogAi <91348155+FrogAi@users.noreply.github.com> Date: Fri, 5 Apr 2024 03:23:26 -0700 Subject: [PATCH] Driver camera view when in reverse Added toggle to show the driver camera when in the reverse gear. --- common/params.cc | 1 + .../frogpilot/ui/qt/offroad/visual_settings.cc | 1 + .../frogpilot/ui/qt/offroad/visual_settings.h | 2 +- selfdrive/ui/qt/home.cc | 15 ++++++++++++--- selfdrive/ui/qt/home.h | 2 +- selfdrive/ui/ui.cc | 3 +++ selfdrive/ui/ui.h | 3 +++ 7 files changed, 22 insertions(+), 5 deletions(-) diff --git a/common/params.cc b/common/params.cc index 2b9dbbe32..16220e47a 100644 --- a/common/params.cc +++ b/common/params.cc @@ -256,6 +256,7 @@ std::unordered_map keys = { {"DisableOpenpilotLongitudinal", PERSISTENT}, {"DisengageVolume", PERSISTENT}, {"DragonPilotTune", PERSISTENT}, + {"DriverCamera", PERSISTENT}, {"DynamicPathWidth", PERSISTENT}, {"EngageVolume", PERSISTENT}, {"FrogPilotTogglesUpdated", PERSISTENT}, diff --git a/selfdrive/frogpilot/ui/qt/offroad/visual_settings.cc b/selfdrive/frogpilot/ui/qt/offroad/visual_settings.cc index 49e79a3da..cd958e3a0 100644 --- a/selfdrive/frogpilot/ui/qt/offroad/visual_settings.cc +++ b/selfdrive/frogpilot/ui/qt/offroad/visual_settings.cc @@ -38,6 +38,7 @@ FrogPilotVisualsPanel::FrogPilotVisualsPanel(SettingsWindow *parent) : FrogPilot {"QOLVisuals", tr("Quality of Life"), tr("Miscellaneous quality of life changes to improve your overall openpilot experience."), "../frogpilot/assets/toggle_icons/quality_of_life.png"}, {"CameraView", tr("Camera View"), tr("Choose your preferred camera view for the onroad UI. This is purely a visual change and doesn't impact how openpilot drives."), ""}, + {"DriverCamera", tr("Driver Camera On Reverse"), tr("Show the driver camera feed when in reverse."), ""}, }; for (const auto &[param, title, desc, icon] : visualToggles) { diff --git a/selfdrive/frogpilot/ui/qt/offroad/visual_settings.h b/selfdrive/frogpilot/ui/qt/offroad/visual_settings.h index 5df42050b..baa6ec138 100644 --- a/selfdrive/frogpilot/ui/qt/offroad/visual_settings.h +++ b/selfdrive/frogpilot/ui/qt/offroad/visual_settings.h @@ -28,7 +28,7 @@ private: std::set customOnroadUIKeys = {"CustomPaths", "DeveloperUI", "LeadInfo"}; std::set customThemeKeys = {"CustomColors", "CustomIcons", "CustomSignals", "CustomSounds"}; std::set modelUIKeys = {"DynamicPathWidth", "HideLeadMarker", "LaneLinesWidth", "PathEdgeWidth", "PathWidth", "RoadEdgesWidth", "UnlimitedLength"}; - std::set qolKeys = {"CameraView"}; + std::set qolKeys = {"CameraView", "DriverCamera"}; std::set screenKeys = {}; std::map toggles; diff --git a/selfdrive/ui/qt/home.cc b/selfdrive/ui/qt/home.cc index e95fb5e68..e54012fc9 100644 --- a/selfdrive/ui/qt/home.cc +++ b/selfdrive/ui/qt/home.cc @@ -66,6 +66,10 @@ void HomeWindow::updateState(const UIState &s) { body->setEnabled(true); slayout->setCurrentWidget(body); } + + if (s.scene.started) { + showDriverView(s.scene.driver_camera_timer >= 10, true); + } } void HomeWindow::offroadTransition(bool offroad) { @@ -79,14 +83,19 @@ void HomeWindow::offroadTransition(bool offroad) { } } -void HomeWindow::showDriverView(bool show) { +void HomeWindow::showDriverView(bool show, bool started) { if (show) { emit closeSettings(); slayout->setCurrentWidget(driver_view); + sidebar->setVisible(show == false); } else { - slayout->setCurrentWidget(home); + if (started) { + slayout->setCurrentWidget(onroad); + } else { + slayout->setCurrentWidget(home); + sidebar->setVisible(show == false); + } } - sidebar->setVisible(show == false); } void HomeWindow::mousePressEvent(QMouseEvent* e) { diff --git a/selfdrive/ui/qt/home.h b/selfdrive/ui/qt/home.h index 13d97b004..5ea4a16fe 100644 --- a/selfdrive/ui/qt/home.h +++ b/selfdrive/ui/qt/home.h @@ -56,7 +56,7 @@ signals: public slots: void offroadTransition(bool offroad); - void showDriverView(bool show); + void showDriverView(bool show, bool started=false); void showSidebar(bool show); void showMapPanel(bool show); diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index f2148f28e..8920b403b 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -226,6 +226,7 @@ static void update_state(UIState *s) { scene.acceleration = carState.getAEgo(); scene.blind_spot_left = carState.getLeftBlindspot(); scene.blind_spot_right = carState.getRightBlindspot(); + scene.reverse = carState.getGearShifter() == cereal::CarState::GearShifter::REVERSE; scene.turn_signal_left = carState.getLeftBlinker(); scene.turn_signal_right = carState.getRightBlinker(); } @@ -329,6 +330,7 @@ void ui_update_frogpilot_params(UIState *s) { bool quality_of_life_visuals = params.getBool("QOLVisuals"); scene.camera_view = quality_of_life_visuals ? params.getInt("CameraView") : 0; + scene.driver_camera = quality_of_life_visuals && params.getBool("DriverCamera"); } void UIState::updateStatus() { @@ -398,6 +400,7 @@ void UIState::update() { // FrogPilot live variables that need to be constantly checked scene.conditional_status = scene.conditional_experimental ? paramsMemory.getInt("CEStatus") : 0; + scene.driver_camera_timer = (scene.driver_camera && scene.reverse) ? scene.driver_camera_timer + 1 : 0; } void UIState::setPrimeType(PrimeType type) { diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 7449a7863..cabd5af8d 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -179,6 +179,7 @@ typedef struct UIScene { bool blind_spot_path; bool blind_spot_right; bool conditional_experimental; + bool driver_camera; bool dynamic_path_width; bool enabled; bool experimental_mode; @@ -188,6 +189,7 @@ typedef struct UIScene { bool live_valid; bool map_open; bool model_ui; + bool reverse; bool right_hand_drive; bool show_aol_status_bar; bool show_cem_status_bar; @@ -221,6 +223,7 @@ typedef struct UIScene { int custom_icons; int custom_signals; int desired_follow; + int driver_camera_timer; int obstacle_distance; int obstacle_distance_stock; int stopped_equivalence;