Skip to content

Commit

Permalink
common touch sleep code
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Sep 14, 2021
1 parent 23ab798 commit 35599db
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 46 deletions.
9 changes: 5 additions & 4 deletions Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ TFT_IO tftio;
#include "../touch/touch_buttons.h"
#if HAS_TOUCH_SLEEP
#define HAS_TOUCH_BUTTONS_SLEEP 1
static bool sleepCleared;
#endif
#endif

Expand Down Expand Up @@ -388,9 +387,10 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u

case U8G_DEV_MSG_STOP: preinit = true; break;

case U8G_DEV_MSG_PAGE_FIRST:
case U8G_DEV_MSG_PAGE_FIRST: {
page = 0;
#if HAS_TOUCH_BUTTONS_SLEEP
static bool sleepCleared;
if (touchBt.isSleeping()) {
if (!sleepCleared) {
sleepCleared = true;
Expand All @@ -399,11 +399,12 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u
}
break;
}
else sleepCleared = false;
else
sleepCleared = false;
#endif
TERN_(HAS_TOUCH_BUTTONS, drawTouchButtons(u8g, dev));
setWindow(u8g, dev, TFT_PIXEL_OFFSET_X, TFT_PIXEL_OFFSET_Y, X_HI, Y_HI);
break;
} break;

case U8G_DEV_MSG_PAGE_NEXT:
if (TERN0(HAS_TOUCH_BUTTONS_SLEEP, touchBt.isSleeping())) break;
Expand Down
14 changes: 1 addition & 13 deletions Marlin/src/lcd/tft/ui_1024x600.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,7 @@

void MarlinUI::tft_idle() {
#if ENABLED(TOUCH_SCREEN)
#if HAS_TOUCH_SLEEP
static bool sleepCleared;
if (touch.isSleeping()) {
tft.queue.reset();
if (!sleepCleared) {
sleepCleared = true;
ui.clear_lcd();
tft.queue.async();
}
touch.idle();
return;
} else sleepCleared = false;
#endif
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);
Expand Down
14 changes: 1 addition & 13 deletions Marlin/src/lcd/tft/ui_320x240.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,7 @@

void MarlinUI::tft_idle() {
#if ENABLED(TOUCH_SCREEN)
#if HAS_TOUCH_SLEEP
static bool sleepCleared;
if (touch.isSleeping()) {
tft.queue.reset();
if (!sleepCleared) {
sleepCleared = true;
ui.clear_lcd();
tft.queue.async();
}
touch.idle();
return;
} else sleepCleared = false;
#endif
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);
Expand Down
14 changes: 1 addition & 13 deletions Marlin/src/lcd/tft/ui_480x320.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,7 @@

void MarlinUI::tft_idle() {
#if ENABLED(TOUCH_SCREEN)
#if HAS_TOUCH_SLEEP
static bool sleepCleared;
if (touch.isSleeping()) {
tft.queue.reset();
if (!sleepCleared) {
sleepCleared = true;
ui.clear_lcd();
tft.queue.async();
}
touch.idle();
return;
} else sleepCleared = false;
#endif
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);
Expand Down
21 changes: 21 additions & 0 deletions Marlin/src/lcd/tft/ui_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions Marlin/src/lcd/tft/ui_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions Marlin/src/lcd/touch/touch_buttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ TouchButtons touchBt;

void TouchButtons::init() {
touchIO.Init();
#if HAS_TOUCH_SLEEP
next_sleep_ms = millis() + SEC_TO_MS(TOUCH_IDLE_SLEEP);
#endif
TERN_(HAS_TOUCH_SLEEP, next_sleep_ms = millis() + SEC_TO_MS(TOUCH_IDLE_SLEEP));
}

uint8_t TouchButtons::read_buttons() {
Expand Down

0 comments on commit 35599db

Please sign in to comment.