From 21ee6d25c7f84be810a6ed31cc2cf5aa94a89c11 Mon Sep 17 00:00:00 2001 From: Dean Lee Date: Tue, 4 Jan 2022 09:35:05 +0800 Subject: [PATCH] ui: emit offroadTransition in UIState::updateStatus (#23265) --- selfdrive/ui/ui.cc | 38 +++++++++++++++++--------------------- selfdrive/ui/ui.h | 1 + 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index 5c67d5f474..3d8f50e238 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -184,33 +184,34 @@ void ui_update_params(UIState *s) { s->scene.is_metric = Params().getBool("IsMetric"); } -static void update_status(UIState *s) { - if (s->scene.started && s->sm->updated("controlsState")) { - auto controls_state = (*s->sm)["controlsState"].getControlsState(); +void UIState::updateStatus() { + if (scene.started && sm->updated("controlsState")) { + auto controls_state = (*sm)["controlsState"].getControlsState(); auto alert_status = controls_state.getAlertStatus(); if (alert_status == cereal::ControlsState::AlertStatus::USER_PROMPT) { - s->status = STATUS_WARNING; + status = STATUS_WARNING; } else if (alert_status == cereal::ControlsState::AlertStatus::CRITICAL) { - s->status = STATUS_ALERT; + status = STATUS_ALERT; } else { - s->status = controls_state.getEnabled() ? STATUS_ENGAGED : STATUS_DISENGAGED; + status = controls_state.getEnabled() ? STATUS_ENGAGED : STATUS_DISENGAGED; } } // Handle onroad/offroad transition - static bool started_prev = false; - if (s->scene.started != started_prev) { - if (s->scene.started) { - s->status = STATUS_DISENGAGED; - s->scene.started_frame = s->sm->frame; - s->scene.end_to_end = Params().getBool("EndToEndToggle"); - s->wide_camera = Hardware::TICI() ? Params().getBool("EnableWideCamera") : false; + if (scene.started != started_prev) { + if (scene.started) { + status = STATUS_DISENGAGED; + scene.started_frame = sm->frame; + scene.end_to_end = Params().getBool("EndToEndToggle"); + wide_camera = Hardware::TICI() ? Params().getBool("EnableWideCamera") : false; } + started_prev = scene.started; + emit offroadTransition(!scene.started); + } else if (sm->frame == 1) { + emit offroadTransition(!scene.started); } - started_prev = s->scene.started; } - UIState::UIState(QObject *parent) : QObject(parent) { sm = std::make_unique>({ "modelV2", "controlsState", "liveCalibration", "radarState", "deviceState", "roadCameraState", @@ -230,12 +231,7 @@ UIState::UIState(QObject *parent) : QObject(parent) { void UIState::update() { update_sockets(this); update_state(this); - update_status(this); - - if (scene.started != started_prev || sm->frame == 1) { - started_prev = scene.started; - emit offroadTransition(!scene.started); - } + updateStatus(); if (sm->frame % UI_FREQ == 0) { watchdog_kick(); diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 01e4253024..b215bfa9b5 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -113,6 +113,7 @@ class UIState : public QObject { public: UIState(QObject* parent = 0); + void updateStatus(); inline bool worldObjectsVisible() const { return sm->rcv_frame("liveCalibration") > scene.started_frame; };