improved handle_display_state (#19574)

old-commit-hash: e032c31069
commatwo_master
Dean Lee 4 years ago committed by GitHub
parent d731984ad9
commit c9db9b1fb4
  1. 32
      selfdrive/ui/android/ui.cc

@ -30,27 +30,27 @@ static void ui_set_brightness(UIState *s, int brightness) {
} }
static void handle_display_state(UIState *s, bool user_input) { static void handle_display_state(UIState *s, bool user_input) {
static int awake_timeout = 0; static int awake_timeout = 0;
awake_timeout = std::max(awake_timeout-1, 0);
// tap detection while display is off
const float accel_samples = 5*UI_FREQ;
static float accel_prev, gyro_prev = 0;
bool accel_trigger = abs(s->accel_sensor - accel_prev) > 0.2; constexpr float accel_samples = 5*UI_FREQ;
bool gyro_trigger = abs(s->gyro_sensor - gyro_prev) > 0.15; static float accel_prev = 0., gyro_prev = 0.;
user_input = user_input || (accel_trigger && gyro_trigger);
gyro_prev = s->gyro_sensor; bool should_wake = s->started || s->ignition || user_input;
accel_prev = (accel_prev*(accel_samples - 1) + s->accel_sensor) / accel_samples; if (!should_wake) {
// tap detection while display is off
bool accel_trigger = abs(s->accel_sensor - accel_prev) > 0.2;
bool gyro_trigger = abs(s->gyro_sensor - gyro_prev) > 0.15;
should_wake = accel_trigger && gyro_trigger;
gyro_prev = s->gyro_sensor;
accel_prev = (accel_prev * (accel_samples - 1) + s->accel_sensor) / accel_samples;
}
// determine desired state // determine desired state
bool should_wake = s->awake; if (should_wake) {
if (user_input || s->ignition || s->started) {
should_wake = true;
awake_timeout = 30*UI_FREQ; awake_timeout = 30*UI_FREQ;
} else if (awake_timeout == 0){ } else if (awake_timeout > 0){
should_wake = false; --awake_timeout;
should_wake = true;
} }
// handle state transition // handle state transition

Loading…
Cancel
Save