Skip to content

Commit

Permalink
Braking status UI (commaai#18)
Browse files Browse the repository at this point in the history
* Braking status UI

* add brake

* wrong things to check
  • Loading branch information
sunnyhaibin authored Feb 6, 2023
1 parent b193992 commit ca4cbcc
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions selfdrive/car/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 13 additions & 1 deletion selfdrive/ui/qt/onroad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions selfdrive/ui/qt/onroad.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -105,6 +108,8 @@ class AnnotatedCameraWidget : public CameraWidget {
bool dynamicLaneProfileToggle;
int dynamicLaneProfile;

bool brakeLights;

protected:
void paintGL() override;
void initializeGL() override;
Expand Down
1 change: 1 addition & 0 deletions selfdrive/ui/ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions selfdrive/ui/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ca4cbcc

Please sign in to comment.