ui: emit offroadTransition in UIState::updateStatus (#23265)

pull/23382/head
Dean Lee 3 years ago committed by GitHub
parent 7b612d47b6
commit 21ee6d25c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 38
      selfdrive/ui/ui.cc
  2. 1
      selfdrive/ui/ui.h

@ -184,33 +184,34 @@ void ui_update_params(UIState *s) {
s->scene.is_metric = Params().getBool("IsMetric"); s->scene.is_metric = Params().getBool("IsMetric");
} }
static void update_status(UIState *s) { void UIState::updateStatus() {
if (s->scene.started && s->sm->updated("controlsState")) { if (scene.started && sm->updated("controlsState")) {
auto controls_state = (*s->sm)["controlsState"].getControlsState(); auto controls_state = (*sm)["controlsState"].getControlsState();
auto alert_status = controls_state.getAlertStatus(); auto alert_status = controls_state.getAlertStatus();
if (alert_status == cereal::ControlsState::AlertStatus::USER_PROMPT) { if (alert_status == cereal::ControlsState::AlertStatus::USER_PROMPT) {
s->status = STATUS_WARNING; status = STATUS_WARNING;
} else if (alert_status == cereal::ControlsState::AlertStatus::CRITICAL) { } else if (alert_status == cereal::ControlsState::AlertStatus::CRITICAL) {
s->status = STATUS_ALERT; status = STATUS_ALERT;
} else { } else {
s->status = controls_state.getEnabled() ? STATUS_ENGAGED : STATUS_DISENGAGED; status = controls_state.getEnabled() ? STATUS_ENGAGED : STATUS_DISENGAGED;
} }
} }
// Handle onroad/offroad transition // Handle onroad/offroad transition
static bool started_prev = false; if (scene.started != started_prev) {
if (s->scene.started != started_prev) { if (scene.started) {
if (s->scene.started) { status = STATUS_DISENGAGED;
s->status = STATUS_DISENGAGED; scene.started_frame = sm->frame;
s->scene.started_frame = s->sm->frame; scene.end_to_end = Params().getBool("EndToEndToggle");
s->scene.end_to_end = Params().getBool("EndToEndToggle"); wide_camera = Hardware::TICI() ? Params().getBool("EnableWideCamera") : false;
s->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) { UIState::UIState(QObject *parent) : QObject(parent) {
sm = std::make_unique<SubMaster, const std::initializer_list<const char *>>({ sm = std::make_unique<SubMaster, const std::initializer_list<const char *>>({
"modelV2", "controlsState", "liveCalibration", "radarState", "deviceState", "roadCameraState", "modelV2", "controlsState", "liveCalibration", "radarState", "deviceState", "roadCameraState",
@ -230,12 +231,7 @@ UIState::UIState(QObject *parent) : QObject(parent) {
void UIState::update() { void UIState::update() {
update_sockets(this); update_sockets(this);
update_state(this); update_state(this);
update_status(this); updateStatus();
if (scene.started != started_prev || sm->frame == 1) {
started_prev = scene.started;
emit offroadTransition(!scene.started);
}
if (sm->frame % UI_FREQ == 0) { if (sm->frame % UI_FREQ == 0) {
watchdog_kick(); watchdog_kick();

@ -113,6 +113,7 @@ class UIState : public QObject {
public: public:
UIState(QObject* parent = 0); UIState(QObject* parent = 0);
void updateStatus();
inline bool worldObjectsVisible() const { inline bool worldObjectsVisible() const {
return sm->rcv_frame("liveCalibration") > scene.started_frame; return sm->rcv_frame("liveCalibration") > scene.started_frame;
}; };

Loading…
Cancel
Save