Border Indicator - 2025-05-27

This commit is contained in:
Rick Lan
2025-05-27 20:02:56 +08:00
parent c7b91221ff
commit aec4fa3814
2 changed files with 56 additions and 2 deletions
+36 -2
View File
@@ -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);
}
+20
View File
@@ -1,11 +1,18 @@
#pragma once
#include <QColor>
#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);