🚸 COLOR_UI sleep timeout / setting (#24994)

This commit is contained in:
Tanguy Pruvot
2022-11-26 08:23:24 +01:00
committed by Scott Lahteine
parent b8ba9d60bb
commit b9bed1ca69
5 changed files with 31 additions and 21 deletions

View File

@ -43,7 +43,7 @@ int16_t Touch::x, Touch::y;
touch_control_t Touch::controls[];
touch_control_t *Touch::current_control;
uint16_t Touch::controls_count;
millis_t Touch::last_touch_ms = 0,
millis_t Touch::next_touch_ms = 0,
Touch::time_to_hold,
Touch::repeat_delay,
Touch::touch_time;
@ -83,8 +83,8 @@ void Touch::idle() {
// Return if Touch::idle is called within the same millisecond
const millis_t now = millis();
if (last_touch_ms == now) return;
last_touch_ms = now;
if (now <= next_touch_ms) return;
next_touch_ms = now;
if (get_point(&_x, &_y)) {
#if HAS_RESUME_CONTINUE
@ -97,18 +97,18 @@ void Touch::idle() {
}
#endif
ui.reset_status_timeout(last_touch_ms);
ui.reset_status_timeout(now);
if (touch_time) {
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
if (touch_control_type == NONE && ELAPSED(last_touch_ms, touch_time + TOUCH_SCREEN_HOLD_TO_CALIBRATE_MS) && ui.on_status_screen())
if (touch_control_type == NONE && ELAPSED(now, touch_time + TOUCH_SCREEN_HOLD_TO_CALIBRATE_MS) && ui.on_status_screen())
ui.goto_screen(touch_screen_calibration);
#endif
return;
}
if (time_to_hold == 0) time_to_hold = last_touch_ms + MINIMUM_HOLD_TIME;
if (PENDING(last_touch_ms, time_to_hold)) return;
if (time_to_hold == 0) time_to_hold = now + MINIMUM_HOLD_TIME;
if (PENDING(now, time_to_hold)) return;
if (x != 0 && y != 0) {
if (current_control) {
@ -133,7 +133,7 @@ void Touch::idle() {
}
if (!current_control)
touch_time = last_touch_ms;
touch_time = now;
}
x = _x;
y = _y;
@ -252,8 +252,8 @@ void Touch::touch(touch_control_t *control) {
void Touch::hold(touch_control_t *control, millis_t delay) {
current_control = control;
if (delay) {
repeat_delay = delay > MIN_REPEAT_DELAY ? delay : MIN_REPEAT_DELAY;
time_to_hold = last_touch_ms + repeat_delay;
repeat_delay = _MAX(delay, MIN_REPEAT_DELAY);
time_to_hold = next_touch_ms + repeat_delay;
}
ui.refresh();
}
@ -301,6 +301,8 @@ bool Touch::get_point(int16_t *x, int16_t *y) {
#elif PIN_EXISTS(TFT_BACKLIGHT)
WRITE(TFT_BACKLIGHT_PIN, HIGH);
#endif
next_touch_ms = millis() + 100;
safe_delay(20);
}
next_sleep_ms = millis() + SEC_TO_MS(ui.sleep_timeout_minutes * 60);
}

View File

@ -103,7 +103,7 @@ class Touch {
static touch_control_t *current_control;
static uint16_t controls_count;
static millis_t last_touch_ms, time_to_hold, repeat_delay, touch_time;
static millis_t next_touch_ms, time_to_hold, repeat_delay, touch_time;
static TouchControlType touch_control_type;
static bool get_point(int16_t *x, int16_t *y);