From 00d469dbc9d5ab8237247f7036892fe74c5e3c8a Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Tue, 15 Feb 2022 16:18:09 -0800 Subject: [PATCH] UI: fix power buttons disable logic (#23774) --- selfdrive/ui/qt/offroad/settings.cc | 4 ++-- selfdrive/ui/ui.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index 73dbf0a845f6e2..051eaedfa5f1cd 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -196,7 +196,7 @@ void DevicePanel::updateCalibDescription() { } void DevicePanel::reboot() { - if (uiState()->status == UIStatus::STATUS_DISENGAGED) { + if (!uiState()->engaged()) { if (ConfirmationDialog::confirm("Are you sure you want to reboot?", this)) { // Check engaged again in case it changed while the dialog was open if (uiState()->status == UIStatus::STATUS_DISENGAGED) { @@ -209,7 +209,7 @@ void DevicePanel::reboot() { } void DevicePanel::poweroff() { - if (uiState()->status == UIStatus::STATUS_DISENGAGED) { + if (!uiState()->engaged()) { if (ConfirmationDialog::confirm("Are you sure you want to power off?", this)) { // Check engaged again in case it changed while the dialog was open if (uiState()->status == UIStatus::STATUS_DISENGAGED) { diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 6847a7bc902e1a..382a7df5ed430d 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -118,6 +118,9 @@ class UIState : public QObject { inline bool worldObjectsVisible() const { return sm->rcv_frame("liveCalibration") > scene.started_frame; }; + inline bool engaged() const { + return scene.started && (*sm)["controlsState"].getControlsState().getEnabled(); + }; int fb_w = 0, fb_h = 0;