Skip to content

Commit

Permalink
Re-use "is_metric" declaration (commaai#32948)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrogAi authored Jul 13, 2024
1 parent 50f5568 commit 953e566
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions selfdrive/ui/qt/onroad/annotated_camera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,23 @@ 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;
}

// Handle older routes where vEgoCluster is not set
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<float>(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;

Expand Down

0 comments on commit 953e566

Please sign in to comment.