update toggle on cereal message change

pull/31792/head
Shane Smiskol 1 year ago
parent 27d5900f96
commit 6d114095ad
  1. 23
      selfdrive/ui/qt/offroad/settings.cc
  2. 4
      selfdrive/ui/qt/offroad/settings.h
  3. 4
      selfdrive/ui/qt/widgets/controls.h
  4. 1
      selfdrive/ui/ui.h

@ -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 &param_name, const QString &param_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<int>(personality));
}
uiState()->scene.personality = personality;
}
}
void TogglesPanel::expandToggleDescription(const QString &param) {
toggles[param.toStdString()]->showDescription();
}

@ -11,6 +11,7 @@
#include <QWidget>
#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 &param);
private slots:
void updateState(const UIState &s);
private:
Params params;
std::map<std::string, ParamControl*> toggles;

@ -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);

@ -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;

Loading…
Cancel
Save