diff --git a/selfdrive/car/interfaces.py b/selfdrive/car/interfaces.py index 29331b48a454ad..1766353a9e7fa0 100644 --- a/selfdrive/car/interfaces.py +++ b/selfdrive/car/interfaces.py @@ -399,6 +399,7 @@ def get_sp_common_state(self, cs_out, CS, gear_allowed=True): cs_out.madsEnabled = CS.madsEnabled cs_out.accEnabled = CS.accEnabled cs_out.disengageByBrake = CS.disengageByBrake + cs_out.brakeLights |= cs_out.brakePressed or cs_out.brakeHoldActive or cs_out.parkingBrake or cs_out.regenBraking or cs_out.brake return cs_out, CS diff --git a/selfdrive/ui/qt/onroad.cc b/selfdrive/ui/qt/onroad.cc index 6b5cc07ab10961..bfb7fd7e5c631e 100644 --- a/selfdrive/ui/qt/onroad.cc +++ b/selfdrive/ui/qt/onroad.cc @@ -302,6 +302,8 @@ void AnnotatedCameraWidget::updateState(const UIState &s) { setProperty("dynamicLaneProfileToggle", s.scene.dynamic_lane_profile_toggle); setProperty("dynamicLaneProfile", s.scene.dynamic_lane_profile); + setProperty("brakeLights", car_state.getBrakeLights()); + // update engageability/experimental mode button experimental_btn->updateState(s); @@ -455,7 +457,7 @@ void AnnotatedCameraWidget::drawHud(QPainter &p) { // current speed configFont(p, "Inter", 176, "Bold"); - drawText(p, rect().center().x(), 210, speedStr); + drawSpeedText(p, rect().center().x(), 210, speedStr, brakeLights ? QColor(0xff, 0, 0, 255) : QColor(0xff, 0xff, 0xff, 255)); configFont(p, "Inter", 66, "Regular"); drawText(p, rect().center().x(), 290, speedUnit, 200); @@ -485,6 +487,16 @@ void AnnotatedCameraWidget::drawText(QPainter &p, int x, int y, const QString &t p.drawText(real_rect.x(), real_rect.bottom(), text); } +void AnnotatedCameraWidget::drawSpeedText(QPainter &p, int x, int y, const QString &text, QColor color) { + QFontMetrics fm(p.font()); + QRect init_rect = fm.boundingRect(text); + QRect real_rect = fm.boundingRect(init_rect, 0, text); + real_rect.moveCenter({x, y - real_rect.height() / 2}); + + p.setPen(color); + p.drawText(real_rect.x(), real_rect.bottom(), text); +} + void AnnotatedCameraWidget::drawIcon(QPainter &p, int x, int y, QPixmap &img, QBrush bg, float opacity) { p.setOpacity(1.0); // bg dictates opacity of ellipse p.setPen(Qt::NoPen); diff --git a/selfdrive/ui/qt/onroad.h b/selfdrive/ui/qt/onroad.h index 11986494b5eade..f88d5d5d3ef4ff 100644 --- a/selfdrive/ui/qt/onroad.h +++ b/selfdrive/ui/qt/onroad.h @@ -68,6 +68,8 @@ class AnnotatedCameraWidget : public CameraWidget { Q_PROPERTY(bool dynamicLaneProfileToggle MEMBER dynamicLaneProfileToggle); Q_PROPERTY(int dynamicLaneProfile MEMBER dynamicLaneProfile); + Q_PROPERTY(bool brakeLights MEMBER brakeLights); + public: explicit AnnotatedCameraWidget(VisionStreamType type, QWidget* parent = 0); void updateState(const UIState &s); @@ -77,6 +79,7 @@ class AnnotatedCameraWidget : public CameraWidget { void drawText(QPainter &p, int x, int y, const QString &text, int alpha = 255); void drawDlpButton(QPainter &p, int x, int y, int w, int h); + void drawSpeedText(QPainter &p, int x, int y, const QString &text, QColor color); ExperimentalButton *experimental_btn; QPixmap dm_img; @@ -105,6 +108,8 @@ class AnnotatedCameraWidget : public CameraWidget { bool dynamicLaneProfileToggle; int dynamicLaneProfile; + bool brakeLights; + protected: void paintGL() override; void initializeGL() override; diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index 3e5465b65702a8..834c001750f2f7 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -178,6 +178,7 @@ void ui_update_params(UIState *s) { s->scene.is_metric = params.getBool("IsMetric"); s->scene.map_on_left = params.getBool("NavSettingLeftSide"); s->scene.dynamic_lane_profile_toggle = params.getBool("DynamicLaneProfileToggle"); + s->scene.visual_brake_lights = params.getBool("BrakeLights"); } void UIState::updateStatus() { diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 13dfa3ed8cdaad..838d09434f3a4e 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -111,6 +111,8 @@ typedef struct UIScene { int dynamic_lane_profile; bool dynamic_lane_profile_status, dynamic_lane_profile_toggle; + + bool visual_brake_lights; } UIScene; class UIState : public QObject {