mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-07-07 05:42:06 +08:00
ui: emit offroadTransition in UIState::updateStatus (#23265)
This commit is contained in:
+17
-21
@@ -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",
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user