diff --git a/selfdrive/ui/qt/window.cc b/selfdrive/ui/qt/window.cc index 36f12c266..d0806e437 100644 --- a/selfdrive/ui/qt/window.cc +++ b/selfdrive/ui/qt/window.cc @@ -92,6 +92,16 @@ bool MainWindow::eventFilter(QObject *obj, QEvent *event) { // ignore events when device is awakened by resetInteractiveTimeout ignore = !device()->isAwake(); device()->resetInteractiveTimeout(); + +#ifdef SUNNYPILOT + auto *s_sp = uiStateSP(); + bool onroadScreenControl = s_sp->scene.onroadScreenOffControl; + bool started = s_sp->scene.started; + bool timerExpired = (s_sp->scene.onroadScreenOffTimer == 0); + ignore |= (onroadScreenControl and started and timerExpired); + s_sp->reset_onroad_sleep_timer(); +#endif + break; } default: diff --git a/selfdrive/ui/qt/window.h b/selfdrive/ui/qt/window.h index 8a118b0bb..63293d417 100644 --- a/selfdrive/ui/qt/window.h +++ b/selfdrive/ui/qt/window.h @@ -7,6 +7,10 @@ #include "selfdrive/ui/qt/offroad/onboarding.h" #include "selfdrive/ui/qt/offroad/settings.h" +#ifdef SUNNYPILOT +#include "selfdrive/ui/sunnypilot/ui.h" +#endif + class MainWindow : public QWidget { Q_OBJECT diff --git a/selfdrive/ui/sunnypilot/qt/onroad/annotated_camera.cc b/selfdrive/ui/sunnypilot/qt/onroad/annotated_camera.cc index 1d5567161..f9b62b0ae 100644 --- a/selfdrive/ui/sunnypilot/qt/onroad/annotated_camera.cc +++ b/selfdrive/ui/sunnypilot/qt/onroad/annotated_camera.cc @@ -18,4 +18,10 @@ void AnnotatedCameraWidgetSP::updateState(const UIState &s) { void AnnotatedCameraWidgetSP::showEvent(QShowEvent *event) { AnnotatedCameraWidget::showEvent(event); ui_update_params_sp(uiState()); + uiStateSP()->reset_onroad_sleep_timer(OnroadTimerStatusToggle::RESUME); +} + +void AnnotatedCameraWidgetSP::hideEvent(QHideEvent *event) { + AnnotatedCameraWidget::hideEvent(event); + uiStateSP()->reset_onroad_sleep_timer(OnroadTimerStatusToggle::PAUSE); } diff --git a/selfdrive/ui/sunnypilot/qt/onroad/annotated_camera.h b/selfdrive/ui/sunnypilot/qt/onroad/annotated_camera.h index 8c0a38565..2e7609dae 100644 --- a/selfdrive/ui/sunnypilot/qt/onroad/annotated_camera.h +++ b/selfdrive/ui/sunnypilot/qt/onroad/annotated_camera.h @@ -18,4 +18,5 @@ public: protected: void showEvent(QShowEvent *event) override; + void hideEvent(QHideEvent* event) override; }; diff --git a/selfdrive/ui/sunnypilot/qt/onroad/onroad_home.cc b/selfdrive/ui/sunnypilot/qt/onroad/onroad_home.cc index 3f853e336..b26d1b828 100644 --- a/selfdrive/ui/sunnypilot/qt/onroad/onroad_home.cc +++ b/selfdrive/ui/sunnypilot/qt/onroad/onroad_home.cc @@ -25,10 +25,8 @@ void OnroadWindowSP::updateState(const UIStateSP &s) { void OnroadWindowSP::mousePressEvent(QMouseEvent *e) { OnroadWindow::mousePressEvent(e); - uiStateSP()->reset_onroad_sleep_timer(); } void OnroadWindowSP::offroadTransition(bool offroad) { OnroadWindow::offroadTransition(offroad); - uiStateSP()->reset_onroad_sleep_timer(); } diff --git a/selfdrive/ui/sunnypilot/ui.cc b/selfdrive/ui/sunnypilot/ui.cc index c021e0e95..2244e2319 100644 --- a/selfdrive/ui/sunnypilot/ui.cc +++ b/selfdrive/ui/sunnypilot/ui.cc @@ -71,17 +71,19 @@ void ui_update_params_sp(UIStateSP *s) { s->scene.onroadScreenOffBrightness = std::atoi(params.get("OnroadScreenOffBrightness").c_str()); s->scene.onroadScreenOffControl = params.getBool("OnroadScreenOffControl"); s->scene.onroadScreenOffTimerParam = std::atoi(params.get("OnroadScreenOffTimer").c_str()); - s->reset_onroad_sleep_timer(); s->scene.turn_signals = params.getBool("ShowTurnSignals"); } -void UIStateSP::reset_onroad_sleep_timer() { - if (scene.onroadScreenOffTimerParam >= 0 and scene.onroadScreenOffControl) { - scene.onroadScreenOffTimer = scene.onroadScreenOffTimerParam * UI_FREQ; - } else { +void UIStateSP::reset_onroad_sleep_timer(OnroadTimerStatusToggle toggleTimerStatus) { + // Toggling from active state to inactive + if (toggleTimerStatus == OnroadTimerStatusToggle::PAUSE and scene.onroadScreenOffTimer != -1) { scene.onroadScreenOffTimer = -1; } + // Toggling from a previously inactive state or resetting an active timer + else if ((scene.onroadScreenOffTimerParam >= 0 and scene.onroadScreenOffControl and scene.onroadScreenOffTimer != -1) or toggleTimerStatus == OnroadTimerStatusToggle::RESUME) { + scene.onroadScreenOffTimer = scene.onroadScreenOffTimerParam * UI_FREQ; + } } DeviceSP::DeviceSP(QObject *parent) : Device(parent) { diff --git a/selfdrive/ui/sunnypilot/ui.h b/selfdrive/ui/sunnypilot/ui.h index 55dd43ad5..ba5de83ef 100644 --- a/selfdrive/ui/sunnypilot/ui.h +++ b/selfdrive/ui/sunnypilot/ui.h @@ -15,6 +15,12 @@ #include "selfdrive/ui/ui.h" #include "selfdrive/ui/qt/util.h" +enum OnroadTimerStatusToggle { + NONE, + PAUSE, + RESUME +}; + class UIStateSP : public UIState { Q_OBJECT @@ -61,7 +67,7 @@ public: return user.user_id.toLower() != "unregisteredsponsor" && user.user_id.toLower() != "temporarysponsor"; }); } - void reset_onroad_sleep_timer(); + void reset_onroad_sleep_timer(OnroadTimerStatusToggle toggleTimerStatus = OnroadTimerStatusToggle::NONE); signals: void sunnylinkRoleChanged(bool subscriber);