From 222f7f6727ee4914b61843026d71ce96f2f8de6a Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Wed, 12 Jul 2023 18:36:44 -0700 Subject: [PATCH] ui: singleton Device instance (#28908) * singleton * remove awake old-commit-hash: b8dd4dcc288361f51f7664ef82055bfb47d83513 --- selfdrive/ui/qt/request_repeater.cc | 2 +- selfdrive/ui/qt/window.cc | 6 +++--- selfdrive/ui/qt/window.h | 2 -- selfdrive/ui/ui.cc | 8 +++++--- selfdrive/ui/ui.h | 4 +++- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/selfdrive/ui/qt/request_repeater.cc b/selfdrive/ui/qt/request_repeater.cc index fa37c015f7..7aa731898c 100644 --- a/selfdrive/ui/qt/request_repeater.cc +++ b/selfdrive/ui/qt/request_repeater.cc @@ -5,7 +5,7 @@ RequestRepeater::RequestRepeater(QObject *parent, const QString &requestURL, con timer = new QTimer(this); timer->setTimerType(Qt::VeryCoarseTimer); QObject::connect(timer, &QTimer::timeout, [=]() { - if ((!uiState()->scene.started || while_onroad) && uiState()->awake && !active()) { + if ((!uiState()->scene.started || while_onroad) && device()->isAwake() && !active()) { sendRequest(requestURL); } }); diff --git a/selfdrive/ui/qt/window.cc b/selfdrive/ui/qt/window.cc index e8714ff344..74fd05ed7b 100644 --- a/selfdrive/ui/qt/window.cc +++ b/selfdrive/ui/qt/window.cc @@ -38,7 +38,7 @@ MainWindow::MainWindow(QWidget *parent) : QWidget(parent) { closeSettings(); } }); - QObject::connect(&device, &Device::interactiveTimeout, [=]() { + QObject::connect(device(), &Device::interactiveTimeout, [=]() { if (main_layout->currentWidget() == settingsWindow) { closeSettings(); } @@ -91,8 +91,8 @@ bool MainWindow::eventFilter(QObject *obj, QEvent *event) { case QEvent::MouseButtonPress: case QEvent::MouseMove: { // ignore events when device is awakened by resetInteractiveTimeout - ignore = !uiState()->awake; - device.resetInteractiveTimeout(); + ignore = !device()->isAwake(); + device()->resetInteractiveTimeout(); break; } default: diff --git a/selfdrive/ui/qt/window.h b/selfdrive/ui/qt/window.h index 71fc466c20..05b61e1f76 100644 --- a/selfdrive/ui/qt/window.h +++ b/selfdrive/ui/qt/window.h @@ -18,8 +18,6 @@ private: void openSettings(int index = 0, const QString ¶m = ""); void closeSettings(); - Device device; - QStackedLayout *main_layout; HomeWindow *homeWindow; SettingsWindow *settingsWindow; diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index e9e5675e04..f978df852d 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -283,9 +283,6 @@ Device::Device(QObject *parent) : brightness_filter(BACKLIGHT_OFFROAD, BACKLIGHT void Device::update(const UIState &s) { updateBrightness(s); updateWakefulness(s); - - // TODO: remove from UIState and use signals - uiState()->awake = awake; } void Device::setAwake(bool on) { @@ -347,3 +344,8 @@ UIState *uiState() { static UIState ui_state; return &ui_state; } + +Device *device() { + static Device _device; + return &_device; +} diff --git a/selfdrive/ui/ui.h b/selfdrive/ui/ui.h index 3f11b1bcbf..a97ef35789 100644 --- a/selfdrive/ui/ui.h +++ b/selfdrive/ui/ui.h @@ -161,7 +161,6 @@ public: UIStatus status; UIScene scene = {}; - bool awake; QString language; QTransform car_space_transform; @@ -188,6 +187,7 @@ class Device : public QObject { public: Device(QObject *parent = 0); + bool isAwake() { return awake; } private: bool awake = false; @@ -210,6 +210,8 @@ public slots: void update(const UIState &s); }; +Device *device(); + void ui_update_params(UIState *s); int get_path_length_idx(const cereal::XYZTData::Reader &line, const float path_height); void update_model(UIState *s,