offroad ui: support storing confirmation of a toggle (#26510)

* show confirmation toggle on first toggle of experimental mode

* don't store confirmation if users toggle off *after* this PR

* refactor

* cleaner

* not true

* try here
pull/26512/head
Shane Smiskol 2 years ago committed by GitHub
parent 4eda53cef2
commit 2ad9a4f95a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      common/params.cc
  2. 20
      selfdrive/ui/qt/offroad/settings.cc
  3. 10
      selfdrive/ui/qt/widgets/controls.h

@ -103,6 +103,7 @@ std::unordered_map<std::string, uint32_t> keys = {
{"DisableLogging", CLEAR_ON_MANAGER_START | CLEAR_ON_IGNITION_ON}, {"DisableLogging", CLEAR_ON_MANAGER_START | CLEAR_ON_IGNITION_ON},
{"DisablePowerDown", PERSISTENT}, {"DisablePowerDown", PERSISTENT},
{"ExperimentalMode", PERSISTENT}, {"ExperimentalMode", PERSISTENT},
{"ExperimentalModeConfirmed", PERSISTENT},
{"ExperimentalLongitudinalEnabled", PERSISTENT}, // WARNING: THIS MAY DISABLE AEB {"ExperimentalLongitudinalEnabled", PERSISTENT}, // WARNING: THIS MAY DISABLE AEB
{"DisableUpdates", PERSISTENT}, {"DisableUpdates", PERSISTENT},
{"DisengageOnAccelerator", PERSISTENT}, {"DisengageOnAccelerator", PERSISTENT},

@ -28,20 +28,18 @@
TogglesPanel::TogglesPanel(SettingsWindow *parent) : ListWidget(parent) { TogglesPanel::TogglesPanel(SettingsWindow *parent) : ListWidget(parent) {
// param, title, desc, icon, confirm // param, title, desc, icon, confirm
std::vector<std::tuple<QString, QString, QString, QString, bool>> toggle_defs{ std::vector<std::tuple<QString, QString, QString, QString>> toggle_defs{
{ {
"OpenpilotEnabledToggle", "OpenpilotEnabledToggle",
tr("Enable openpilot"), tr("Enable openpilot"),
tr("Use the openpilot system for adaptive cruise control and lane keep driver assistance. Your attention is required at all times to use this feature. Changing this setting takes effect when the car is powered off."), tr("Use the openpilot system for adaptive cruise control and lane keep driver assistance. Your attention is required at all times to use this feature. Changing this setting takes effect when the car is powered off."),
"../assets/offroad/icon_openpilot.png", "../assets/offroad/icon_openpilot.png",
false,
}, },
{ {
"ExperimentalMode", "ExperimentalMode",
tr("Experimental Mode"), tr("Experimental Mode"),
"", "",
"../assets/offroad/icon_road.png", "../assets/offroad/icon_road.png",
false,
}, },
{ {
"ExperimentalLongitudinalEnabled", "ExperimentalLongitudinalEnabled",
@ -50,35 +48,30 @@ TogglesPanel::TogglesPanel(SettingsWindow *parent) : ListWidget(parent) {
.arg(tr("WARNING: openpilot longitudinal control is experimental for this car and will disable Automatic Emergency Braking (AEB).")) .arg(tr("WARNING: openpilot longitudinal control is experimental for this car and will disable Automatic Emergency Braking (AEB)."))
.arg(tr("openpilot defaults to the car's built-in ACC instead of openpilot's longitudinal control on this car. Enable this to switch to openpilot longitudinal control.")), .arg(tr("openpilot defaults to the car's built-in ACC instead of openpilot's longitudinal control on this car. Enable this to switch to openpilot longitudinal control.")),
"../assets/offroad/icon_speed_limit.png", "../assets/offroad/icon_speed_limit.png",
true,
}, },
{ {
"IsLdwEnabled", "IsLdwEnabled",
tr("Enable Lane Departure Warnings"), tr("Enable Lane Departure Warnings"),
tr("Receive alerts to steer back into the lane when your vehicle drifts over a detected lane line without a turn signal activated while driving over 31 mph (50 km/h)."), tr("Receive alerts to steer back into the lane when your vehicle drifts over a detected lane line without a turn signal activated while driving over 31 mph (50 km/h)."),
"../assets/offroad/icon_warning.png", "../assets/offroad/icon_warning.png",
false,
}, },
{ {
"IsMetric", "IsMetric",
tr("Use Metric System"), tr("Use Metric System"),
tr("Display speed in km/h instead of mph."), tr("Display speed in km/h instead of mph."),
"../assets/offroad/icon_metric.png", "../assets/offroad/icon_metric.png",
false,
}, },
{ {
"RecordFront", "RecordFront",
tr("Record and Upload Driver Camera"), tr("Record and Upload Driver Camera"),
tr("Upload data from the driver facing camera and help improve the driver monitoring algorithm."), tr("Upload data from the driver facing camera and help improve the driver monitoring algorithm."),
"../assets/offroad/icon_monitoring.png", "../assets/offroad/icon_monitoring.png",
false,
}, },
{ {
"DisengageOnAccelerator", "DisengageOnAccelerator",
tr("Disengage on Accelerator Pedal"), tr("Disengage on Accelerator Pedal"),
tr("When enabled, pressing the accelerator pedal will disengage openpilot."), tr("When enabled, pressing the accelerator pedal will disengage openpilot."),
"../assets/offroad/icon_disengage_on_accelerator.svg", "../assets/offroad/icon_disengage_on_accelerator.svg",
false,
}, },
#ifdef ENABLE_MAPS #ifdef ENABLE_MAPS
{ {
@ -86,20 +79,18 @@ TogglesPanel::TogglesPanel(SettingsWindow *parent) : ListWidget(parent) {
tr("Show ETA in 24h Format"), tr("Show ETA in 24h Format"),
tr("Use 24h format instead of am/pm"), tr("Use 24h format instead of am/pm"),
"../assets/offroad/icon_metric.png", "../assets/offroad/icon_metric.png",
false,
}, },
{ {
"NavSettingLeftSide", "NavSettingLeftSide",
tr("Show Map on Left Side of UI"), tr("Show Map on Left Side of UI"),
tr("Show map on left side when in split screen view."), tr("Show map on left side when in split screen view."),
"../assets/offroad/icon_road.png", "../assets/offroad/icon_road.png",
false,
}, },
#endif #endif
}; };
for (auto &[param, title, desc, icon, confirm] : toggle_defs) { for (auto &[param, title, desc, icon] : toggle_defs) {
auto toggle = new ParamControl(param, title, desc, icon, confirm, this); auto toggle = new ParamControl(param, title, desc, icon, false, this);
bool locked = params.getBool((param + "Lock").toStdString()); bool locked = params.getBool((param + "Lock").toStdString());
toggle->setEnabled(!locked); toggle->setEnabled(!locked);
@ -108,6 +99,11 @@ TogglesPanel::TogglesPanel(SettingsWindow *parent) : ListWidget(parent) {
toggles[param.toStdString()] = toggle; toggles[param.toStdString()] = toggle;
} }
// Toggles with confirmation dialogs
toggles["ExperimentalMode"]->confirm = true;
toggles["ExperimentalMode"]->store_confirm = true;
toggles["ExperimentalLongitudinalEnabled"]->confirm = true;
connect(toggles["ExperimentalLongitudinalEnabled"], &ToggleControl::toggleFlipped, [=]() { connect(toggles["ExperimentalLongitudinalEnabled"], &ToggleControl::toggleFlipped, [=]() {
updateToggles(); updateToggles();
}); });

@ -139,13 +139,16 @@ class ParamControl : public ToggleControl {
Q_OBJECT Q_OBJECT
public: public:
ParamControl(const QString &param, const QString &title, const QString &desc, const QString &icon, const bool confirm, QWidget *parent = nullptr) : ToggleControl(title, desc, icon, false, parent) { ParamControl(const QString &param, const QString &title, const QString &desc, const QString &icon, const bool _confirm, QWidget *parent = nullptr) : confirm(_confirm), ToggleControl(title, desc, icon, false, parent) {
key = param.toStdString(); key = param.toStdString();
QObject::connect(this, &ParamControl::toggleFlipped, [=](bool state) { QObject::connect(this, &ParamControl::toggleFlipped, [=](bool state) {
QString content("<body><h2 style=\"text-align: center;\">" + title + "</h2><br>" QString content("<body><h2 style=\"text-align: center;\">" + title + "</h2><br>"
"<p style=\"text-align: center; margin: 0 128px; font-size: 50px;\">" + getDescription() + "</p></body>"); "<p style=\"text-align: center; margin: 0 128px; font-size: 50px;\">" + getDescription() + "</p></body>");
ConfirmationDialog dialog(content, tr("Enable"), tr("Cancel"), true, this); ConfirmationDialog dialog(content, tr("Enable"), tr("Cancel"), true, this);
if (!confirm || !state || dialog.exec()) {
bool confirmed = store_confirm && params.getBool(key + "Confirmed");
if (!confirm || confirmed || !state || dialog.exec()) {
if (store_confirm && state) params.putBool(key + "Confirmed", true);
params.putBool(key, state); params.putBool(key, state);
} else { } else {
toggle.togglePosition(); toggle.togglePosition();
@ -153,6 +156,9 @@ public:
}); });
} }
bool confirm = false;
bool store_confirm = false;
void refresh() { void refresh() {
if (params.getBool(key) != toggle.on) { if (params.getBool(key) != toggle.on) {
toggle.togglePosition(); toggle.togglePosition();

Loading…
Cancel
Save