diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index d033654b8e..3413fdce3f 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -131,6 +131,12 @@ TogglesPanel::TogglesPanel(SettingsWindow *parent) : ListWidget(parent) { }); connect(new SPControlsPanel(), &SPControlsPanel::updateStockToggles, this, &TogglesPanel::updateToggles); + + param_watcher = new ParamWatcher(this); + + QObject::connect(param_watcher, &ParamWatcher::paramChanged, [=](const QString ¶m_name, const QString ¶m_value) { + updateButtons(); + }); } void TogglesPanel::expandToggleDescription(const QString ¶m) { @@ -139,6 +145,7 @@ void TogglesPanel::expandToggleDescription(const QString ¶m) { void TogglesPanel::showEvent(QShowEvent *event) { updateToggles(); + updateButtons(); } void TogglesPanel::updateToggles() { @@ -220,6 +227,14 @@ void TogglesPanel::updateToggles() { } } +void TogglesPanel::updateButtons() { + param_watcher->addParam("LongitudinalPersonality"); + + if (!isVisible()) return; + + long_personality_setting->setButton("LongitudinalPersonality"); +} + DevicePanel::DevicePanel(SettingsWindow *parent) : ListWidget(parent) { setSpacing(50); addItem(new LabelControl(tr("Dongle ID"), getDongleId().value_or(tr("N/A")))); diff --git a/selfdrive/ui/qt/offroad/settings.h b/selfdrive/ui/qt/offroad/settings.h index 473a77456e..bce7f19295 100644 --- a/selfdrive/ui/qt/offroad/settings.h +++ b/selfdrive/ui/qt/offroad/settings.h @@ -77,6 +77,9 @@ private: Params params; std::map toggles; ButtonParamControl *long_personality_setting; + + ParamWatcher *param_watcher; + void updateButtons(); }; class SoftwarePanel : public ListWidget { diff --git a/selfdrive/ui/qt/offroad/sunnypilot_settings.cc b/selfdrive/ui/qt/offroad/sunnypilot_settings.cc index eebba2231c..a78b119cf3 100644 --- a/selfdrive/ui/qt/offroad/sunnypilot_settings.cc +++ b/selfdrive/ui/qt/offroad/sunnypilot_settings.cc @@ -1125,13 +1125,28 @@ DynamicLaneProfile::DynamicLaneProfile(QWidget *parent) : QWidget(parent), outer addItem(dynamicLaneProfile); addItem(dlp_settings); + + param_watcher = new ParamWatcher(this); + + QObject::connect(param_watcher, &ParamWatcher::paramChanged, [=](const QString ¶m_name, const QString ¶m_value) { + updateButtons(); + }); } void DynamicLaneProfile::showEvent(QShowEvent *event) { updateToggles(); + updateButtons(); } void DynamicLaneProfile::updateToggles() { // toggle names to update when DynamicLaneProfile is flipped dlp_settings->setVisible(params.getBool("DynamicLaneProfileToggle")); } + +void DynamicLaneProfile::updateButtons() { + param_watcher->addParam("DynamicLaneProfile"); + + if (!isVisible()) return; + + dlp_settings->setButton("DynamicLaneProfile"); +} diff --git a/selfdrive/ui/qt/offroad/sunnypilot_settings.h b/selfdrive/ui/qt/offroad/sunnypilot_settings.h index 29f08ed5d7..a71c3f7369 100644 --- a/selfdrive/ui/qt/offroad/sunnypilot_settings.h +++ b/selfdrive/ui/qt/offroad/sunnypilot_settings.h @@ -6,6 +6,7 @@ #include #include +#include "selfdrive/ui/qt/util.h" #include "selfdrive/ui/qt/widgets/controls.h" class SPOptionControl : public AbstractControl { @@ -308,6 +309,9 @@ private: ParamControl *dynamicLaneProfile; ButtonParamControl *dlp_settings; + + ParamWatcher *param_watcher; + void updateButtons(); }; class SPGeneralPanel : public ListWidget { diff --git a/selfdrive/ui/qt/widgets/controls.h b/selfdrive/ui/qt/widgets/controls.h index 811595726d..fe4742722c 100644 --- a/selfdrive/ui/qt/widgets/controls.h +++ b/selfdrive/ui/qt/widgets/controls.h @@ -252,6 +252,14 @@ public: } } + void setButton(QString param) { + key = param.toStdString(); + int value = atoi(params.get(key).c_str()); + for (int i = 0; i < button_group->buttons().size(); i++) { + button_group->buttons()[i]->setChecked(i == value); + } + } + private: std::string key; Params params;