ui onroad: utilize local variables for repeated capnp reader access (#29325)

old-commit-hash: 22cf5421d6
beeps
Jason Wen 2 years ago committed by GitHub
parent c8c2c5f801
commit 55f7f723a0
  1. 12
      selfdrive/ui/qt/onroad.cc

@ -270,6 +270,8 @@ void AnnotatedCameraWidget::updateState(const UIState &s) {
const bool nav_alive = sm.alive("navInstruction") && sm["navInstruction"].getValid();
const auto cs = sm["controlsState"].getControlsState();
const auto car_state = sm["carState"].getCarState();
const auto nav_instruction = sm["navInstruction"].getNavInstruction();
// Handle older routes where vCruiseCluster is not set
float v_cruise = cs.getVCruiseCluster() == 0.0 ? cs.getVCruise() : cs.getVCruiseCluster();
@ -281,17 +283,17 @@ void AnnotatedCameraWidget::updateState(const UIState &s) {
// Handle older routes where vEgoCluster is not set
float v_ego;
if (sm["carState"].getCarState().getVEgoCluster() == 0.0 && !v_ego_cluster_seen) {
v_ego = sm["carState"].getCarState().getVEgo();
if (car_state.getVEgoCluster() == 0.0 && !v_ego_cluster_seen) {
v_ego = car_state.getVEgo();
} else {
v_ego = sm["carState"].getCarState().getVEgoCluster();
v_ego = car_state.getVEgoCluster();
v_ego_cluster_seen = true;
}
float cur_speed = cs_alive ? std::max<float>(0.0, v_ego) : 0.0;
cur_speed *= s.scene.is_metric ? MS_TO_KPH : MS_TO_MPH;
auto speed_limit_sign = sm["navInstruction"].getNavInstruction().getSpeedLimitSign();
float speed_limit = nav_alive ? sm["navInstruction"].getNavInstruction().getSpeedLimit() : 0.0;
auto speed_limit_sign = nav_instruction.getSpeedLimitSign();
float speed_limit = nav_alive ? nav_instruction.getSpeedLimit() : 0.0;
speed_limit *= (s.scene.is_metric ? MS_TO_KPH : MS_TO_MPH);
setProperty("speedLimit", speed_limit);

Loading…
Cancel
Save