util.h: add unit conversion constants (#22813)

* Add unit conversion constants.

* move to common/util.h
pull/22826/head
Dean Lee 4 years ago committed by GitHub
parent adeeebf00e
commit e29cc1c2ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      selfdrive/common/util.h
  2. 4
      selfdrive/ui/paint.cc
  3. 6
      selfdrive/ui/qt/maps/map.cc
  4. 2
      selfdrive/ui/qt/maps/map_helpers.h
  5. 2
      selfdrive/ui/qt/widgets/drive_stats.cc

@ -30,6 +30,13 @@
typedef void (*sighandler_t)(int sig);
#endif
const double MILE_TO_KM = 1.609344;
const double KM_TO_MILE = 1. / MILE_TO_KM;
const double MS_TO_KPH = 3.6;
const double MS_TO_MPH = MS_TO_KPH * KM_TO_MILE;
const double METER_TO_MILE = KM_TO_MILE / 1000.0;
const double METER_TO_FOOT = 3.28084;
void set_thread_name(const char* name);
int set_realtime_priority(int level);

@ -155,7 +155,7 @@ static void ui_draw_vision_maxspeed(UIState *s) {
const int SET_SPEED_NA = 255;
float maxspeed = (*s->sm)["controlsState"].getControlsState().getVCruise();
const bool is_cruise_set = maxspeed != 0 && maxspeed != SET_SPEED_NA;
if (is_cruise_set && !s->scene.is_metric) { maxspeed *= 0.6225; }
if (is_cruise_set && !s->scene.is_metric) { maxspeed *= KM_TO_MILE; }
const Rect rect = {bdr_s * 2, int(bdr_s * 1.5), 184, 202};
ui_fill_rect(s->vg, rect, COLOR_BLACK_ALPHA(100), 30.);
@ -172,7 +172,7 @@ static void ui_draw_vision_maxspeed(UIState *s) {
}
static void ui_draw_vision_speed(UIState *s) {
const float speed = std::max(0.0, (*s->sm)["carState"].getCarState().getVEgo() * (s->scene.is_metric ? 3.6 : 2.2369363));
const float speed = std::max(0.0, (*s->sm)["carState"].getCarState().getVEgo() * (s->scene.is_metric ? MS_TO_KPH : MS_TO_MPH));
const std::string speed_str = std::to_string((int)std::nearbyint(speed));
nvgTextAlign(s->vg, NVG_ALIGN_CENTER | NVG_ALIGN_BASELINE);
ui_draw_text(s, s->fb_w/2, 210, speed_str.c_str(), 96 * 2.5, COLOR_WHITE, "sans-bold");

@ -381,8 +381,8 @@ void MapInstructions::updateDistance(float d) {
distance_str += " m";
}
} else {
float miles = d * METER_2_MILE;
float feet = d * METER_2_FOOT;
float miles = d * METER_TO_MILE;
float feet = d * METER_TO_FOOT;
if (feet > 500) {
distance_str.setNum(miles, 'f', 1);
@ -597,7 +597,7 @@ void MapETA::updateETA(float s, float s_typical, float d) {
num = d / 1000.0;
distance_unit->setText("km");
} else {
num = d * METER_2_MILE;
num = d * METER_TO_MILE;
distance_unit->setText("mi");
}

@ -9,8 +9,6 @@
#include "common/transformations/orientation.hpp"
#include "cereal/messaging/messaging.h"
const float METER_2_MILE = 0.000621371;
const float METER_2_FOOT = 3.28084;
#define RAD2DEG(x) ((x) * 180.0 / M_PI)
QGeoCoordinate to_QGeoCoordinate(const QMapbox::Coordinate &in);

@ -9,8 +9,6 @@
#include "selfdrive/ui/qt/request_repeater.h"
#include "selfdrive/ui/qt/util.h"
const double MILE_TO_KM = 1.60934;
static QLabel* newLabel(const QString& text, const QString &type) {
QLabel* label = new QLabel(text);
label->setProperty("type", type);

Loading…
Cancel
Save