ui: singleton Device instance (#28908)

* singleton

* remove awake
old-commit-hash: b8dd4dcc28
beeps
Shane Smiskol 2 years ago committed by GitHub
parent b9aa2c232f
commit 222f7f6727
  1. 2
      selfdrive/ui/qt/request_repeater.cc
  2. 6
      selfdrive/ui/qt/window.cc
  3. 2
      selfdrive/ui/qt/window.h
  4. 8
      selfdrive/ui/ui.cc
  5. 4
      selfdrive/ui/ui.h

@ -5,7 +5,7 @@ RequestRepeater::RequestRepeater(QObject *parent, const QString &requestURL, con
timer = new QTimer(this); timer = new QTimer(this);
timer->setTimerType(Qt::VeryCoarseTimer); timer->setTimerType(Qt::VeryCoarseTimer);
QObject::connect(timer, &QTimer::timeout, [=]() { 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); sendRequest(requestURL);
} }
}); });

@ -38,7 +38,7 @@ MainWindow::MainWindow(QWidget *parent) : QWidget(parent) {
closeSettings(); closeSettings();
} }
}); });
QObject::connect(&device, &Device::interactiveTimeout, [=]() { QObject::connect(device(), &Device::interactiveTimeout, [=]() {
if (main_layout->currentWidget() == settingsWindow) { if (main_layout->currentWidget() == settingsWindow) {
closeSettings(); closeSettings();
} }
@ -91,8 +91,8 @@ bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
case QEvent::MouseButtonPress: case QEvent::MouseButtonPress:
case QEvent::MouseMove: { case QEvent::MouseMove: {
// ignore events when device is awakened by resetInteractiveTimeout // ignore events when device is awakened by resetInteractiveTimeout
ignore = !uiState()->awake; ignore = !device()->isAwake();
device.resetInteractiveTimeout(); device()->resetInteractiveTimeout();
break; break;
} }
default: default:

@ -18,8 +18,6 @@ private:
void openSettings(int index = 0, const QString &param = ""); void openSettings(int index = 0, const QString &param = "");
void closeSettings(); void closeSettings();
Device device;
QStackedLayout *main_layout; QStackedLayout *main_layout;
HomeWindow *homeWindow; HomeWindow *homeWindow;
SettingsWindow *settingsWindow; SettingsWindow *settingsWindow;

@ -283,9 +283,6 @@ Device::Device(QObject *parent) : brightness_filter(BACKLIGHT_OFFROAD, BACKLIGHT
void Device::update(const UIState &s) { void Device::update(const UIState &s) {
updateBrightness(s); updateBrightness(s);
updateWakefulness(s); updateWakefulness(s);
// TODO: remove from UIState and use signals
uiState()->awake = awake;
} }
void Device::setAwake(bool on) { void Device::setAwake(bool on) {
@ -347,3 +344,8 @@ UIState *uiState() {
static UIState ui_state; static UIState ui_state;
return &ui_state; return &ui_state;
} }
Device *device() {
static Device _device;
return &_device;
}

@ -161,7 +161,6 @@ public:
UIStatus status; UIStatus status;
UIScene scene = {}; UIScene scene = {};
bool awake;
QString language; QString language;
QTransform car_space_transform; QTransform car_space_transform;
@ -188,6 +187,7 @@ class Device : public QObject {
public: public:
Device(QObject *parent = 0); Device(QObject *parent = 0);
bool isAwake() { return awake; }
private: private:
bool awake = false; bool awake = false;
@ -210,6 +210,8 @@ public slots:
void update(const UIState &s); void update(const UIState &s);
}; };
Device *device();
void ui_update_params(UIState *s); void ui_update_params(UIState *s);
int get_path_length_idx(const cereal::XYZTData::Reader &line, const float path_height); int get_path_length_idx(const cereal::XYZTData::Reader &line, const float path_height);
void update_model(UIState *s, void update_model(UIState *s,

Loading…
Cancel
Save