diff --git a/common/params_keys.h b/common/params_keys.h index 13c8a9c7b..ef21c0663 100644 --- a/common/params_keys.h +++ b/common/params_keys.h @@ -128,4 +128,5 @@ inline static std::unordered_map keys = { {"dp_device_model_list", PERSISTENT}, {"dp_lat_lca_speed", PERSISTENT}, {"dp_lat_lca_auto_sec", PERSISTENT}, + {"dp_device_go_off_road", CLEAR_ON_MANAGER_START}, }; diff --git a/selfdrive/ui/qt/offroad/settings.h b/selfdrive/ui/qt/offroad/settings.h index b8277e0ae..baeca21ce 100644 --- a/selfdrive/ui/qt/offroad/settings.h +++ b/selfdrive/ui/qt/offroad/settings.h @@ -92,6 +92,7 @@ private: QLabel *onroadLbl; LabelControl *versionLbl; ButtonControl *installBtn; + ButtonControl *onOffRoadBtn; ButtonControl *downloadBtn; ButtonControl *targetBranchBtn; diff --git a/selfdrive/ui/qt/offroad/software_settings.cc b/selfdrive/ui/qt/offroad/software_settings.cc index 43358ad72..e2a333068 100644 --- a/selfdrive/ui/qt/offroad/software_settings.cc +++ b/selfdrive/ui/qt/offroad/software_settings.cc @@ -29,6 +29,16 @@ SoftwarePanel::SoftwarePanel(QWidget* parent) : ListWidget(parent) { versionLbl = new LabelControl(tr("Current Version"), ""); addItem(versionLbl); + // on/off road mode switch + onOffRoadBtn = new ButtonControl(tr("Onroad/Offroad Mode"), tr("Go Offroad")); + connect(onOffRoadBtn, &ButtonControl::clicked, [&]() { + if (ConfirmationDialog::confirm(tr("Are you sure you want to switch mode?"), tr("CONFIRM"), this)) { + bool val = params.getBool("dp_device_go_off_road"); + params.putBool("dp_device_go_off_road", !val); + } + }); + addItem(onOffRoadBtn); + // download update btn downloadBtn = new ButtonControl(tr("Download"), tr("CHECK")); connect(downloadBtn, &ButtonControl::clicked, [=]() { @@ -111,6 +121,7 @@ void SoftwarePanel::updateLabels() { fs_watch->addParam("UpdateFailedCount"); fs_watch->addParam("UpdaterState"); fs_watch->addParam("UpdateAvailable"); + fs_watch->addParam("dp_device_go_off_road"); if (!isVisible()) { return; @@ -120,6 +131,13 @@ void SoftwarePanel::updateLabels() { onroadLbl->setVisible(is_onroad); downloadBtn->setVisible(!is_onroad); + // on/off road text change + if (params.getBool("dp_device_go_off_road")) { + onOffRoadBtn->setText(tr("Go Onroad")); + } else { + onOffRoadBtn->setText(tr("Go Offroad")); + } + // download update QString updater_state = QString::fromStdString(params.get("UpdaterState")); bool failed = std::atoi(params.get("UpdateFailedCount").c_str()) > 0; diff --git a/system/hardware/hardwared.py b/system/hardware/hardwared.py index 9a1e00289..1dc8fb579 100755 --- a/system/hardware/hardwared.py +++ b/system/hardware/hardwared.py @@ -204,6 +204,8 @@ def hardware_thread(end_event, hw_queue) -> None: fan_controller = None + dp_device_go_off_road = False + while not end_event.is_set(): sm.update(PANDA_STATES_TIMEOUT) @@ -333,7 +335,9 @@ def hardware_thread(end_event, hw_queue) -> None: pass # Handle offroad/onroad transition - should_start = all(onroad_conditions.values()) + if count % 6 == 0: + dp_device_go_off_road = params.get_bool("dp_device_go_off_road") + should_start = not dp_device_go_off_road and all(onroad_conditions.values()) if started_ts is None: should_start = should_start and all(startup_conditions.values())