diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index 6726641342..ea491ca259 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -95,6 +95,17 @@ TogglesPanel::TogglesPanel(SettingsWindow *parent) : ListWidget(parent) { "your steering wheel distance button."), "../assets/offroad/icon_speed_limit.png", longi_button_texts); + + // Watch param to update the personality setting in the UI + ParamWatcher *lp_watch = new ParamWatcher(this); + lp_watch->addParam("LongitudinalPersonality"); + QObject::connect(lp_watch, &ParamWatcher::paramChanged, [=](const QString ¶m_name, const QString ¶m_value) { + lp_watch->addParam("LongitudinalPersonality"); + if (isVisible()) { + long_personality_setting->refresh(); + } + }); + for (auto &[param, title, desc, icon] : toggle_defs) { auto toggle = new ParamControl(param, title, desc, icon, this); @@ -128,11 +139,6 @@ void TogglesPanel::showEvent(QShowEvent *event) { updateToggles(); } -void TogglesPanel::updatePersonalitySetting(int personality) { - // Update the personality setting in the UI - long_personality_setting->setCheckedButton(personality); -} - void TogglesPanel::updateToggles() { auto experimental_mode_toggle = toggles["ExperimentalMode"]; auto op_long_toggle = toggles["ExperimentalLongitudinalEnabled"]; @@ -346,23 +352,8 @@ void SettingsWindow::setCurrentPanel(int index, const QString ¶m) { } } -void SettingsWindow::updateState(const UIState &s) { - const SubMaster &sm = *(s.sm); - - if (sm.updated("longitudinalPlan")) { - auto personality = sm["longitudinalPlan"].getLongitudinalPlan().getPersonality(); - if (personality != s.scene.personality && s.scene.started) { - emit updatePersonalitySetting(static_cast(personality)); - } - uiState()->scene.personality = personality; - } -} - SettingsWindow::SettingsWindow(QWidget *parent) : QFrame(parent) { - // setup uiState updates - QObject::connect(uiState(), &UIState::uiUpdate, this, &SettingsWindow::updateState); - // setup two main layouts sidebar_widget = new QWidget; QVBoxLayout *sidebar_layout = new QVBoxLayout(sidebar_widget); @@ -394,7 +385,6 @@ 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, &TogglesPanel::updatePersonalitySetting); QList> panels = { {tr("Device"), device}, diff --git a/selfdrive/ui/qt/offroad/settings.h b/selfdrive/ui/qt/offroad/settings.h index 14a6176654..a5dd25b14f 100644 --- a/selfdrive/ui/qt/offroad/settings.h +++ b/selfdrive/ui/qt/offroad/settings.h @@ -11,7 +11,6 @@ #include -#include "selfdrive/ui/ui.h" #include "selfdrive/ui/qt/util.h" #include "selfdrive/ui/qt/widgets/controls.h" @@ -23,9 +22,6 @@ public: explicit SettingsWindow(QWidget *parent = 0); void setCurrentPanel(int index, const QString ¶m = ""); -private slots: - void updateState(const UIState &s); - protected: void showEvent(QShowEvent *event) override; @@ -34,7 +30,6 @@ signals: void reviewTrainingGuide(); void showDriverView(); void expandToggleDescription(const QString ¶m); - void updatePersonalitySetting(int personality); private: QPushButton *sidebar_alert_widget; @@ -68,7 +63,6 @@ public: public slots: void expandToggleDescription(const QString ¶m); - void updatePersonalitySetting(int personality); private: Params params; diff --git a/selfdrive/ui/qt/widgets/controls.h b/selfdrive/ui/qt/widgets/controls.h index 2643f6d020..bac3e4d006 100644 --- a/selfdrive/ui/qt/widgets/controls.h +++ b/selfdrive/ui/qt/widgets/controls.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "common/params.h" @@ -234,8 +235,13 @@ public: } } - void setCheckedButton(int id) { - button_group->button(id)->setChecked(true); + void refresh() { + int value = atoi(params.get(key).c_str()); + button_group->button(value)->setChecked(true); + } + + void showEvent(QShowEvent *event) override { + refresh(); } private: diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index 438e7d995e..9afd22f13a 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -248,7 +248,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", "longitudinalPlan", + "wideRoadCameraState", "managerState", "navInstruction", "navRoute", "uiPlan", }); Params params; diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 333888cbf7..86cd70f028 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -158,7 +158,6 @@ 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;