From 34a5e626d6f55cd33bc292e4f9d4a21e1fd2972b Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Tue, 11 Jul 2023 14:49:19 -0700 Subject: [PATCH] ui: show map with nav (#28867) * accept touch events in map settings * draft * draft 2.0 * revert this stuff * need this * fix * clean up debug prints * fraft * only show map on closeSettings if nav * works! * can't do it here * I was going to connect signals from UIState to HomeWindow, then to OnroadWidget, but that seems like too much * just need to keep track of it in onroad, seems like the cleanest option * ideally we show the map where we set the scene variable, and that's in map.cc * old variable * comments * less confusing * app comment * add back * fix * move to top * remove this comment --- selfdrive/ui/qt/home.cc | 4 ++++ selfdrive/ui/qt/home.h | 1 + selfdrive/ui/qt/maps/map.cc | 9 +++++++++ selfdrive/ui/qt/onroad.cc | 4 +++- selfdrive/ui/qt/onroad.h | 1 + selfdrive/ui/qt/window.cc | 4 ++++ selfdrive/ui/ui.h | 2 ++ 7 files changed, 24 insertions(+), 1 deletion(-) diff --git a/selfdrive/ui/qt/home.cc b/selfdrive/ui/qt/home.cc index b4181f82b7..b674d39fbd 100644 --- a/selfdrive/ui/qt/home.cc +++ b/selfdrive/ui/qt/home.cc @@ -55,6 +55,10 @@ void HomeWindow::showSidebar(bool show) { sidebar->setVisible(show); } +void HomeWindow::showMapPanel(bool show) { + onroad->showMapPanel(show); +} + void HomeWindow::updateState(const UIState &s) { const SubMaster &sm = *(s.sm); diff --git a/selfdrive/ui/qt/home.h b/selfdrive/ui/qt/home.h index ed1c215467..c6032852a1 100644 --- a/selfdrive/ui/qt/home.h +++ b/selfdrive/ui/qt/home.h @@ -55,6 +55,7 @@ public slots: void offroadTransition(bool offroad); void showDriverView(bool show); void showSidebar(bool show); + void showMapPanel(bool show); protected: void mousePressEvent(QMouseEvent* e) override; diff --git a/selfdrive/ui/qt/maps/map.cc b/selfdrive/ui/qt/maps/map.cc index 09eb4045b2..3ae708624d 100644 --- a/selfdrive/ui/qt/maps/map.cc +++ b/selfdrive/ui/qt/maps/map.cc @@ -130,6 +130,15 @@ void MapWindow::updateState(const UIState &s) { const SubMaster &sm = *(s.sm); update(); + // update navigate on openpilot status + if (sm.updated("modelV2")) { + bool nav_enabled = sm["modelV2"].getModelV2().getNavEnabled(); + if (nav_enabled && !uiState()->scene.navigate_on_openpilot) { + emit requestVisible(true); // Show map on rising edge of navigate on openpilot + } + uiState()->scene.navigate_on_openpilot = nav_enabled; + } + if (sm.updated("liveLocationKalman")) { auto locationd_location = sm["liveLocationKalman"].getLiveLocationKalman(); auto locationd_pos = locationd_location.getPositionGeodetic(); diff --git a/selfdrive/ui/qt/onroad.cc b/selfdrive/ui/qt/onroad.cc index 4f144f667f..ef711afd50 100644 --- a/selfdrive/ui/qt/onroad.cc +++ b/selfdrive/ui/qt/onroad.cc @@ -74,8 +74,10 @@ void OnroadWindow::updateState(const UIState &s) { void OnroadWindow::mousePressEvent(QMouseEvent* e) { #ifdef ENABLE_MAPS if (map != nullptr) { + // Switch between map and sidebar when using navigate on openpilot bool sidebarVisible = geometry().x() > 0; - map->setVisible(!sidebarVisible && !map->isVisible()); + bool show_map = uiState()->scene.navigate_on_openpilot ? sidebarVisible : !sidebarVisible; + map->setVisible(show_map && !map->isVisible()); } #endif // propagation event to parent(HomeWindow) diff --git a/selfdrive/ui/qt/onroad.h b/selfdrive/ui/qt/onroad.h index 6f30d0f37e..955ddf254d 100644 --- a/selfdrive/ui/qt/onroad.h +++ b/selfdrive/ui/qt/onroad.h @@ -117,6 +117,7 @@ class OnroadWindow : public QWidget { public: OnroadWindow(QWidget* parent = 0); bool isMapVisible() const { return map && map->isVisible(); } + void showMapPanel(bool show) { if (map) map->setVisible(show); } signals: void mapPanelRequested(); diff --git a/selfdrive/ui/qt/window.cc b/selfdrive/ui/qt/window.cc index faa62a71e8..705c2f2172 100644 --- a/selfdrive/ui/qt/window.cc +++ b/selfdrive/ui/qt/window.cc @@ -75,6 +75,10 @@ void MainWindow::closeSettings() { if (uiState()->scene.started) { homeWindow->showSidebar(false); + // Map is always shown when using navigate on openpilot + if (uiState()->scene.navigate_on_openpilot) { + homeWindow->showMapPanel(true); + } } } diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index cf5094371c..2519f8ea2c 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -131,6 +131,8 @@ typedef struct UIScene { float driver_pose_coss[3]; vec3 face_kpts_draw[std::size(default_face_kpts_3d)]; + bool navigate_on_openpilot = false; + float light_sensor; bool started, ignition, is_metric, map_on_left, longitudinal_control; uint64_t started_frame;