diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index ea491ca259..465fe341bb 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -96,15 +96,8 @@ TogglesPanel::TogglesPanel(SettingsWindow *parent) : ListWidget(parent) { "../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(); - } - }); + // set up uiState update for personality setting + QObject::connect(uiState(), &UIState::uiUpdate, this, &TogglesPanel::updateState); for (auto &[param, title, desc, icon] : toggle_defs) { auto toggle = new ParamControl(param, title, desc, icon, this); @@ -131,6 +124,18 @@ TogglesPanel::TogglesPanel(SettingsWindow *parent) : ListWidget(parent) { }); } +void TogglesPanel::updateState(const UIState &s) { + const SubMaster &sm = *(s.sm); + + if (sm.updated("longitudinalPlan")) { + auto personality = sm["longitudinalPlan"].getLongitudinalPlan().getPersonalityDEPRECATED(); + if (personality != s.scene.personality && s.scene.started && isVisible()) { + long_personality_setting->setCheckedButton(static_cast(personality)); + } + uiState()->scene.personality = personality; + } +} + void TogglesPanel::expandToggleDescription(const QString ¶m) { toggles[param.toStdString()]->showDescription(); } diff --git a/selfdrive/ui/qt/offroad/settings.h b/selfdrive/ui/qt/offroad/settings.h index a5dd25b14f..581fc098f4 100644 --- a/selfdrive/ui/qt/offroad/settings.h +++ b/selfdrive/ui/qt/offroad/settings.h @@ -11,6 +11,7 @@ #include +#include "selfdrive/ui/ui.h" #include "selfdrive/ui/qt/util.h" #include "selfdrive/ui/qt/widgets/controls.h" @@ -64,6 +65,9 @@ public: public slots: void expandToggleDescription(const QString ¶m); +private slots: + void updateState(const UIState &s); + private: Params params; std::map toggles; diff --git a/selfdrive/ui/qt/widgets/controls.h b/selfdrive/ui/qt/widgets/controls.h index 4b4259f451..aa304e0df6 100644 --- a/selfdrive/ui/qt/widgets/controls.h +++ b/selfdrive/ui/qt/widgets/controls.h @@ -234,6 +234,10 @@ 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); diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 86cd70f028..6efb72af9a 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -155,6 +155,7 @@ typedef struct UIScene { vec3 face_kpts_draw[std::size(default_face_kpts_3d)]; bool navigate_on_openpilot = false; + cereal::LongitudinalPersonality personality; float light_sensor; bool started, ignition, is_metric, map_on_left, longitudinal_control;