Re-use "is_metric" declaration (#32948)

old-commit-hash: 953e5667b1
This commit is contained in:
James 2024-07-12 17:07:57 -07:00 committed by GitHub
parent 25985e3999
commit 5cdff92d43
1 changed files with 5 additions and 4 deletions

View File

@ -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<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;