From 01df7f02d6bcbbdd4701d4765031499b93586a35 Mon Sep 17 00:00:00 2001 From: deanlee Date: Tue, 16 Nov 2021 15:42:12 +0800 Subject: [PATCH 1/4] remove update_params --- selfdrive/ui/ui.cc | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index 054e90e1768a82..8e02582d74ff91 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -186,14 +186,6 @@ static void update_state(UIState *s) { scene.started = sm["deviceState"].getDeviceState().getStarted() && scene.ignition; } -static void update_params(UIState *s) { - const uint64_t frame = s->sm->frame; - UIScene &scene = s->scene; - if (frame % (5*UI_FREQ) == 0) { - 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(); @@ -211,10 +203,12 @@ static void update_status(UIState *s) { static bool started_prev = false; if (s->scene.started != started_prev) { if (s->scene.started) { + Params params; 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; + s->scene.is_metric = params.getBool("IsMetric"); + s->scene.end_to_end = params.getBool("EndToEndToggle"); + s->wide_camera = Hardware::TICI() ? params.getBool("EnableWideCamera") : false; } // Invisible until we receive a calibration message. s->scene.world_objects_visible = false; @@ -240,7 +234,6 @@ QUIState::QUIState(QObject *parent) : QObject(parent) { } void QUIState::update() { - update_params(&ui_state); update_sockets(&ui_state); update_state(&ui_state); update_status(&ui_state); From 33856956b968ad602635164ed6261fb7dbe317a2 Mon Sep 17 00:00:00 2001 From: deanlee Date: Tue, 16 Nov 2021 19:09:28 +0800 Subject: [PATCH 2/4] update in showEvent --- selfdrive/ui/paint.h | 1 + selfdrive/ui/qt/onroad.cc | 5 +++++ selfdrive/ui/qt/onroad.h | 1 + selfdrive/ui/ui.cc | 10 ++++++---- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/selfdrive/ui/paint.h b/selfdrive/ui/paint.h index 55fe9c1d0835f1..70096cb9733bf8 100644 --- a/selfdrive/ui/paint.h +++ b/selfdrive/ui/paint.h @@ -2,6 +2,7 @@ #include "selfdrive/ui/ui.h" +void ui_update_params(UIState *s); void ui_draw(UIState *s, int w, int h); void ui_draw_image(const UIState *s, const Rect &r, const char *name, float alpha); void ui_draw_rect(NVGcontext *vg, const Rect &r, NVGcolor color, int width, float radius = 0); diff --git a/selfdrive/ui/qt/onroad.cc b/selfdrive/ui/qt/onroad.cc index c3fbdcb6e64112..bb65b08fb721a2 100644 --- a/selfdrive/ui/qt/onroad.cc +++ b/selfdrive/ui/qt/onroad.cc @@ -186,3 +186,8 @@ void NvgWindow::paintGL() { } prev_draw_t = cur_draw_t; } + +void NvgWindow::showEvent(QShowEvent *event) { + CameraViewWidget::showEvent(event); + ui_update_params(&QUIState::ui_state); +} diff --git a/selfdrive/ui/qt/onroad.h b/selfdrive/ui/qt/onroad.h index 9be04e04ae473f..ee44973cf24c19 100644 --- a/selfdrive/ui/qt/onroad.h +++ b/selfdrive/ui/qt/onroad.h @@ -34,6 +34,7 @@ class NvgWindow : public CameraViewWidget { protected: void paintGL() override; void initializeGL() override; + void showEvent(QShowEvent *event) override; double prev_draw_t = 0; }; diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index 8e02582d74ff91..016bf72d1d00c5 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -186,6 +186,10 @@ static void update_state(UIState *s) { scene.started = sm["deviceState"].getDeviceState().getStarted() && scene.ignition; } +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(); @@ -203,12 +207,10 @@ static void update_status(UIState *s) { static bool started_prev = false; if (s->scene.started != started_prev) { if (s->scene.started) { - Params params; s->status = STATUS_DISENGAGED; s->scene.started_frame = s->sm->frame; - s->scene.is_metric = params.getBool("IsMetric"); - s->scene.end_to_end = params.getBool("EndToEndToggle"); - s->wide_camera = Hardware::TICI() ? params.getBool("EnableWideCamera") : false; + s->scene.end_to_end = Params().getBool("EndToEndToggle"); + s->wide_camera = Hardware::TICI() ? Params().getBool("EnableWideCamera") : false; } // Invisible until we receive a calibration message. s->scene.world_objects_visible = false; From 6536abf8a308c1f0d890390ecb49ecc72cd89d72 Mon Sep 17 00:00:00 2001 From: deanlee Date: Tue, 16 Nov 2021 19:12:08 +0800 Subject: [PATCH 3/4] reset prev_draw_t in showEvent --- selfdrive/ui/qt/onroad.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/selfdrive/ui/qt/onroad.cc b/selfdrive/ui/qt/onroad.cc index bb65b08fb721a2..1eef3122e08629 100644 --- a/selfdrive/ui/qt/onroad.cc +++ b/selfdrive/ui/qt/onroad.cc @@ -190,4 +190,5 @@ void NvgWindow::paintGL() { void NvgWindow::showEvent(QShowEvent *event) { CameraViewWidget::showEvent(event); ui_update_params(&QUIState::ui_state); + prev_draw_t = millis_since_boot(); } From 85c03f11b1acb07aedd1d4c1fb796adbbf73258b Mon Sep 17 00:00:00 2001 From: deanlee Date: Tue, 16 Nov 2021 19:16:28 +0800 Subject: [PATCH 4/4] sort alphabetically --- selfdrive/ui/paint.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfdrive/ui/paint.h b/selfdrive/ui/paint.h index 70096cb9733bf8..4ce7cbd133e156 100644 --- a/selfdrive/ui/paint.h +++ b/selfdrive/ui/paint.h @@ -2,7 +2,6 @@ #include "selfdrive/ui/ui.h" -void ui_update_params(UIState *s); void ui_draw(UIState *s, int w, int h); void ui_draw_image(const UIState *s, const Rect &r, const char *name, float alpha); void ui_draw_rect(NVGcontext *vg, const Rect &r, NVGcolor color, int width, float radius = 0); @@ -10,3 +9,4 @@ void ui_fill_rect(NVGcontext *vg, const Rect &r, const NVGpaint &paint, float ra void ui_fill_rect(NVGcontext *vg, const Rect &r, const NVGcolor &color, float radius = 0); void ui_nvg_init(UIState *s); void ui_resize(UIState *s, int width, int height); +void ui_update_params(UIState *s);