From dd9c6b7ad3b96274672ca9ed4c61c4a19e843e34 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Sat, 9 Mar 2024 01:26:04 -0800 Subject: [PATCH] works but at what cost --- selfdrive/ui/qt/offroad/settings.cc | 17 +++++++++++++++++ selfdrive/ui/qt/offroad/settings.h | 10 ++++++++++ selfdrive/ui/qt/widgets/controls.h | 4 ++++ selfdrive/ui/qt/window.cc | 9 +++++++++ selfdrive/ui/qt/window.h | 6 ++++++ selfdrive/ui/ui.cc | 8 +++++++- selfdrive/ui/ui.h | 1 + 7 files changed, 54 insertions(+), 1 deletion(-) diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index a9a3f3eaae..9678f17b16 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -128,6 +128,11 @@ void TogglesPanel::showEvent(QShowEvent *event) { updateToggles(); } +void TogglesPanel::updatePersonalitySetting(int personality) { + qDebug() << "updatePersonalitySetting" << personality; + long_personality_setting->setActiveButton(personality); +} + void TogglesPanel::updateToggles() { auto experimental_mode_toggle = toggles["ExperimentalMode"]; auto op_long_toggle = toggles["ExperimentalLongitudinalEnabled"]; @@ -341,6 +346,10 @@ void SettingsWindow::setCurrentPanel(int index, const QString ¶m) { } } +//void SettingsWindow::updatePersonalitySetting(int personality) { +// emit updatePersonalitySetting1(personality); +//} + SettingsWindow::SettingsWindow(QWidget *parent) : QFrame(parent) { // setup two main layouts @@ -374,6 +383,14 @@ SettingsWindow::SettingsWindow(QWidget *parent) : QFrame(parent) { TogglesPanel *toggles = new TogglesPanel(this); QObject::connect(this, &SettingsWindow::expandToggleDescription, toggles, &TogglesPanel::expandToggleDescription); +// QObject::connect(this, &SettingsWindow::updatePersonalitySetting, toggles, [toggles](int personality) { +//// qDebug() << "HERE"; +//// emit updatePersonalitySetting(personality); +// toggles->updatePersonalitySetting(personality); +// }); + QObject::connect(this, &SettingsWindow::updatePersonalitySetting, toggles, &TogglesPanel::updatePersonalitySetting); + +// QObject::connect(uiState(), &UIState::uiUpdate, this, &TogglesPanel::updateState); QList> panels = { {tr("Device"), device}, diff --git a/selfdrive/ui/qt/offroad/settings.h b/selfdrive/ui/qt/offroad/settings.h index a5dd25b14f..dc9db1e30c 100644 --- a/selfdrive/ui/qt/offroad/settings.h +++ b/selfdrive/ui/qt/offroad/settings.h @@ -22,6 +22,9 @@ public: explicit SettingsWindow(QWidget *parent = 0); void setCurrentPanel(int index, const QString ¶m = ""); +//public slots: +// void updatePersonalitySetting(int); + protected: void showEvent(QShowEvent *event) override; @@ -30,6 +33,8 @@ signals: void reviewTrainingGuide(); void showDriverView(); void expandToggleDescription(const QString ¶m); + void updatePersonalitySetting(int personality); +// void updatePersonalitySetting1(int personality); private: QPushButton *sidebar_alert_widget; @@ -63,6 +68,11 @@ public: public slots: void expandToggleDescription(const QString ¶m); + void updatePersonalitySetting(int); +// void updateState(const UIState &s); + +//private slots: +// void updateState(const UIState &s); private: Params params; diff --git a/selfdrive/ui/qt/widgets/controls.h b/selfdrive/ui/qt/widgets/controls.h index e4630c6590..2f980c894e 100644 --- a/selfdrive/ui/qt/widgets/controls.h +++ b/selfdrive/ui/qt/widgets/controls.h @@ -230,6 +230,10 @@ public: }); } + void setActiveButton(int id) { + button_group->button(id)->setChecked(true); + } + void setEnabled(bool enable) { for (auto btn : button_group->buttons()) { btn->setEnabled(enable); diff --git a/selfdrive/ui/qt/window.cc b/selfdrive/ui/qt/window.cc index 74fd05ed7b..08f331069a 100644 --- a/selfdrive/ui/qt/window.cc +++ b/selfdrive/ui/qt/window.cc @@ -4,10 +4,18 @@ #include "system/hardware/hw.h" +void MainWindow::updateState(const UIState &s) { + qDebug() << "updateState" << static_cast(s.scene.personality); + emit updatePersonalitySetting(static_cast(s.scene.personality)); +// settingsWindow->updatePersonalitySetting(static_cast(s.scene.personality)); +} + MainWindow::MainWindow(QWidget *parent) : QWidget(parent) { main_layout = new QStackedLayout(this); main_layout->setMargin(0); + QObject::connect(uiState(), &UIState::uiUpdate, this, &MainWindow::updateState); + homeWindow = new HomeWindow(this); main_layout->addWidget(homeWindow); QObject::connect(homeWindow, &HomeWindow::openSettings, this, &MainWindow::openSettings); @@ -15,6 +23,7 @@ MainWindow::MainWindow(QWidget *parent) : QWidget(parent) { settingsWindow = new SettingsWindow(this); main_layout->addWidget(settingsWindow); + QObject::connect(this, &MainWindow::updatePersonalitySetting, settingsWindow, &SettingsWindow::updatePersonalitySetting); QObject::connect(settingsWindow, &SettingsWindow::closeSettings, this, &MainWindow::closeSettings); QObject::connect(settingsWindow, &SettingsWindow::reviewTrainingGuide, [=]() { onboardingWindow->showTrainingGuide(); diff --git a/selfdrive/ui/qt/window.h b/selfdrive/ui/qt/window.h index 05b61e1f76..212794971f 100644 --- a/selfdrive/ui/qt/window.h +++ b/selfdrive/ui/qt/window.h @@ -13,6 +13,12 @@ class MainWindow : public QWidget { public: explicit MainWindow(QWidget *parent = 0); +private slots: + void updateState(const UIState &s); + +signals: + void updatePersonalitySetting(int); + private: bool eventFilter(QObject *obj, QEvent *event) override; void openSettings(int index = 0, const QString ¶m = ""); diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index 9afd22f13a..1d39d37ef5 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -3,6 +3,7 @@ #include #include #include +#include #include @@ -206,6 +207,11 @@ static void update_state(UIState *s) { float scale = (cam_state.getSensor() == cereal::FrameData::ImageSensor::AR0231) ? 6.0f : 1.0f; scene.light_sensor = std::max(100.0f - scale * cam_state.getExposureValPercent(), 0.0f); } + if (sm.updated("longitudinalPlan")) { + auto plan = sm["longitudinalPlan"].getLongitudinalPlan(); + scene.personality = plan.getPersonality(); + std::cout << "Personality: " << static_cast(scene.personality) << std::endl; + } scene.started = sm["deviceState"].getDeviceState().getStarted() && scene.ignition; scene.world_objects_visible = scene.world_objects_visible || @@ -248,7 +254,7 @@ UIState::UIState(QObject *parent) : QObject(parent) { sm = std::make_unique>({ "modelV2", "controlsState", "liveCalibration", "radarState", "deviceState", "pandaStates", "carParams", "driverMonitoringState", "carState", "liveLocationKalman", "driverStateV2", - "wideRoadCameraState", "managerState", "navInstruction", "navRoute", "uiPlan", + "wideRoadCameraState", "managerState", "navInstruction", "navRoute", "uiPlan", "longitudinalPlan", }); Params params; diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 86cd70f028..333888cbf7 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -158,6 +158,7 @@ typedef struct UIScene { float light_sensor; bool started, ignition, is_metric, map_on_left, longitudinal_control; + cereal::LongitudinalPersonality personality; bool world_objects_visible = false; uint64_t started_frame; } UIScene;