From aec4fa3814c604570c94a246bd07f08772c87aee Mon Sep 17 00:00:00 2001 From: Rick Lan Date: Tue, 27 May 2025 20:02:56 +0800 Subject: [PATCH] Border Indicator - 2025-05-27 --- selfdrive/ui/qt/onroad/onroad_home.cc | 38 +++++++++++++++++++++++++-- selfdrive/ui/qt/onroad/onroad_home.h | 20 ++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/selfdrive/ui/qt/onroad/onroad_home.cc b/selfdrive/ui/qt/onroad/onroad_home.cc index 080f9bd50..f8faf2787 100644 --- a/selfdrive/ui/qt/onroad/onroad_home.cc +++ b/selfdrive/ui/qt/onroad/onroad_home.cc @@ -39,16 +39,48 @@ OnroadWindow::OnroadWindow(QWidget *parent) : QWidget(parent) { QObject::connect(uiState(), &UIState::offroadTransition, this, &OnroadWindow::offroadTransition); } +void OnroadWindow::updateDpIndicatorSideState(bool blinker_state, bool bsm_state, bool &show, bool &show_prev, int &count, QColor &color) { + if (!blinker_state && !bsm_state) { + show = false; + count = 0; + } else { + count += 1; + } + if (bsm_state && blinker_state) { + show = count % DP_INDICATOR_BLINK_RATE_FAST == 0? !show : show; + color = DP_INDICATOR_COLOR_BSM; + } else if (blinker_state) { + show = count % DP_INDICATOR_BLINK_RATE_STD == 0? !show : show; + color = DP_INDICATOR_COLOR_BLINKER; + } else if (bsm_state) { + show = true; + color = DP_INDICATOR_COLOR_BSM; + } else { + show = false; + } +} + +void OnroadWindow::updateDpIndicatorStates(const UIState &s) { + const auto cs = (*s.sm)["carState"].getCarState(); + updateDpIndicatorSideState(cs.getLeftBlinker(), cs.getLeftBlindspot(), dp_indicator_show_left, dp_indicator_show_left_prev, dp_indicator_count_left, dp_indicator_color_left); + updateDpIndicatorSideState(cs.getRightBlinker(), cs.getRightBlindspot(), dp_indicator_show_right, dp_indicator_show_right_prev, dp_indicator_count_right, dp_indicator_color_right); +} + void OnroadWindow::updateState(const UIState &s) { if (!s.scene.started) { return; } + dp_indicator_show_left_prev = dp_indicator_show_left; + dp_indicator_show_right_prev = dp_indicator_show_right; + updateDpIndicatorStates(s); + bool indicator_states_changed = dp_indicator_show_left != dp_indicator_show_left_prev || dp_indicator_show_right != dp_indicator_show_right_prev; + alerts->updateState(s); nvg->updateState(s); QColor bgColor = bg_colors[s.status]; - if (bg != bgColor) { + if (bg != bgColor || indicator_states_changed) { // repaint border bg = bgColor; update(); @@ -61,5 +93,7 @@ void OnroadWindow::offroadTransition(bool offroad) { void OnroadWindow::paintEvent(QPaintEvent *event) { QPainter p(this); - p.fillRect(rect(), QColor(bg.red(), bg.green(), bg.blue(), 255)); + p.fillRect(rect(), QColor(bg.red(), bg.green(), bg.blue(), 180)); + if (dp_indicator_show_left) p.fillRect(QRect(0, 0, width() * 0.2, height()), dp_indicator_color_left); + if (dp_indicator_show_right) p.fillRect(QRect(width() * 0.8, 0, width() * 0.2, height()), dp_indicator_color_right); } diff --git a/selfdrive/ui/qt/onroad/onroad_home.h b/selfdrive/ui/qt/onroad/onroad_home.h index c321d2d44..dc4eb81b3 100644 --- a/selfdrive/ui/qt/onroad/onroad_home.h +++ b/selfdrive/ui/qt/onroad/onroad_home.h @@ -1,11 +1,18 @@ #pragma once +#include + #include "selfdrive/ui/qt/onroad/alerts.h" #include "selfdrive/ui/qt/onroad/annotated_camera.h" class OnroadWindow : public QWidget { Q_OBJECT + const int DP_INDICATOR_BLINK_RATE_STD = 8; + const int DP_INDICATOR_BLINK_RATE_FAST = 4; + const QColor DP_INDICATOR_COLOR_BLINKER = QColor(0, 0xff, 0, 255); + const QColor DP_INDICATOR_COLOR_BSM = QColor(0xff, 0xff, 0, 255); + public: OnroadWindow(QWidget* parent = 0); @@ -16,6 +23,19 @@ private: QColor bg = bg_colors[STATUS_DISENGAGED]; QHBoxLayout* split; + void updateDpIndicatorSideState(bool blinker_state, bool bsm_state, bool &show, bool &show_prev, int &count, QColor &color); + void updateDpIndicatorStates(const UIState &s); + // left + int dp_indicator_count_left = 0; + QColor dp_indicator_color_left = DP_INDICATOR_COLOR_BLINKER; + bool dp_indicator_show_left = false; + bool dp_indicator_show_left_prev = false; + // right + int dp_indicator_count_right = 0; + QColor dp_indicator_color_right = DP_INDICATOR_COLOR_BLINKER; + bool dp_indicator_show_right = false; + bool dp_indicator_show_right_prev = false; + private slots: void offroadTransition(bool offroad); void updateState(const UIState &s);