Skip to content

Commit

Permalink
ui: emit offroadTransition in UIState::updateStatus (commaai#23265)
Browse files Browse the repository at this point in the history
  • Loading branch information
deanlee authored Jan 4, 2022
1 parent 7b612d4 commit 21ee6d2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
38 changes: 17 additions & 21 deletions selfdrive/ui/ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<SubMaster, const std::initializer_list<const char *>>({
"modelV2", "controlsState", "liveCalibration", "radarState", "deviceState", "roadCameraState",
Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions selfdrive/ui/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit 21ee6d2

Please sign in to comment.