✨ TFT Screen/Backlight Sleep (#22617)
This commit is contained in:
committed by
Scott Lahteine
parent
033043218e
commit
224371dfc6
@ -38,6 +38,10 @@
|
||||
#include "../tft_io/touch_calibration.h"
|
||||
#endif
|
||||
|
||||
#if HAS_TOUCH_SLEEP
|
||||
millis_t TouchButtons::next_sleep_ms;
|
||||
#endif
|
||||
|
||||
#include "../buttons.h" // For EN_C bit mask
|
||||
#include "../marlinui.h" // For ui.refresh
|
||||
#include "../tft_io/tft_io.h"
|
||||
@ -50,15 +54,24 @@
|
||||
#define BUTTON_AREA_TOP BUTTON_Y_LO
|
||||
#define BUTTON_AREA_BOT BUTTON_Y_HI
|
||||
|
||||
TouchButtons touch;
|
||||
TouchButtons touchBt;
|
||||
|
||||
void TouchButtons::init() { touchIO.Init(); }
|
||||
void TouchButtons::init() {
|
||||
touchIO.Init();
|
||||
TERN_(HAS_TOUCH_SLEEP, next_sleep_ms = millis() + SEC_TO_MS(TOUCH_IDLE_SLEEP));
|
||||
}
|
||||
|
||||
uint8_t TouchButtons::read_buttons() {
|
||||
#ifdef HAS_WIRED_LCD
|
||||
int16_t x, y;
|
||||
|
||||
const bool is_touched = (TERN(TOUCH_SCREEN_CALIBRATION, touch_calibration.calibration.orientation, TOUCH_ORIENTATION) == TOUCH_PORTRAIT ? touchIO.getRawPoint(&y, &x) : touchIO.getRawPoint(&x, &y));
|
||||
#if HAS_TOUCH_SLEEP
|
||||
if (is_touched)
|
||||
wakeUp();
|
||||
else if (!isSleeping() && ELAPSED(millis(), next_sleep_ms) && ui.on_status_screen())
|
||||
sleepTimeout();
|
||||
#endif
|
||||
if (!is_touched) return 0;
|
||||
|
||||
#if ENABLED(TOUCH_SCREEN_CALIBRATION)
|
||||
@ -96,4 +109,23 @@ uint8_t TouchButtons::read_buttons() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if HAS_TOUCH_SLEEP
|
||||
|
||||
void TouchButtons::sleepTimeout() {
|
||||
#if PIN_EXISTS(TFT_BACKLIGHT)
|
||||
OUT_WRITE(TFT_BACKLIGHT_PIN, LOW);
|
||||
#endif
|
||||
next_sleep_ms = TSLP_SLEEPING;
|
||||
}
|
||||
void TouchButtons::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
|
||||
|
||||
#endif // HAS_TOUCH_BUTTONS
|
||||
|
@ -50,10 +50,19 @@
|
||||
#define BUTTON_Y_HI (TFT_HEIGHT) - BUTTON_SPACING
|
||||
#define BUTTON_Y_LO BUTTON_Y_HI - BUTTON_HEIGHT
|
||||
|
||||
#define TSLP_PREINIT 0
|
||||
#define TSLP_SLEEPING 1
|
||||
|
||||
class TouchButtons {
|
||||
public:
|
||||
static void init();
|
||||
static uint8_t read_buttons();
|
||||
#if HAS_TOUCH_SLEEP
|
||||
static millis_t next_sleep_ms;
|
||||
static bool isSleeping() { return next_sleep_ms == TSLP_SLEEPING; }
|
||||
static void sleepTimeout();
|
||||
static void wakeUp();
|
||||
#endif
|
||||
};
|
||||
|
||||
extern TouchButtons touch;
|
||||
extern TouchButtons touchBt;
|
||||
|
Reference in New Issue
Block a user