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
old-commit-hash: 2ad9a4f95a
taco
Shane Smiskol 2 years ago committed by GitHub
parent bc00819b3f
commit 74aa9e5b80
  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},
{"DisablePowerDown", PERSISTENT},
{"ExperimentalMode", PERSISTENT},
{"ExperimentalModeConfirmed", PERSISTENT},
{"ExperimentalLongitudinalEnabled", PERSISTENT}, // WARNING: THIS MAY DISABLE AEB
{"DisableUpdates", PERSISTENT},
{"DisengageOnAccelerator", PERSISTENT},

@ -28,20 +28,18 @@
TogglesPanel::TogglesPanel(SettingsWindow *parent) : ListWidget(parent) {
// 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",
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."),
"../assets/offroad/icon_openpilot.png",
false,
},
{
"ExperimentalMode",
tr("Experimental Mode"),
"",
"../assets/offroad/icon_road.png",
false,
},
{
"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("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",
true,
},
{
"IsLdwEnabled",
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)."),
"../assets/offroad/icon_warning.png",
false,
},
{
"IsMetric",
tr("Use Metric System"),
tr("Display speed in km/h instead of mph."),
"../assets/offroad/icon_metric.png",
false,
},
{
"RecordFront",
tr("Record and Upload Driver Camera"),
tr("Upload data from the driver facing camera and help improve the driver monitoring algorithm."),
"../assets/offroad/icon_monitoring.png",
false,
},
{
"DisengageOnAccelerator",
tr("Disengage on Accelerator Pedal"),
tr("When enabled, pressing the accelerator pedal will disengage openpilot."),
"../assets/offroad/icon_disengage_on_accelerator.svg",
false,
},
#ifdef ENABLE_MAPS
{
@ -86,20 +79,18 @@ TogglesPanel::TogglesPanel(SettingsWindow *parent) : ListWidget(parent) {
tr("Show ETA in 24h Format"),
tr("Use 24h format instead of am/pm"),
"../assets/offroad/icon_metric.png",
false,
},
{
"NavSettingLeftSide",
tr("Show Map on Left Side of UI"),
tr("Show map on left side when in split screen view."),
"../assets/offroad/icon_road.png",
false,
},
#endif
};
for (auto &[param, title, desc, icon, confirm] : toggle_defs) {
auto toggle = new ParamControl(param, title, desc, icon, confirm, this);
for (auto &[param, title, desc, icon] : toggle_defs) {
auto toggle = new ParamControl(param, title, desc, icon, false, this);
bool locked = params.getBool((param + "Lock").toStdString());
toggle->setEnabled(!locked);
@ -108,6 +99,11 @@ TogglesPanel::TogglesPanel(SettingsWindow *parent) : ListWidget(parent) {
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, [=]() {
updateToggles();
});

@ -139,13 +139,16 @@ class ParamControl : public ToggleControl {
Q_OBJECT
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();
QObject::connect(this, &ParamControl::toggleFlipped, [=](bool state) {
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>");
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);
} else {
toggle.togglePosition();
@ -153,6 +156,9 @@ public:
});
}
bool confirm = false;
bool store_confirm = false;
void refresh() {
if (params.getBool(key) != toggle.on) {
toggle.togglePosition();

Loading…
Cancel
Save