✨ TFT Screen/Backlight Sleep (#22617)
This commit is contained in:
committed by
Scott Lahteine
parent
033043218e
commit
224371dfc6
@ -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() {
|
||||
|
@ -90,6 +90,9 @@ typedef struct __attribute__((__packed__)) {
|
||||
#define UBL_REPEAT_DELAY 125
|
||||
#define FREE_MOVE_RANGE 32
|
||||
|
||||
#define TSLP_PREINIT 0
|
||||
#define TSLP_SLEEPING 1
|
||||
|
||||
class Touch {
|
||||
private:
|
||||
static TOUCH_DRIVER_CLASS io;
|
||||
@ -121,7 +124,12 @@ class Touch {
|
||||
}
|
||||
static void disable() { enabled = false; }
|
||||
static void enable() { enabled = true; }
|
||||
|
||||
#if HAS_TOUCH_SLEEP
|
||||
static millis_t next_sleep_ms;
|
||||
static inline bool isSleeping() { return next_sleep_ms == TSLP_SLEEPING; }
|
||||
static void sleepTimeout();
|
||||
static void wakeUp();
|
||||
#endif
|
||||
static void add_control(TouchControlType type, uint16_t x, uint16_t y, uint16_t width, uint16_t height, intptr_t data = 0);
|
||||
};
|
||||
|
||||
|
@ -47,6 +47,7 @@
|
||||
|
||||
void MarlinUI::tft_idle() {
|
||||
#if ENABLED(TOUCH_SCREEN)
|
||||
if (TERN0(HAS_TOUCH_SLEEP, lcd_sleep_task())) return;
|
||||
if (draw_menu_navigation) {
|
||||
add_control(164, TFT_HEIGHT - 50, PAGE_UP, imgPageUp, encoderTopLine > 0);
|
||||
add_control(796, TFT_HEIGHT - 50, PAGE_DOWN, imgPageDown, encoderTopLine + LCD_HEIGHT < screen_items);
|
||||
|
@ -47,6 +47,7 @@
|
||||
|
||||
void MarlinUI::tft_idle() {
|
||||
#if ENABLED(TOUCH_SCREEN)
|
||||
if (TERN0(HAS_TOUCH_SLEEP, lcd_sleep_task())) return;
|
||||
if (draw_menu_navigation) {
|
||||
add_control(48, 206, PAGE_UP, imgPageUp, encoderTopLine > 0);
|
||||
add_control(240, 206, PAGE_DOWN, imgPageDown, encoderTopLine + LCD_HEIGHT < screen_items);
|
||||
|
@ -47,6 +47,7 @@
|
||||
|
||||
void MarlinUI::tft_idle() {
|
||||
#if ENABLED(TOUCH_SCREEN)
|
||||
if (TERN0(HAS_TOUCH_SLEEP, lcd_sleep_task())) return;
|
||||
if (draw_menu_navigation) {
|
||||
add_control(104, TFT_HEIGHT - 34, PAGE_UP, imgPageUp, encoderTopLine > 0);
|
||||
add_control(344, TFT_HEIGHT - 34, PAGE_DOWN, imgPageDown, encoderTopLine + LCD_HEIGHT < screen_items);
|
||||
|
@ -37,6 +37,27 @@ static xy_uint_t cursor;
|
||||
bool draw_menu_navigation = false;
|
||||
#endif
|
||||
|
||||
#if HAS_TOUCH_SLEEP
|
||||
|
||||
bool lcd_sleep_task() {
|
||||
static bool sleepCleared;
|
||||
if (touch.isSleeping()) {
|
||||
tft.queue.reset();
|
||||
if (!sleepCleared) {
|
||||
sleepCleared = true;
|
||||
ui.clear_lcd();
|
||||
tft.queue.async();
|
||||
}
|
||||
touch.idle();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
sleepCleared = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void menu_line(const uint8_t row, uint16_t color) {
|
||||
cursor.set(0, row);
|
||||
tft.canvas(0, TFT_TOP_LINE_Y + cursor.y * MENU_LINE_HEIGHT, TFT_WIDTH, MENU_ITEM_HEIGHT);
|
||||
|
@ -51,6 +51,10 @@ void draw_fan_status(uint16_t x, uint16_t y, const bool blink);
|
||||
void menu_line(const uint8_t row, uint16_t color=COLOR_BACKGROUND);
|
||||
void menu_item(const uint8_t row, bool sel = false);
|
||||
|
||||
#if HAS_TOUCH_SLEEP
|
||||
bool lcd_sleep_task();
|
||||
#endif
|
||||
|
||||
#define ABSOLUTE_ZERO -273.15
|
||||
|
||||
#if HAS_TEMP_CHAMBER && HOTENDS > 1
|
||||
|
Reference in New Issue
Block a user