From acf280e15babfc5654b0cfc093b7050dbd9205e5 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Fri, 15 Sep 2023 22:55:59 -0400 Subject: [PATCH] ui: Handle frequency checks for live params and other elements (#278) --- selfdrive/ui/qt/sidebar.cc | 4 +--- selfdrive/ui/qt/sidebar.h | 1 - selfdrive/ui/ui.cc | 16 +++++++++++----- selfdrive/ui/ui.h | 1 - 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/selfdrive/ui/qt/sidebar.cc b/selfdrive/ui/qt/sidebar.cc index f17822c5c4..eca5247b0f 100644 --- a/selfdrive/ui/qt/sidebar.cc +++ b/selfdrive/ui/qt/sidebar.cc @@ -92,9 +92,7 @@ void Sidebar::updateState(const UIState &s) { } setProperty("connectStatus", QVariant::fromValue(connectStatus)); - if (millis_since_boot() - last_temp_count > 1000 * 1) { - last_temp_count = millis_since_boot(); - + if (sm.frame % (UI_FREQ / 20) == 0) { // Update every 1 Hz switch (s.scene.sidebar_temp_options) { case 0: sidebar_temp = QString::number((int)deviceState.getAmbientTempC()); diff --git a/selfdrive/ui/qt/sidebar.h b/selfdrive/ui/qt/sidebar.h index 01ad00915c..4297602908 100644 --- a/selfdrive/ui/qt/sidebar.h +++ b/selfdrive/ui/qt/sidebar.h @@ -61,7 +61,6 @@ protected: private: std::unique_ptr pm; - uint64_t last_temp_count; QString sidebar_temp = "0"; QString sidebar_temp_str = "0"; }; diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index 8d39e35db4..5884660b37 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -231,15 +231,14 @@ void ui_update_params(UIState *s) { auto params = Params(); s->scene.is_metric = params.getBool("IsMetric"); s->scene.map_on_left = params.getBool("NavSettingLeftSide"); + s->scene.dynamic_lane_profile_toggle = params.getBool("DynamicLaneProfileToggle"); - s->scene.dynamic_lane_profile = std::atoi(params.get("DynamicLaneProfile").c_str()); s->scene.visual_brake_lights = params.getBool("BrakeLights"); s->scene.onroadScreenOff = std::atoi(params.get("OnroadScreenOff").c_str()); s->scene.onroadScreenOffBrightness = std::atoi(params.get("OnroadScreenOffBrightness").c_str()); s->scene.onroadScreenOffEvent = params.getBool("OnroadScreenOffEvent"); s->scene.brightness = std::atoi(params.get("BrightnessControl").c_str()); s->scene.stand_still_timer = params.getBool("StandStillTimer"); - s->scene.speed_limit_control_enabled = params.getBool("SpeedLimitControl"); s->scene.speed_limit_perc_offset = params.getBool("SpeedLimitPercOffset"); s->scene.show_debug_ui = params.getBool("ShowDebugUI"); s->scene.debug_snapshot_enabled = params.getBool("EnableDebugSnapshot"); @@ -253,7 +252,6 @@ void ui_update_params(UIState *s) { s->scene.e2e_long_alert_light = params.getBool("EndToEndLongAlertLight"); s->scene.e2e_long_alert_lead = params.getBool("EndToEndLongAlertLead"); s->scene.e2e_long_alert_ui = params.getBool("EndToEndLongAlertUI"); - s->scene.longitudinal_personality = std::atoi(params.get("LongitudinalPersonality").c_str()); // Handle Onroad Screen Off params if (s->scene.onroadScreenOff > 0) { @@ -314,6 +312,15 @@ void UIState::updateStatus() { } if (scene.started) { + // Update live params when the camera view is on + { + if (sm->frame % (UI_FREQ / 10) == 0) { // Update every 2 Hz + scene.dynamic_lane_profile = std::atoi(params.get("DynamicLaneProfile").c_str()); + scene.longitudinal_personality = std::atoi(params.get("LongitudinalPersonality").c_str()); + scene.speed_limit_control_enabled = params.getBool("SpeedLimitControl"); + } + } + // Auto hide UI button state machine { if (scene.button_auto_hide) { @@ -366,8 +373,7 @@ void UIState::updateStatus() { } } - if (millis_since_boot() - last_update_params_sidebar > 1000 * 1) { - last_update_params_sidebar = millis_since_boot(); + if (sm->frame % (UI_FREQ / 20) == 0) { // Update every 1 Hz scene.sidebar_temp = params.getBool("SidebarTemperature"); scene.sidebar_temp_options = std::atoi(params.get("SidebarTemperatureOptions").c_str()); } diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 23ccc48b84..086acdeb89 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -265,7 +265,6 @@ private: QTimer *timer; bool started_prev = false; PrimeType prime_type = PrimeType::UNKNOWN; - uint64_t last_update_params_sidebar; bool last_mads_enabled = false; bool mads_path_state = false;