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 6f0b436
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 43 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
2 changes: 2 additions & 0 deletions Marlin/src/lcd/tft/ui_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
#error "Unsupported display resolution!"
#endif

bool lcd_sleep_task();

void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater);
void draw_fan_status(uint16_t x, uint16_t y, const bool blink);

Expand Down

0 comments on commit 6f0b436

Please sign in to comment.