ui: move struct Alert into OnroadAlerts (#32024)

* move Alert into OnroadAlerts

* multi-lang
old-commit-hash: fad9edf344
pull/32199/head
Dean Lee 1 year ago committed by GitHub
parent 78c88cfdd4
commit 2afcc4a9a6
  1. 53
      selfdrive/ui/qt/onroad.cc
  2. 23
      selfdrive/ui/qt/onroad.h
  3. 23
      selfdrive/ui/translations/main_ar.ts
  4. 23
      selfdrive/ui/translations/main_de.ts
  5. 23
      selfdrive/ui/translations/main_fr.ts
  6. 23
      selfdrive/ui/translations/main_ja.ts
  7. 23
      selfdrive/ui/translations/main_ko.ts
  8. 23
      selfdrive/ui/translations/main_pt-BR.ts
  9. 23
      selfdrive/ui/translations/main_th.ts
  10. 23
      selfdrive/ui/translations/main_tr.ts
  11. 23
      selfdrive/ui/translations/main_zh-CHS.ts
  12. 23
      selfdrive/ui/translations/main_zh-CHT.ts
  13. 60
      selfdrive/ui/ui.h

@ -73,18 +73,16 @@ void OnroadWindow::updateState(const UIState &s) {
return;
}
QColor bgColor = bg_colors[s.status];
Alert alert = Alert::get(*(s.sm), s.scene.started_frame);
alerts->updateAlert(alert);
if (s.scene.map_on_left) {
split->setDirection(QBoxLayout::LeftToRight);
} else {
split->setDirection(QBoxLayout::RightToLeft);
}
alerts->updateState(s);
nvg->updateState(s);
QColor bgColor = bg_colors[s.status];
if (bg != bgColor) {
// repaint border
bg = bgColor;
@ -128,7 +126,7 @@ void OnroadWindow::offroadTransition(bool offroad) {
}
}
#endif
alerts->updateAlert({});
alerts->clear();
}
void OnroadWindow::primeChanged(bool prime) {
@ -152,13 +150,56 @@ void OnroadWindow::paintEvent(QPaintEvent *event) {
// ***** onroad widgets *****
// OnroadAlerts
void OnroadAlerts::updateAlert(const Alert &a) {
void OnroadAlerts::updateState(const UIState &s) {
Alert a = getAlert(*(s.sm), s.scene.started_frame);
if (!alert.equal(a)) {
alert = a;
update();
}
}
void OnroadAlerts::clear() {
alert = {};
update();
}
OnroadAlerts::Alert OnroadAlerts::getAlert(const SubMaster &sm, uint64_t started_frame) {
const cereal::ControlsState::Reader &cs = sm["controlsState"].getControlsState();
const uint64_t controls_frame = sm.rcv_frame("controlsState");
Alert a = {};
if (controls_frame >= started_frame) { // Don't get old alert.
a = {cs.getAlertText1().cStr(), cs.getAlertText2().cStr(),
cs.getAlertType().cStr(), cs.getAlertSize(), cs.getAlertStatus()};
}
if (!sm.updated("controlsState") && (sm.frame - started_frame) > 5 * UI_FREQ) {
const int CONTROLS_TIMEOUT = 5;
const int controls_missing = (nanos_since_boot() - sm.rcv_time("controlsState")) / 1e9;
// Handle controls timeout
if (controls_frame < started_frame) {
// car is started, but controlsState hasn't been seen at all
a = {tr("openpilot Unavailable"), tr("Waiting for controls to start"),
"controlsWaiting", cereal::ControlsState::AlertSize::MID,
cereal::ControlsState::AlertStatus::NORMAL};
} else if (controls_missing > CONTROLS_TIMEOUT && !Hardware::PC()) {
// car is started, but controls is lagging or died
if (cs.getEnabled() && (controls_missing - CONTROLS_TIMEOUT) < 10) {
a = {tr("TAKE CONTROL IMMEDIATELY"), tr("Controls Unresponsive"),
"controlsUnresponsive", cereal::ControlsState::AlertSize::FULL,
cereal::ControlsState::AlertStatus::CRITICAL};
} else {
a = {tr("Controls Unresponsive"), tr("Reboot Device"),
"controlsUnresponsivePermanent", cereal::ControlsState::AlertSize::MID,
cereal::ControlsState::AlertStatus::NORMAL};
}
}
}
return a;
}
void OnroadAlerts::paintEvent(QPaintEvent *event) {
if (alert.size == cereal::ControlsState::AlertSize::NONE) {
return;

@ -21,12 +21,31 @@ class OnroadAlerts : public QWidget {
public:
OnroadAlerts(QWidget *parent = 0) : QWidget(parent) {}
void updateAlert(const Alert &a);
void updateState(const UIState &s);
void clear();
protected:
struct Alert {
QString text1;
QString text2;
QString type;
cereal::ControlsState::AlertSize size;
cereal::ControlsState::AlertStatus status;
bool equal(const Alert &other) const {
return text1 == other.text1 && other.text2 == other.text2 && type == other.type;
}
};
const QMap<cereal::ControlsState::AlertStatus, QColor> alert_colors = {
{cereal::ControlsState::AlertStatus::NORMAL, QColor(0x15, 0x15, 0x15, 0xf1)},
{cereal::ControlsState::AlertStatus::USER_PROMPT, QColor(0xDA, 0x6F, 0x25, 0xf1)},
{cereal::ControlsState::AlertStatus::CRITICAL, QColor(0xC9, 0x22, 0x31, 0xf1)},
};
void paintEvent(QPaintEvent*) override;
OnroadAlerts::Alert getAlert(const SubMaster &sm, uint64_t started_frame);
private:
QColor bg;
Alert alert = {};
};

@ -492,6 +492,29 @@
<translation> تنبيه</translation>
</message>
</context>
<context>
<name>OnroadAlerts</name>
<message>
<source>openpilot Unavailable</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Waiting for controls to start</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>TAKE CONTROL IMMEDIATELY</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Controls Unresponsive</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Reboot Device</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PairingPopup</name>
<message>

@ -487,6 +487,29 @@
<translation> HINWEIS</translation>
</message>
</context>
<context>
<name>OnroadAlerts</name>
<message>
<source>openpilot Unavailable</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Waiting for controls to start</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>TAKE CONTROL IMMEDIATELY</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Controls Unresponsive</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Reboot Device</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PairingPopup</name>
<message>

@ -488,6 +488,29 @@
<translation> ALERTE</translation>
</message>
</context>
<context>
<name>OnroadAlerts</name>
<message>
<source>openpilot Unavailable</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Waiting for controls to start</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>TAKE CONTROL IMMEDIATELY</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Controls Unresponsive</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Reboot Device</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PairingPopup</name>
<message>

@ -486,6 +486,29 @@
<translation> </translation>
</message>
</context>
<context>
<name>OnroadAlerts</name>
<message>
<source>openpilot Unavailable</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Waiting for controls to start</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>TAKE CONTROL IMMEDIATELY</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Controls Unresponsive</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Reboot Device</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PairingPopup</name>
<message>

@ -487,6 +487,29 @@
<translation> </translation>
</message>
</context>
<context>
<name>OnroadAlerts</name>
<message>
<source>openpilot Unavailable</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Waiting for controls to start</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>TAKE CONTROL IMMEDIATELY</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Controls Unresponsive</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Reboot Device</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PairingPopup</name>
<message>

@ -488,6 +488,29 @@
<translation> ALERTA</translation>
</message>
</context>
<context>
<name>OnroadAlerts</name>
<message>
<source>openpilot Unavailable</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Waiting for controls to start</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>TAKE CONTROL IMMEDIATELY</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Controls Unresponsive</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Reboot Device</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PairingPopup</name>
<message>

@ -487,6 +487,29 @@
<translation> </translation>
</message>
</context>
<context>
<name>OnroadAlerts</name>
<message>
<source>openpilot Unavailable</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Waiting for controls to start</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>TAKE CONTROL IMMEDIATELY</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Controls Unresponsive</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Reboot Device</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PairingPopup</name>
<message>

@ -486,6 +486,29 @@
<translation> UYARI</translation>
</message>
</context>
<context>
<name>OnroadAlerts</name>
<message>
<source>openpilot Unavailable</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Waiting for controls to start</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>TAKE CONTROL IMMEDIATELY</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Controls Unresponsive</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Reboot Device</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PairingPopup</name>
<message>

@ -487,6 +487,29 @@
<translation> </translation>
</message>
</context>
<context>
<name>OnroadAlerts</name>
<message>
<source>openpilot Unavailable</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Waiting for controls to start</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>TAKE CONTROL IMMEDIATELY</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Controls Unresponsive</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Reboot Device</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PairingPopup</name>
<message>

@ -487,6 +487,29 @@
<translation> </translation>
</message>
</context>
<context>
<name>OnroadAlerts</name>
<message>
<source>openpilot Unavailable</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Waiting for controls to start</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>TAKE CONTROL IMMEDIATELY</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Controls Unresponsive</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Reboot Device</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PairingPopup</name>
<message>

@ -1,6 +1,5 @@
#pragma once
#include <map>
#include <memory>
#include <string>
@ -22,7 +21,6 @@ const int UI_HEADER_HEIGHT = 420;
const int UI_FREQ = 20; // Hz
const int BACKLIGHT_OFFROAD = 50;
typedef cereal::CarControl::HUDControl::AudibleAlert AudibleAlert;
const float MIN_DRAW_DISTANCE = 10.0;
const float MAX_DRAW_DISTANCE = 100.0;
@ -47,59 +45,6 @@ constexpr vec3 default_face_kpts_3d[] = {
{18.02, -49.14, 8.00}, {6.36, -51.20, 8.00}, {-5.98, -51.20, 8.00},
};
struct Alert {
QString text1;
QString text2;
QString type;
cereal::ControlsState::AlertSize size;
cereal::ControlsState::AlertStatus status;
AudibleAlert sound;
bool equal(const Alert &a2) {
return text1 == a2.text1 && text2 == a2.text2 && type == a2.type && sound == a2.sound;
}
static Alert get(const SubMaster &sm, uint64_t started_frame) {
const cereal::ControlsState::Reader &cs = sm["controlsState"].getControlsState();
const uint64_t controls_frame = sm.rcv_frame("controlsState");
Alert alert = {};
if (controls_frame >= started_frame) { // Don't get old alert.
alert = {cs.getAlertText1().cStr(), cs.getAlertText2().cStr(),
cs.getAlertType().cStr(), cs.getAlertSize(),
cs.getAlertStatus(),
cs.getAlertSound()};
}
if (!sm.updated("controlsState") && (sm.frame - started_frame) > 5 * UI_FREQ) {
const int CONTROLS_TIMEOUT = 5;
const int controls_missing = (nanos_since_boot() - sm.rcv_time("controlsState")) / 1e9;
// Handle controls timeout
if (controls_frame < started_frame) {
// car is started, but controlsState hasn't been seen at all
alert = {"openpilot Unavailable", "Waiting for controls to start",
"controlsWaiting", cereal::ControlsState::AlertSize::MID,
cereal::ControlsState::AlertStatus::NORMAL,
AudibleAlert::NONE};
} else if (controls_missing > CONTROLS_TIMEOUT && !Hardware::PC()) {
// car is started, but controls is lagging or died
if (cs.getEnabled() && (controls_missing - CONTROLS_TIMEOUT) < 10) {
alert = {"TAKE CONTROL IMMEDIATELY", "Controls Unresponsive",
"controlsUnresponsive", cereal::ControlsState::AlertSize::FULL,
cereal::ControlsState::AlertStatus::CRITICAL,
AudibleAlert::WARNING_IMMEDIATE};
} else {
alert = {"Controls Unresponsive", "Reboot Device",
"controlsUnresponsivePermanent", cereal::ControlsState::AlertSize::MID,
cereal::ControlsState::AlertStatus::NORMAL,
AudibleAlert::NONE};
}
}
}
return alert;
}
};
typedef enum UIStatus {
STATUS_DISENGAGED,
@ -123,11 +68,6 @@ const QColor bg_colors [] = {
[STATUS_ENGAGED] = QColor(0x17, 0x86, 0x44, 0xf1),
};
static std::map<cereal::ControlsState::AlertStatus, QColor> alert_colors = {
{cereal::ControlsState::AlertStatus::NORMAL, QColor(0x15, 0x15, 0x15, 0xf1)},
{cereal::ControlsState::AlertStatus::USER_PROMPT, QColor(0xDA, 0x6F, 0x25, 0xf1)},
{cereal::ControlsState::AlertStatus::CRITICAL, QColor(0xC9, 0x22, 0x31, 0xf1)},
};
typedef struct UIScene {
bool calibration_valid = false;

Loading…
Cancel
Save