From 5cdff92d43638cbfd1c8a346e00db07e803a53b6 Mon Sep 17 00:00:00 2001 From: James <91348155+FrogAi@users.noreply.github.com> Date: Fri, 12 Jul 2024 17:07:57 -0700 Subject: [PATCH] Re-use "is_metric" declaration (#32948) old-commit-hash: 953e5667b1dce769611e742622e3612b0b09d9f4 --- selfdrive/ui/qt/onroad/annotated_camera.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/selfdrive/ui/qt/onroad/annotated_camera.cc b/selfdrive/ui/qt/onroad/annotated_camera.cc index b08420a713..60f2380dc5 100644 --- a/selfdrive/ui/qt/onroad/annotated_camera.cc +++ b/selfdrive/ui/qt/onroad/annotated_camera.cc @@ -31,11 +31,13 @@ void AnnotatedCameraWidget::updateState(const UIState &s) { const auto cs = sm["controlsState"].getControlsState(); const auto car_state = sm["carState"].getCarState(); + is_metric = s.scene.is_metric; + // Handle older routes where vCruiseCluster is not set float v_cruise = cs.getVCruiseCluster() == 0.0 ? cs.getVCruise() : cs.getVCruiseCluster(); setSpeed = cs_alive ? v_cruise : SET_SPEED_NA; is_cruise_set = setSpeed > 0 && (int)setSpeed != SET_SPEED_NA; - if (is_cruise_set && !s.scene.is_metric) { + if (is_cruise_set && !is_metric) { setSpeed *= KM_TO_MILE; } @@ -43,10 +45,9 @@ void AnnotatedCameraWidget::updateState(const UIState &s) { v_ego_cluster_seen = v_ego_cluster_seen || car_state.getVEgoCluster() != 0.0; float v_ego = v_ego_cluster_seen ? car_state.getVEgoCluster() : car_state.getVEgo(); speed = cs_alive ? std::max(0.0, v_ego) : 0.0; - speed *= s.scene.is_metric ? MS_TO_KPH : MS_TO_MPH; + speed *= is_metric ? MS_TO_KPH : MS_TO_MPH; - is_metric = s.scene.is_metric; - speedUnit = s.scene.is_metric ? tr("km/h") : tr("mph"); + speedUnit = is_metric ? tr("km/h") : tr("mph"); hideBottomIcons = (cs.getAlertSize() != cereal::ControlsState::AlertSize::NONE); status = s.status;