TFT Screen/Backlight Sleep (#22617)

This commit is contained in:
Tanguy Pruvot
2021-09-14 04:07:08 +02:00
committed by Scott Lahteine
parent 033043218e
commit 224371dfc6
17 changed files with 176 additions and 25 deletions

View File

@@ -47,7 +47,10 @@ millis_t Touch::last_touch_ms = 0,
Touch::time_to_hold,
Touch::repeat_delay,
Touch::touch_time;
TouchControlType Touch::touch_control_type = NONE;
TouchControlType Touch::touch_control_type = NONE;
#if HAS_TOUCH_SLEEP
millis_t Touch::next_sleep_ms; // = 0
#endif
#if HAS_RESUME_CONTINUE
extern bool wait_for_user;
#endif
@@ -56,6 +59,7 @@ void Touch::init() {
TERN_(TOUCH_SCREEN_CALIBRATION, touch_calibration.calibration_reset());
reset();
io.Init();
TERN_(HAS_TOUCH_SLEEP, wakeUp());
enable();
}
@@ -271,9 +275,34 @@ bool Touch::get_point(int16_t *x, int16_t *y) {
#elif ENABLED(TFT_TOUCH_DEVICE_GT911)
bool is_touched = (TOUCH_ORIENTATION == TOUCH_PORTRAIT ? io.getPoint(y, x) : io.getPoint(x, y));
#endif
#if HAS_TOUCH_SLEEP
if (is_touched)
wakeUp();
else if (!isSleeping() && ELAPSED(millis(), next_sleep_ms) && ui.on_status_screen())
sleepTimeout();
#endif
return is_touched;
}
#if HAS_TOUCH_SLEEP
void Touch::sleepTimeout() {
#if PIN_EXISTS(TFT_BACKLIGHT)
OUT_WRITE(TFT_BACKLIGHT_PIN, LOW);
#endif
next_sleep_ms = TSLP_SLEEPING;
}
void Touch::wakeUp() {
if (isSleeping()) {
#if PIN_EXISTS(TFT_BACKLIGHT)
WRITE(TFT_BACKLIGHT_PIN, HIGH);
#endif
}
next_sleep_ms = millis() + SEC_TO_MS(TOUCH_IDLE_SLEEP);
}
#endif // HAS_TOUCH_SLEEP
Touch touch;
bool MarlinUI::touch_pressed() {