diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index ec3d40961d..5dde3e0c90 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -68,13 +68,27 @@ void ui_update_params(UIState *s) { } void UIState::updateStatus() { - if (scene.started && sm->updated("selfdriveState")) { - auto ss = (*sm)["selfdriveState"].getSelfdriveState(); - auto state = ss.getState(); - if (state == cereal::SelfdriveState::OpenpilotState::PRE_ENABLED || state == cereal::SelfdriveState::OpenpilotState::OVERRIDING) { - status = STATUS_OVERRIDE; - } else { - status = ss.getEnabled() ? STATUS_ENGAGED : STATUS_DISENGAGED; + if (scene.started) { + // Check for user flag events + if (sm->updated("userFlag")) { + user_flag_active_frame = sm->frame; + } + + // Show user flag status for 1 second after event is received + if (user_flag_active_frame > 0 && (sm->frame - user_flag_active_frame) < (1 * UI_FREQ)) { + status = STATUS_USER_FLAG; + return; // Skip rest of status checks for this frame + } + + // Check for selfdrive state status + if (sm->updated("selfdriveState")) { + auto ss = (*sm)["selfdriveState"].getSelfdriveState(); + auto state = ss.getState(); + if (state == cereal::SelfdriveState::OpenpilotState::PRE_ENABLED || state == cereal::SelfdriveState::OpenpilotState::OVERRIDING) { + status = STATUS_OVERRIDE; + } else { + status = ss.getEnabled() ? STATUS_ENGAGED : STATUS_DISENGAGED; + } } } @@ -93,7 +107,7 @@ UIState::UIState(QObject *parent) : QObject(parent) { sm = std::make_unique(std::vector{ "modelV2", "controlsState", "liveCalibration", "radarState", "deviceState", "pandaStates", "carParams", "driverMonitoringState", "carState", "driverStateV2", - "wideRoadCameraState", "managerState", "selfdriveState", "longitudinalPlan", + "wideRoadCameraState", "managerState", "selfdriveState", "longitudinalPlan", "userFlag" }); prime_state = new PrimeState(this); language = QString::fromStdString(Params().get("LanguageSetting")); diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 6ff67cacde..706d3acc24 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -42,12 +42,14 @@ typedef enum UIStatus { STATUS_DISENGAGED, STATUS_OVERRIDE, STATUS_ENGAGED, + STATUS_USER_FLAG, } UIStatus; const QColor bg_colors [] = { [STATUS_DISENGAGED] = QColor(0x17, 0x33, 0x49, 0xc8), [STATUS_OVERRIDE] = QColor(0x91, 0x9b, 0x95, 0xf1), [STATUS_ENGAGED] = QColor(0x17, 0x86, 0x44, 0xf1), + [STATUS_USER_FLAG] = QColor(0xff, 0xff, 0x00, 0xf1), }; typedef struct UIScene { @@ -77,6 +79,7 @@ public: UIScene scene = {}; QString language; PrimeState *prime_state; + uint64_t user_flag_active_frame = 0; // frame when user flag was received signals: void uiUpdate(const UIState &s);