UI: add timeout to close settings window while onroad (#22980)

* refactor updateWakefulness

* don't hide sidebar

* rename reset->reset_timeout

* move related variables and functions into class Device

* reset timeout in ctor

* set timeout to 10s if ignition is on

* cleanup

* remove unused QTimer *timer

* check getTimestamp

* keep socket reading in update_state

* keep filtering

Co-authored-by: Willem Melching <willem.melching@gmail.com>
pull/23113/head
Dean Lee 4 years ago committed by GitHub
parent d4b8cba0f6
commit c5dbee4e58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      selfdrive/ui/qt/window.cc
  2. 42
      selfdrive/ui/ui.cc
  3. 12
      selfdrive/ui/ui.h

@ -37,17 +37,16 @@ MainWindow::MainWindow(QWidget *parent) : QWidget(parent) {
main_layout->setCurrentWidget(onboardingWindow);
}
device.setAwake(true, true);
QObject::connect(&qs, &QUIState::uiUpdate, &device, &Device::update);
QObject::connect(&qs, &QUIState::offroadTransition, [=](bool offroad) {
if (!offroad) {
closeSettings();
}
});
QObject::connect(&device, &Device::displayPowerChanged, [=]() {
if(main_layout->currentWidget() != onboardingWindow) {
closeSettings();
}
QObject::connect(&device, &Device::interactiveTimout, [=]() {
if (main_layout->currentWidget() == settingsWindow) {
closeSettings();
}
});
// load fonts
@ -86,9 +85,8 @@ void MainWindow::closeSettings() {
}
bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
// wake screen on tap
if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::TouchBegin) {
device.setAwake(true, true);
device.resetInteractiveTimout();
}
#ifdef QCOM

@ -251,6 +251,8 @@ void QUIState::update() {
}
Device::Device(QObject *parent) : brightness_filter(BACKLIGHT_OFFROAD, BACKLIGHT_TS, BACKLIGHT_DT), QObject(parent) {
setAwake(true);
resetInteractiveTimout();
}
void Device::update(const UIState &s) {
@ -261,17 +263,17 @@ void Device::update(const UIState &s) {
QUIState::ui_state.awake = awake;
}
void Device::setAwake(bool on, bool reset) {
void Device::setAwake(bool on) {
if (on != awake) {
awake = on;
Hardware::set_display_power(awake);
LOGD("setting display power %d", awake);
emit displayPowerChanged(awake);
}
}
if (reset) {
awake_timeout = 30 * UI_FREQ;
}
void Device::resetInteractiveTimout() {
interactive_timeout = (ignition_on ? 10 : 30) * UI_FREQ;
}
void Device::updateBrightness(const UIState &s) {
@ -302,18 +304,28 @@ void Device::updateBrightness(const UIState &s) {
last_brightness = brightness;
}
bool Device::motionTriggered(const UIState &s) {
static float accel_prev = 0;
static float gyro_prev = 0;
bool accel_trigger = abs(s.scene.accel_sensor - accel_prev) > 0.2;
bool gyro_trigger = abs(s.scene.gyro_sensor - gyro_prev) > 0.15;
gyro_prev = s.scene.gyro_sensor;
accel_prev = (accel_prev * (accel_samples - 1) + s.scene.accel_sensor) / accel_samples;
return (!awake && accel_trigger && gyro_trigger);
}
void Device::updateWakefulness(const UIState &s) {
awake_timeout = std::max(awake_timeout - 1, 0);
bool should_wake = s.scene.started || s.scene.ignition;
if (!should_wake) {
// tap detection while display is off
bool accel_trigger = abs(s.scene.accel_sensor - accel_prev) > 0.2;
bool gyro_trigger = abs(s.scene.gyro_sensor - gyro_prev) > 0.15;
should_wake = accel_trigger && gyro_trigger;
gyro_prev = s.scene.gyro_sensor;
accel_prev = (accel_prev * (accel_samples - 1) + s.scene.accel_sensor) / accel_samples;
bool ignition_just_turned_off = !s.scene.ignition && ignition_on;
ignition_on = s.scene.ignition;
if (ignition_just_turned_off || motionTriggered(s)) {
resetInteractiveTimout();
} else if (interactive_timeout > 0 && --interactive_timeout == 0) {
emit interactiveTimout();
}
setAwake(awake_timeout, should_wake);
setAwake(s.scene.ignition || interactive_timeout > 0);
}

@ -152,22 +152,22 @@ private:
const float accel_samples = 5*UI_FREQ;
bool awake = false;
int awake_timeout = 0;
float accel_prev = 0;
float gyro_prev = 0;
int interactive_timeout = 0;
bool ignition_on = false;
int last_brightness = 0;
FirstOrderFilter brightness_filter;
QTimer *timer;
void updateBrightness(const UIState &s);
void updateWakefulness(const UIState &s);
bool motionTriggered(const UIState &s);
void setAwake(bool on);
signals:
void displayPowerChanged(bool on);
void interactiveTimout();
public slots:
void setAwake(bool on, bool reset);
void resetInteractiveTimout();
void update(const UIState &s);
};

Loading…
Cancel
Save