Skip to content

Commit

Permalink
TFT: Merge PR MarlinFirmware#22617 additions
Browse files Browse the repository at this point in the history
- HAS_TOUCH_SLEEP conditional
- common touch sleep code
  • Loading branch information
thinkyhead authored and tpruvot committed Sep 14, 2021
1 parent 656b538 commit bf223b3
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 120 deletions.
2 changes: 1 addition & 1 deletion Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
next_cub_ms_##N = ms + CUB_DEBOUNCE_DELAY_##N; \
CODE; \
queue.inject_P(PSTR(BUTTON##N##_GCODE)); \
TERN_(HAS_LCD_MENU, ui.completion_feedback()); \
TERN_(HAS_LCD_MENU, ui.quick_feedback()); \
} \
} \
}while(0)
Expand Down
3 changes: 3 additions & 0 deletions Marlin/src/inc/Conditionals_LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,9 @@

// This emulated DOGM has 'touch/xpt2046', not 'tft/xpt2046'
#if ENABLED(TOUCH_SCREEN)
#if TOUCH_IDLE_SLEEP
#define HAS_TOUCH_SLEEP 1
#endif
#if NONE(TFT_TOUCH_DEVICE_GT911, TFT_TOUCH_DEVICE_XPT2046)
#define TFT_TOUCH_DEVICE_XPT2046 // ADS7843/XPT2046 ADC Touchscreen such as ILI9341 2.8
#endif
Expand Down
24 changes: 12 additions & 12 deletions Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ TFT_IO tftio;
#define HEIGHT LCD_PIXEL_HEIGHT
#define PAGE_HEIGHT 8

#include "../touch/touch_buttons.h"

#if ENABLED(TOUCH_SCREEN_CALIBRATION)
#include "../tft_io/touch_calibration.h"
#include "../marlinui.h"
#endif

#define HAS_TOUCH_SLEEP (defined(TOUCH_IDLE_SLEEP) && TOUCH_IDLE_SLEEP > 0 && HAS_TOUCH_BUTTONS)
#if HAS_TOUCH_SLEEP
static bool sleepCleared;
#if HAS_TOUCH_BUTTONS
#include "../touch/touch_buttons.h"
#if HAS_TOUCH_SLEEP
#define HAS_TOUCH_BUTTONS_SLEEP 1
#endif
#endif

#define X_HI (UPSCALE(TFT_PIXEL_OFFSET_X, WIDTH) - 1)
Expand Down Expand Up @@ -465,9 +465,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_SLEEP
#if HAS_TOUCH_BUTTONS_SLEEP
static bool sleepCleared;
if (touchBt.isSleeping()) {
if (!sleepCleared) {
sleepCleared = true;
Expand All @@ -476,7 +477,8 @@ 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
#ifdef DYNAMIC_DEV_ICONS
redrawIcons = TERN(HAS_TOUCH_BUTTONS, redrawTouchButtons, false);
Expand Down Expand Up @@ -513,12 +515,10 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u
#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 HAS_TOUCH_SLEEP
if (touchBt.isSleeping()) break;
#endif
if (TERN0(HAS_TOUCH_BUTTONS_SLEEP, touchBt.isSleeping())) break;
if (++page > (HEIGHT / PAGE_HEIGHT)) return 1;

LOOP_L_N(y, PAGE_HEIGHT) {
Expand Down
24 changes: 10 additions & 14 deletions Marlin/src/lcd/marlinui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,22 +673,20 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
draw_kill_screen();
}

#ifdef TOUCH_IDLE_SLEEP
// Handle events which should wake up a sleeping TFT
#if HAS_TOUCH_SLEEP
#if HAS_TOUCH_BUTTONS
#include "touch/touch_buttons.h"
#else
#include "tft/touch.h"
#endif
// Wake up a sleeping TFT
void MarlinUI::wakeup_screen() {
#if ENABLED(TOUCH_SCREEN)
touch.wakeUp();
#elif HAS_TOUCH_BUTTONS
touchBt.wakeUp();
#endif
TERN(HAS_TOUCH_BUTTONS, touchBt.wakeUp(), touch.wakeUp());
}
#endif

void MarlinUI::quick_feedback(const bool clear_buttons/*=true*/) {
#ifdef TOUCH_IDLE_SLEEP
// Wake up the TFT with most buttons
ui.wakeup_screen();
#endif
TERN_(HAS_TOUCH_SLEEP, wakeup_screen()); // Wake up the TFT with most buttons
TERN_(HAS_LCD_MENU, refresh());

#if HAS_ENCODER_ACTION
Expand Down Expand Up @@ -969,9 +967,7 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
abs_diff = epps; // Treat as a full step size
encoderDiff = (encoderDiff < 0 ? -1 : 1) * abs_diff; // ...in the spin direction.
}
#ifdef TOUCH_IDLE_SLEEP
if (lastEncoderDiff != encoderDiff) ui.wakeup_screen();
#endif
TERN_(HAS_TOUCH_SLEEP, if (lastEncoderDiff != encoderDiff) wakeup_screen());
lastEncoderDiff = encoderDiff;
#endif

Expand Down
12 changes: 2 additions & 10 deletions Marlin/src/lcd/marlinui.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@
#include "tft_io/touch_calibration.h"
#endif

#if ENABLED(TOUCH_SCREEN) && defined(TOUCH_IDLE_SLEEP)
#include "tft/touch.h"
#elif HAS_TOUCH_BUTTONS && defined(TOUCH_IDLE_SLEEP)
#include "touch/touch_buttons.h"
#endif

#if ANY(HAS_LCD_MENU, ULTIPANEL_FEEDMULTIPLY, SOFT_RESET_ON_KILL)
#define HAS_ENCODER_ACTION 1
#endif
Expand Down Expand Up @@ -441,7 +435,7 @@ class MarlinUI {
static millis_t next_filament_display;
#endif

#ifdef TOUCH_IDLE_SLEEP
#if HAS_TOUCH_SLEEP
static void wakeup_screen();
#endif

Expand All @@ -450,9 +444,7 @@ class MarlinUI {
static void completion_feedback(const bool good=true);
#else
static inline void completion_feedback(const bool=true) {
#ifdef TOUCH_IDLE_SLEEP
wakeup_screen();
#endif
TERN_(HAS_TOUCH_SLEEP, wakeup_screen());
// for top icons like RST, on config load/save/reset menu
TERN_(FSMC_GRAPHICAL_TFT, refresh(LCDVIEW_CALL_REDRAW_NEXT));
}
Expand Down
5 changes: 1 addition & 4 deletions Marlin/src/lcd/menu/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,7 @@ void scroll_screen(const uint8_t limit, const bool is_menu) {

#if HAS_BUZZER
void MarlinUI::completion_feedback(const bool good/*=true*/) {
#ifdef TOUCH_IDLE_SLEEP
// Wake up on rotary encoder click...
ui.wakeup_screen();
#endif
TERN_(HAS_TOUCH_SLEEP, wakeup_screen()); // Wake up on rotary encoder click...
if (good) {
BUZZ(100, 659);
BUZZ(100, 698);
Expand Down
30 changes: 14 additions & 16 deletions Marlin/src/lcd/tft/touch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ millis_t Touch::last_touch_ms = 0,
Touch::time_to_hold,
Touch::repeat_delay,
Touch::touch_time;
TouchControlType Touch::touch_control_type = NONE;
#if TOUCH_IDLE_SLEEP > 0
millis_t Touch::last_touched_ms;
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;
Expand All @@ -59,9 +59,7 @@ void Touch::init() {
TERN_(TOUCH_SCREEN_CALIBRATION, touch_calibration.calibration_reset());
reset();
io.Init();
#if TOUCH_IDLE_SLEEP > 0
last_touched_ms = millis();
#endif
TERN_(HAS_TOUCH_SLEEP, wakeUp());
enable();
}

Expand Down Expand Up @@ -277,33 +275,33 @@ 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 TOUCH_IDLE_SLEEP > 0
if (is_touched) {
#if HAS_TOUCH_SLEEP
if (is_touched)
wakeUp();
} else if (last_touched_ms != TSLP_SLEEPING && (millis() - last_touched_ms) > (TOUCH_IDLE_SLEEP*1000)) {
if (ui.on_status_screen())
sleepTimeout();
}
else if (!isSleeping() && ELAPSED(millis(), next_sleep_ms) && ui.on_status_screen())
sleepTimeout();
#endif
return is_touched;
}

#if TOUCH_IDLE_SLEEP > 0
#if HAS_TOUCH_SLEEP

void Touch::sleepTimeout() {
#if PIN_EXISTS(TFT_BACKLIGHT)
OUT_WRITE(TFT_BACKLIGHT_PIN, LOW);
#endif
last_touched_ms = TSLP_SLEEPING;
next_sleep_ms = TSLP_SLEEPING;
}
void Touch::wakeUp() {
if (isSleeping()) {
#if PIN_EXISTS(TFT_BACKLIGHT)
WRITE(TFT_BACKLIGHT_PIN, HIGH);
#endif
}
last_touched_ms = millis();
next_sleep_ms = millis() + SEC_TO_MS(TOUCH_IDLE_SLEEP);
}
#endif // TOUCH_IDLE_SLEEP

#endif // HAS_TOUCH_SLEEP

Touch touch;

Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/lcd/tft/touch.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ class Touch {
}
static void disable() { enabled = false; }
static void enable() { enabled = true; }
#if TOUCH_IDLE_SLEEP > 0
static millis_t last_touched_ms;
static bool isSleeping() { return (last_touched_ms == TSLP_SLEEPING); }
#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
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
6 changes: 4 additions & 2 deletions Marlin/src/lcd/tft/ui_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
#include "tft.h"
#include "tft_image.h"

#define HAS_TOUCH_SLEEP (defined(TOUCH_IDLE_SLEEP) && TOUCH_IDLE_SLEEP > 0)

#if ENABLED(TOUCH_SCREEN)
#include "touch.h"
extern bool draw_menu_navigation;
Expand All @@ -53,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
1 change: 0 additions & 1 deletion Marlin/src/lcd/tft_io/tft_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
#define TFT_ROTATION TFT_NO_ROTATION
#endif


// TFT_ORIENTATION is the "sum" of TFT_DEFAULT_ORIENTATION plus user TFT_ROTATION
#define TFT_ORIENTATION ((TFT_DEFAULT_ORIENTATION) ^ (TFT_ROTATION))

Expand Down
Loading

0 comments on commit bf223b3

Please sign in to comment.