return Alert

pull/22796/head
deanlee 4 years ago
parent 5da93228fd
commit 3fd007daf6
  1. 9
      selfdrive/ui/qt/onroad.cc
  2. 7
      selfdrive/ui/soundd/sound.cc
  3. 11
      selfdrive/ui/ui.h

@ -41,12 +41,11 @@ 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];
if (auto alert = Alert::get(*(s.sm), s.scene.started_frame)) { auto alert = Alert::get(*(s.sm), s.scene.started_frame);
if (alert->type == "controlsUnresponsive") { if (alert.type == "controlsUnresponsive") {
bgColor = bg_colors[STATUS_ALERT]; bgColor = bg_colors[STATUS_ALERT];
}
alerts->updateAlert(*alert, bgColor);
} }
alerts->updateAlert(alert, bgColor);
if (bg != bgColor) { if (bg != bgColor) {
// repaint border // repaint border
bg = bgColor; bg = bgColor;

@ -38,11 +38,8 @@ void Sound::update() {
} }
} }
if (auto alert = Alert::get(sm, 1)) { auto alert = Alert::get(sm, 1);
setAlert(alert->type, alert->sound); setAlert(alert.type, alert.sound);
} else {
setAlert({}, AudibleAlert::NONE);
}
} }
void Sound::setAlert(const QString &alert_type, AudibleAlert sound) { void Sound::setAlert(const QString &alert_type, AudibleAlert sound) {

@ -61,10 +61,11 @@ struct Alert {
return text1 == a2.text1 && text2 == a2.text2 && type == a2.type; return text1 == a2.text1 && text2 == a2.text2 && type == a2.type;
} }
static std::optional<Alert> get(const SubMaster &sm, uint64_t started_frame) { static Alert get(const SubMaster &sm, uint64_t started_frame) {
Alert alert{};
if (sm.updated("controlsState")) { if (sm.updated("controlsState")) {
const cereal::ControlsState::Reader &cs = sm["controlsState"].getControlsState(); const cereal::ControlsState::Reader &cs = sm["controlsState"].getControlsState();
return Alert{cs.getAlertText1().cStr(), cs.getAlertText2().cStr(), alert = {cs.getAlertText1().cStr(), cs.getAlertText2().cStr(),
cs.getAlertType().cStr(), cs.getAlertSize(), cs.getAlertType().cStr(), cs.getAlertSize(),
cs.getAlertSound()}; cs.getAlertSound()};
} else if ((sm.frame - started_frame) > 5 * UI_FREQ) { } else if ((sm.frame - started_frame) > 5 * UI_FREQ) {
@ -72,17 +73,17 @@ struct Alert {
// Handle controls timeout // Handle controls timeout
if (sm.rcv_frame("controlsState") < started_frame) { if (sm.rcv_frame("controlsState") < started_frame) {
// car is started, but controlsState hasn't been seen at all // car is started, but controlsState hasn't been seen at all
return Alert{"openpilot Unavailable", "Waiting for controls to start", alert = {"openpilot Unavailable", "Waiting for controls to start",
"controlsWaiting", cereal::ControlsState::AlertSize::MID, "controlsWaiting", cereal::ControlsState::AlertSize::MID,
AudibleAlert::NONE}; AudibleAlert::NONE};
} else if ((nanos_since_boot() - sm.rcv_time("controlsState")) / 1e9 > CONTROLS_TIMEOUT) { } else if ((nanos_since_boot() - sm.rcv_time("controlsState")) / 1e9 > CONTROLS_TIMEOUT) {
// car is started, but controls is lagging or died // car is started, but controls is lagging or died
return Alert{"TAKE CONTROL IMMEDIATELY", "Controls Unresponsive", alert = {"TAKE CONTROL IMMEDIATELY", "Controls Unresponsive",
"controlsUnresponsive", cereal::ControlsState::AlertSize::FULL, "controlsUnresponsive", cereal::ControlsState::AlertSize::FULL,
AudibleAlert::CHIME_WARNING_REPEAT}; AudibleAlert::CHIME_WARNING_REPEAT};
} }
} }
return std::nullopt; return alert;
} }
}; };

Loading…
Cancel
Save