static Alert::get

pull/22796/head
deanlee 4 years ago
parent e2b4233adf
commit 6dfdd4102f
  1. 3
      selfdrive/ui/qt/onroad.cc
  2. 6
      selfdrive/ui/soundd.cc
  3. 59
      selfdrive/ui/ui.h

@ -41,8 +41,7 @@ OnroadWindow::OnroadWindow(QWidget *parent) : QWidget(parent) {
void OnroadWindow::updateState(const UIState &s) { void OnroadWindow::updateState(const UIState &s) {
QColor bgColor = bg_colors[s.status]; QColor bgColor = bg_colors[s.status];
auto alert = get_alert(*(s.sm), s.scene.started_frame); if (auto alert = Alert::get(*(s.sm), s.scene.started_frame)) {
if (alert) {
if (alert->type == "controlsUnresponsive") { if (alert->type == "controlsUnresponsive") {
bgColor = bg_colors[STATUS_ALERT]; bgColor = bg_colors[STATUS_ALERT];
} }

@ -62,12 +62,10 @@ public:
} }
} }
auto alert = get_alert(sm, 1); if (auto alert = Alert::get(sm, 1)) {
if (alert) {
setAlert(alert->type, alert->sound); setAlert(alert->type, alert->sound);
} else { } else {
// stop alert. setAlert({}, AudibleAlert::NONE);
setAlert("", AudibleAlert::NONE);
} }
} }

@ -27,6 +27,10 @@
#define COLOR_YELLOW nvgRGBA(218, 202, 37, 255) #define COLOR_YELLOW nvgRGBA(218, 202, 37, 255)
#define COLOR_RED nvgRGBA(201, 34, 49, 255) #define COLOR_RED nvgRGBA(201, 34, 49, 255)
const int bdr_s = 30;
const int header_h = 420;
const int footer_h = 280;
const int UI_FREQ = 20; // Hz const int UI_FREQ = 20; // Hz
typedef cereal::CarControl::HUDControl::AudibleAlert AudibleAlert; typedef cereal::CarControl::HUDControl::AudibleAlert AudibleAlert;
@ -47,7 +51,7 @@ typedef struct Rect {
} }
} Rect; } Rect;
typedef struct Alert { struct Alert {
QString text1; QString text1;
QString text2; QString text2;
QString type; QString type;
@ -56,38 +60,31 @@ typedef struct Alert {
bool equal(const Alert &a2) { bool equal(const Alert &a2) {
return text1 == a2.text1 && text2 == a2.text2 && type == a2.type; return text1 == a2.text1 && text2 == a2.text2 && type == a2.type;
} }
} Alert;
static std::optional<Alert> get(const SubMaster &sm, uint64_t started_frame) {
const Alert CONTROLS_WAITING_ALERT = {"openpilot Unavailable", "Waiting for controls to start", if (sm.updated("controlsState")) {
"controlsWaiting", cereal::ControlsState::AlertSize::MID, const cereal::ControlsState::Reader &cs = sm["controlsState"].getControlsState();
AudibleAlert::NONE}; return Alert{cs.getAlertText1().cStr(), cs.getAlertText2().cStr(),
cs.getAlertType().cStr(), cs.getAlertSize(),
const Alert CONTROLS_UNRESPONSIVE_ALERT = {"TAKE CONTROL IMMEDIATELY", "Controls Unresponsive", cs.getAlertSound()};
"controlsUnresponsive", cereal::ControlsState::AlertSize::FULL, } else if ((sm.frame - started_frame) > 5 * UI_FREQ) {
AudibleAlert::CHIME_WARNING_REPEAT}; const int CONTROLS_TIMEOUT = 5;
inline std::optional<Alert> get_alert(const SubMaster &sm, uint64_t started_frame) { // Handle controls timeout
const int CONTROLS_TIMEOUT = 5; if (sm.rcv_frame("controlsState") < started_frame) {
// car is started, but controlsState hasn't been seen at all
if (sm.updated("controlsState")) { return Alert{"openpilot Unavailable", "Waiting for controls to start",
const cereal::ControlsState::Reader &cs = sm["controlsState"].getControlsState(); "controlsWaiting", cereal::ControlsState::AlertSize::MID,
return Alert{cs.getAlertText1().cStr(), cs.getAlertText2().cStr(), cs.getAlertType().cStr(), AudibleAlert::NONE};
cs.getAlertSize(), cs.getAlertSound()}; } else if ((nanos_since_boot() - sm.rcv_time("controlsState")) / 1e9 > CONTROLS_TIMEOUT) {
} else if ((sm.frame - started_frame) > 5 * UI_FREQ) { // car is started, but controls is lagging or died
// Handle controls timeout return Alert{"TAKE CONTROL IMMEDIATELY", "Controls Unresponsive",
if (sm.rcv_frame("controlsState") < started_frame) { "controlsUnresponsive", cereal::ControlsState::AlertSize::FULL,
// car is started, but controlsState hasn't been seen at all AudibleAlert::CHIME_WARNING_REPEAT};
return CONTROLS_WAITING_ALERT; }
} else if ((nanos_since_boot() - sm.rcv_time("controlsState")) / 1e9 > CONTROLS_TIMEOUT) {
// car is started, but controls is lagging or died
return CONTROLS_UNRESPONSIVE_ALERT;
} }
return std::nullopt;
} }
return std::nullopt; };
}
const int bdr_s = 30;
const int header_h = 420;
const int footer_h = 280;
typedef enum UIStatus { typedef enum UIStatus {
STATUS_DISENGAGED, STATUS_DISENGAGED,

Loading…
Cancel
Save