From 8970a7aa5b5686ccee62b92a2f99a5dcce2b90da Mon Sep 17 00:00:00 2001 From: DevTekVE Date: Mon, 6 Jan 2025 00:58:10 +0100 Subject: [PATCH] ui: prevent driving model change with offroad transition (#524) * Update model manager logic and handle offroad transitions Added is_onroad state tracking in SoftwarePanelSP to handle offroad transitions. Updated model manager conditions for improved bundle validation. Removed unnecessary clear operation for ModelManager_DownloadIndex during offroad transitions to optimize behavior. * Using is_onroad softwarePanel * Enable model label button only when conditions are met Previously, the button's state update was misplaced, leading to potential issues with its interactive availability. The logic has been adjusted to ensure it is properly enabled or disabled based on onroad status and download progress. This change improves UX consistency and prevents unintended actions. * Remove redundant setEnabled call for currentModelLblBtn The setEnabled call was unnecessary as its functionality was not required in this context. Cleaning up this code improves readability and removes redundant operations. No changes to functionality or behavior were introduced. --------- Co-authored-by: Jason Wen --- common/params.cc | 2 +- selfdrive/ui/sunnypilot/qt/offroad/settings/software_panel.cc | 4 +--- selfdrive/ui/sunnypilot/qt/offroad/settings/software_panel.h | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/common/params.cc b/common/params.cc index edf002f10..bface2161 100644 --- a/common/params.cc +++ b/common/params.cc @@ -212,7 +212,7 @@ std::unordered_map keys = { // Model Manager params {"ModelManager_ActiveBundle", PERSISTENT}, - {"ModelManager_DownloadIndex", CLEAR_ON_MANAGER_START | CLEAR_ON_OFFROAD_TRANSITION | CLEAR_ON_ONROAD_TRANSITION}, + {"ModelManager_DownloadIndex", CLEAR_ON_MANAGER_START | CLEAR_ON_ONROAD_TRANSITION}, {"ModelManager_LastSyncTime", CLEAR_ON_MANAGER_START | CLEAR_ON_OFFROAD_TRANSITION}, {"ModelManager_ModelsCache", PERSISTENT | BACKUP}, diff --git a/selfdrive/ui/sunnypilot/qt/offroad/settings/software_panel.cc b/selfdrive/ui/sunnypilot/qt/offroad/settings/software_panel.cc index 6bbef9fb9..e3a921448 100644 --- a/selfdrive/ui/sunnypilot/qt/offroad/settings/software_panel.cc +++ b/selfdrive/ui/sunnypilot/qt/offroad/settings/software_panel.cc @@ -83,8 +83,6 @@ void SoftwarePanelSP::handleBundleDownloadProgress() { if (bundle.getStatus() == cereal::ModelManagerSP::DownloadStatus::DOWNLOADING) { currentModelLblBtn->showDescription(); } - - currentModelLblBtn->setEnabled(!is_onroad && !isDownloading()); } /** @@ -128,7 +126,6 @@ void SoftwarePanelSP::handleCurrentModelLblBtnClicked() { bundleNames.append(index_to_bundle[index]); } - currentModelLblBtn->setEnabled(!is_onroad); currentModelLblBtn->setValue(GetActiveModelName()); const QString selectedBundleName = MultiOptionDialog::getSelection( @@ -161,6 +158,7 @@ void SoftwarePanelSP::updateLabels() { } handleBundleDownloadProgress(); + currentModelLblBtn->setEnabled(!is_onroad && !isDownloading()); currentModelLblBtn->setValue(GetActiveModelName()); SoftwarePanel::updateLabels(); } diff --git a/selfdrive/ui/sunnypilot/qt/offroad/settings/software_panel.h b/selfdrive/ui/sunnypilot/qt/offroad/settings/software_panel.h index fd837e31f..7dd9bbc5e 100644 --- a/selfdrive/ui/sunnypilot/qt/offroad/settings/software_panel.h +++ b/selfdrive/ui/sunnypilot/qt/offroad/settings/software_panel.h @@ -24,7 +24,7 @@ private: const SubMaster &sm = *(uiStateSP()->sm); const auto model_manager = sm["modelManagerSP"].getModelManagerSP(); - if (!model_manager.hasSelectedBundle()) { + if (!model_manager.hasSelectedBundle() || !sm.updated("modelManagerSP")) { return false; }