    last_brightness = brightness;
  }
  
  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;
    }
  
    setAwake(awake_timeout, should_wake);
  }
 
</s> remove   setAwake(awake_timeout, should_wake);
 </s> add   setAwake(s.scene.ignition || interactive_timeout > 0); </s> remove   if (reset) {
    awake_timeout = 30 * UI_FREQ;
  }
 </s> add void Device::resetInteractiveTimout() {
  interactive_timeout = (ignition_on ? 10 : 30) * UI_FREQ; </s> remove   int awake_timeout = 0;
  float accel_prev = 0;
  float gyro_prev = 0;
 </s> add   int interactive_timeout = 0;
  bool ignition_on = false; </s> remove void Device::setAwake(bool on, bool reset) {
 </s> add void Device::setAwake(bool on) {
  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();
    last_brightness = brightness;
  }
  
  void Device::updateWakefulness(const UIState &s) {
  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();
  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();
  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();
  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();
  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();
  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();
  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();
  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();
  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();
  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);
  }
keep keep keep keep replace replace replace replace replace replace replace replace replace replace keep keep keep keep
  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> 
selfdrive/ui/ui.cc