From 78d65db2189ed43ec0e9fa546775e6c4f2bc6ae8 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Thu, 3 Jun 2021 23:06:14 -0700 Subject: [PATCH] limit icon flickering in UI (#21132) old-commit-hash: 2ddfd829134effcf9420019a92984a3133a3f20b --- selfdrive/ui/paint.cc | 5 ++--- selfdrive/ui/ui.cc | 5 +++++ selfdrive/ui/ui.h | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/selfdrive/ui/paint.cc b/selfdrive/ui/paint.cc index 39c1aebda6..eb834ef9fd 100644 --- a/selfdrive/ui/paint.cc +++ b/selfdrive/ui/paint.cc @@ -211,7 +211,7 @@ static void ui_draw_vision_speed(UIState *s) { } static void ui_draw_vision_event(UIState *s) { - if ((*s->sm)["controlsState"].getControlsState().getEngageable()) { + if (s->scene.engageable) { // draw steering wheel const int radius = 96; const int center_x = s->viz_rect.right() - radius - bdr_s * 2; @@ -226,8 +226,7 @@ static void ui_draw_vision_face(UIState *s) { const int radius = 96; const int center_x = s->viz_rect.x + radius + (bdr_s * 2); const int center_y = s->viz_rect.bottom() - footer_h / 2; - bool is_active = (*s->sm)["driverMonitoringState"].getDriverMonitoringState().getIsActiveMode(); - ui_draw_circle_image(s, center_x, center_y, radius, "driver_face", is_active); + ui_draw_circle_image(s, center_x, center_y, radius, "driver_face", s->scene.dm_active); } static void ui_draw_vision_header(UIState *s) { diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index caf64c0958..b43a71d1a3 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -129,6 +129,11 @@ static void update_state(UIState *s) { SubMaster &sm = *(s->sm); UIScene &scene = s->scene; + // update engageability and DM icons at 2Hz + if (sm.frame % (UI_FREQ / 2) == 0) { + scene.engageable = sm["controlsState"].getControlsState().getEngageable(); + scene.dm_active = sm["driverMonitoringState"].getDriverMonitoringState().getIsActiveMode(); + } if (sm.updated("radarState")) { std::optional line; if (sm.rcv_frame("modelV2") > 0) { diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 8be67ae2f2..af5be5b121 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -94,6 +94,8 @@ typedef struct UIScene { line_vertices_data lane_line_vertices[4]; line_vertices_data road_edge_vertices[2]; + bool dm_active, engageable; + // lead vertex_data lead_vertices[2];