ui: singleton Device instance (#28908)

* singleton

* remove awake
This commit is contained in:
Shane Smiskol
2023-07-12 18:36:44 -07:00
committed by GitHub
parent d68bd905fc
commit b8dd4dcc28
5 changed files with 12 additions and 10 deletions
+1 -1
View File
@@ -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);
}
});
+3 -3
View File
@@ -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:
-2
View File
@@ -18,8 +18,6 @@ private:
void openSettings(int index = 0, const QString &param = "");
void closeSettings();
Device device;
QStackedLayout *main_layout;
HomeWindow *homeWindow;
SettingsWindow *settingsWindow;
+5 -3
View File
@@ -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;
}
+3 -1
View File
@@ -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,