diff --git a/selfdrive/ui/qt/ui.cc b/selfdrive/ui/qt/ui.cc index aece1742ab..de4f6950ee 100644 --- a/selfdrive/ui/qt/ui.cc +++ b/selfdrive/ui/qt/ui.cc @@ -25,6 +25,8 @@ int main(int argc, char *argv[]) { w.setFixedSize(vwp_w, vwp_h); w.show(); + a.installEventFilter(&w); + #ifdef QCOM2 QPlatformNativeInterface *native = QGuiApplication::platformNativeInterface(); wl_surface *s = reinterpret_cast(native->nativeResourceForWindow("surface", w.windowHandle())); diff --git a/selfdrive/ui/qt/window.cc b/selfdrive/ui/qt/window.cc index 7810f27864..3aa0de55af 100644 --- a/selfdrive/ui/qt/window.cc +++ b/selfdrive/ui/qt/window.cc @@ -10,8 +10,6 @@ #include #include "window.hpp" -#include "offroad/settings.hpp" -#include "offroad/onboarding.hpp" #include "paint.hpp" #include "common/util.h" @@ -22,6 +20,18 @@ volatile sig_atomic_t do_exit = 0; +static void handle_display_state(UIState *s, int dt, bool user_input) { + static int awake_timeout = 0; + awake_timeout = std::max(awake_timeout-dt, 0); + + if (user_input || s->ignition || s->started) { + s->awake = true; + awake_timeout = 30*UI_FREQ; + } else if (awake_timeout == 0){ + s->awake = false; + } +} + static void set_backlight(int brightness){ std::ofstream brightness_control("/sys/class/backlight/panel0-backlight/brightness"); if (brightness_control.is_open()){ @@ -37,13 +47,13 @@ MainWindow::MainWindow(QWidget *parent) : QWidget(parent) { set_core_affinity(7); #endif - GLWindow *glWindow = new GLWindow(this); + glWindow = new GLWindow(this); main_layout->addWidget(glWindow); - SettingsWindow *settingsWindow = new SettingsWindow(this); + settingsWindow = new SettingsWindow(this); main_layout->addWidget(settingsWindow); - OnboardingWindow *onboardingWindow = new OnboardingWindow(this); + onboardingWindow = new OnboardingWindow(this); main_layout->addWidget(onboardingWindow); main_layout->setMargin(0); @@ -56,6 +66,7 @@ MainWindow::MainWindow(QWidget *parent) : QWidget(parent) { QObject::connect(onboardingWindow, SIGNAL(onboardingDone()), this, SLOT(closeSettings())); onboardingWindow->updateActiveScreen(); + setStyleSheet(R"( * { color: white; @@ -73,6 +84,14 @@ void MainWindow::closeSettings() { } +bool MainWindow::eventFilter(QObject *obj, QEvent *event){ + if (event->type() == QEvent::MouseButtonPress) { + glWindow->wake(); + } + return false; +} + + GLWindow::GLWindow(QWidget *parent) : QOpenGLWidget(parent) { timer = new QTimer(this); QObject::connect(timer, SIGNAL(timeout()), this, SLOT(timerUpdate())); @@ -107,6 +126,8 @@ void GLWindow::initializeGL() { ui_state->fb_h = vwp_h; ui_init(ui_state); + wake(); + timer->start(0); backlight_timer->start(BACKLIGHT_DT * 100); } @@ -119,11 +140,9 @@ void GLWindow::backlightUpdate(){ smooth_brightness = clipped_brightness * k + smooth_brightness * (1.0f - k); int brightness = smooth_brightness; -#ifdef QCOM2 - if (!ui_state->started){ - brightness = 150; + if (!ui_state->awake){ + brightness = 0; } -#endif std::thread{set_backlight, brightness}.detach(); } @@ -136,6 +155,10 @@ void GLWindow::timerUpdate(){ } #endif + // Fix awake timeout if running 1 Hz when offroad + int dt = timer->interval() == 0 ? 1 : 20; + handle_display_state(ui_state, dt, false); + ui_update(ui_state); repaint(); } @@ -148,7 +171,13 @@ void GLWindow::paintGL() { ui_draw(ui_state); } +void GLWindow::wake(){ + handle_display_state(ui_state, 1, true); +} + void GLWindow::mousePressEvent(QMouseEvent *e) { + wake(); + // Settings button click if (!ui_state->scene.uilayout_sidebarcollapsed && settings_btn.ptInRect(e->x(), e->y())) { emit openSettings(); diff --git a/selfdrive/ui/qt/window.hpp b/selfdrive/ui/qt/window.hpp index f98973ec55..fa68cec1d0 100644 --- a/selfdrive/ui/qt/window.hpp +++ b/selfdrive/ui/qt/window.hpp @@ -8,20 +8,8 @@ #include "qt/qt_sound.hpp" #include "ui/ui.hpp" - -class MainWindow : public QWidget { - Q_OBJECT - -public: - explicit MainWindow(QWidget *parent = 0); - -private: - QStackedLayout *main_layout; - -public slots: - void openSettings(); - void closeSettings(); -}; +#include "offroad/settings.hpp" +#include "offroad/onboarding.hpp" #ifdef QCOM2 const int vwp_w = 2160; @@ -30,12 +18,14 @@ const int vwp_w = 1920; #endif const int vwp_h = 1080; + class GLWindow : public QOpenGLWidget, protected QOpenGLFunctions { Q_OBJECT public: using QOpenGLWidget::QOpenGLWidget; explicit GLWindow(QWidget *parent = 0); + void wake(); ~GLWindow(); protected: @@ -65,3 +55,23 @@ public slots: signals: void openSettings(); }; + +class MainWindow : public QWidget { + Q_OBJECT + +protected: + bool eventFilter(QObject *obj, QEvent *event) override; + +public: + explicit MainWindow(QWidget *parent = 0); + +private: + QStackedLayout *main_layout; + GLWindow *glWindow; + SettingsWindow *settingsWindow; + OnboardingWindow *onboardingWindow; + +public slots: + void openSettings(); + void closeSettings(); +};