improved handle_display_state (#19574)
parent
81369a65bb
commit
e032c31069
|
@ -30,27 +30,27 @@ static void ui_set_brightness(UIState *s, int brightness) {
|
|||
}
|
||||
|
||||
static void handle_display_state(UIState *s, bool user_input) {
|
||||
|
||||
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;
|
||||
constexpr float accel_samples = 5*UI_FREQ;
|
||||
static float accel_prev = 0., gyro_prev = 0.;
|
||||
|
||||
bool accel_trigger = abs(s->accel_sensor - accel_prev) > 0.2;
|
||||
bool gyro_trigger = abs(s->gyro_sensor - gyro_prev) > 0.15;
|
||||
user_input = user_input || (accel_trigger && gyro_trigger);
|
||||
gyro_prev = s->gyro_sensor;
|
||||
accel_prev = (accel_prev*(accel_samples - 1) + s->accel_sensor) / accel_samples;
|
||||
bool should_wake = s->started || s->ignition || user_input;
|
||||
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
|
||||
bool should_wake = s->awake;
|
||||
if (user_input || s->ignition || s->started) {
|
||||
should_wake = true;
|
||||
if (should_wake) {
|
||||
awake_timeout = 30*UI_FREQ;
|
||||
} else if (awake_timeout == 0){
|
||||
should_wake = false;
|
||||
} else if (awake_timeout > 0){
|
||||
--awake_timeout;
|
||||
should_wake = true;
|
||||
}
|
||||
|
||||
// handle state transition
|
||||
|
|
Loading…
Reference in New Issue