diff --git a/selfdrive/ui/qt/onroad.cc b/selfdrive/ui/qt/onroad.cc index 40ae436c65..5d562d6e23 100644 --- a/selfdrive/ui/qt/onroad.cc +++ b/selfdrive/ui/qt/onroad.cc @@ -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; diff --git a/selfdrive/ui/qt/onroad.h b/selfdrive/ui/qt/onroad.h index c72d1225e6..c2c2c326db 100644 --- a/selfdrive/ui/qt/onroad.h +++ b/selfdrive/ui/qt/onroad.h @@ -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 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 = {}; }; diff --git a/selfdrive/ui/translations/main_ar.ts b/selfdrive/ui/translations/main_ar.ts index 4f83dc18de..3acbba0c9d 100644 --- a/selfdrive/ui/translations/main_ar.ts +++ b/selfdrive/ui/translations/main_ar.ts @@ -492,6 +492,29 @@ تنبيه + + OnroadAlerts + + openpilot Unavailable + + + + Waiting for controls to start + + + + TAKE CONTROL IMMEDIATELY + + + + Controls Unresponsive + + + + Reboot Device + + + PairingPopup diff --git a/selfdrive/ui/translations/main_de.ts b/selfdrive/ui/translations/main_de.ts index b3fa645217..bc2d685c4d 100644 --- a/selfdrive/ui/translations/main_de.ts +++ b/selfdrive/ui/translations/main_de.ts @@ -487,6 +487,29 @@ HINWEIS + + OnroadAlerts + + openpilot Unavailable + + + + Waiting for controls to start + + + + TAKE CONTROL IMMEDIATELY + + + + Controls Unresponsive + + + + Reboot Device + + + PairingPopup diff --git a/selfdrive/ui/translations/main_fr.ts b/selfdrive/ui/translations/main_fr.ts index cc9c95acd4..55cb1b29aa 100644 --- a/selfdrive/ui/translations/main_fr.ts +++ b/selfdrive/ui/translations/main_fr.ts @@ -488,6 +488,29 @@ ALERTE + + OnroadAlerts + + openpilot Unavailable + + + + Waiting for controls to start + + + + TAKE CONTROL IMMEDIATELY + + + + Controls Unresponsive + + + + Reboot Device + + + PairingPopup diff --git a/selfdrive/ui/translations/main_ja.ts b/selfdrive/ui/translations/main_ja.ts index 13c2083bce..92238d6beb 100644 --- a/selfdrive/ui/translations/main_ja.ts +++ b/selfdrive/ui/translations/main_ja.ts @@ -486,6 +486,29 @@ 警告 + + OnroadAlerts + + openpilot Unavailable + + + + Waiting for controls to start + + + + TAKE CONTROL IMMEDIATELY + + + + Controls Unresponsive + + + + Reboot Device + + + PairingPopup diff --git a/selfdrive/ui/translations/main_ko.ts b/selfdrive/ui/translations/main_ko.ts index a3fd82f610..e2f4b4c7bb 100644 --- a/selfdrive/ui/translations/main_ko.ts +++ b/selfdrive/ui/translations/main_ko.ts @@ -487,6 +487,29 @@ 알림 + + OnroadAlerts + + openpilot Unavailable + + + + Waiting for controls to start + + + + TAKE CONTROL IMMEDIATELY + + + + Controls Unresponsive + + + + Reboot Device + + + PairingPopup diff --git a/selfdrive/ui/translations/main_pt-BR.ts b/selfdrive/ui/translations/main_pt-BR.ts index 27231a9dc4..e5a0c23f40 100644 --- a/selfdrive/ui/translations/main_pt-BR.ts +++ b/selfdrive/ui/translations/main_pt-BR.ts @@ -488,6 +488,29 @@ ALERTA + + OnroadAlerts + + openpilot Unavailable + + + + Waiting for controls to start + + + + TAKE CONTROL IMMEDIATELY + + + + Controls Unresponsive + + + + Reboot Device + + + PairingPopup diff --git a/selfdrive/ui/translations/main_th.ts b/selfdrive/ui/translations/main_th.ts index 1451e3b419..14fb40d21f 100644 --- a/selfdrive/ui/translations/main_th.ts +++ b/selfdrive/ui/translations/main_th.ts @@ -487,6 +487,29 @@ การแจ้งเตือน + + OnroadAlerts + + openpilot Unavailable + + + + Waiting for controls to start + + + + TAKE CONTROL IMMEDIATELY + + + + Controls Unresponsive + + + + Reboot Device + + + PairingPopup diff --git a/selfdrive/ui/translations/main_tr.ts b/selfdrive/ui/translations/main_tr.ts index cb20532b47..9fce4793ca 100644 --- a/selfdrive/ui/translations/main_tr.ts +++ b/selfdrive/ui/translations/main_tr.ts @@ -486,6 +486,29 @@ UYARI + + OnroadAlerts + + openpilot Unavailable + + + + Waiting for controls to start + + + + TAKE CONTROL IMMEDIATELY + + + + Controls Unresponsive + + + + Reboot Device + + + PairingPopup diff --git a/selfdrive/ui/translations/main_zh-CHS.ts b/selfdrive/ui/translations/main_zh-CHS.ts index 5625c73b97..6b040dac26 100644 --- a/selfdrive/ui/translations/main_zh-CHS.ts +++ b/selfdrive/ui/translations/main_zh-CHS.ts @@ -487,6 +487,29 @@ 警报 + + OnroadAlerts + + openpilot Unavailable + + + + Waiting for controls to start + + + + TAKE CONTROL IMMEDIATELY + + + + Controls Unresponsive + + + + Reboot Device + + + PairingPopup diff --git a/selfdrive/ui/translations/main_zh-CHT.ts b/selfdrive/ui/translations/main_zh-CHT.ts index b5e36620ab..dd3f600254 100644 --- a/selfdrive/ui/translations/main_zh-CHT.ts +++ b/selfdrive/ui/translations/main_zh-CHT.ts @@ -487,6 +487,29 @@ 提醒 + + OnroadAlerts + + openpilot Unavailable + + + + Waiting for controls to start + + + + TAKE CONTROL IMMEDIATELY + + + + Controls Unresponsive + + + + Reboot Device + + + PairingPopup diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 6efb72af9a..d639d85eeb 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -1,6 +1,5 @@ #pragma once -#include #include #include @@ -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 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;