Skip to content

Commit

Permalink
HAS_TOUCH_SLEEP conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Sep 14, 2021
1 parent ea29b98 commit dfb5617
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 79 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
17 changes: 8 additions & 9 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,17 @@ 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
static bool sleepCleared;
#endif
#endif

#define X_HI (UPSCALE(TFT_PIXEL_OFFSET_X, WIDTH) - 1)
Expand Down Expand Up @@ -389,7 +390,7 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u

case U8G_DEV_MSG_PAGE_FIRST:
page = 0;
#if HAS_TOUCH_SLEEP
#if HAS_TOUCH_BUTTONS_SLEEP
if (touchBt.isSleeping()) {
if (!sleepCleared) {
sleepCleared = true;
Expand All @@ -405,9 +406,7 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u
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
14 changes: 2 additions & 12 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,19 +435,15 @@ class MarlinUI {
static millis_t next_filament_display;
#endif

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

static void quick_feedback(const bool clear_buttons=true);
#if HAS_BUZZER
static void completion_feedback(const bool good=true);
#else
static inline void completion_feedback(const bool=true) {
#ifdef TOUCH_IDLE_SLEEP
wakeup_screen();
#endif
}
static inline void completion_feedback(const bool=true) { TERN_(HAS_TOUCH_SLEEP, wakeup_screen()); }
#endif

#if DISABLED(LIGHTWEIGHT_UI)
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;
#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, next_sleep_ms = millis() + SEC_TO_MS(TOUCH_IDLE_SLEEP));
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
2 changes: 0 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 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
28 changes: 14 additions & 14 deletions Marlin/src/lcd/touch/touch_buttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
#include "../tft_io/touch_calibration.h"
#endif

#if TOUCH_IDLE_SLEEP > 0
millis_t TouchButtons::last_touch_ms;
#if HAS_TOUCH_SLEEP
millis_t TouchButtons::next_sleep_ms;
#endif

#include "../buttons.h" // For EN_C bit mask
Expand All @@ -58,8 +58,8 @@ TouchButtons touchBt;

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

Expand All @@ -68,13 +68,11 @@ uint8_t TouchButtons::read_buttons() {
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 TOUCH_IDLE_SLEEP > 0
if (is_touched) {
#if HAS_TOUCH_SLEEP
if (is_touched)
wakeUp();
} else if (last_touch_ms != TSLP_SLEEPING && (millis() - last_touch_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
if (!is_touched) return 0;

Expand Down Expand Up @@ -113,21 +111,23 @@ uint8_t TouchButtons::read_buttons() {
return 0;
}

#if TOUCH_IDLE_SLEEP > 0
#if HAS_TOUCH_SLEEP

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

#endif // HAS_TOUCH_SLEEP

#endif // HAS_TOUCH_BUTTONS
6 changes: 3 additions & 3 deletions Marlin/src/lcd/touch/touch_buttons.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ class TouchButtons {
public:
static void init();
static uint8_t read_buttons();
#if TOUCH_IDLE_SLEEP > 0
static millis_t last_touch_ms;
static bool isSleeping() { return (last_touch_ms == TSLP_SLEEPING); }
#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
Expand Down

0 comments on commit dfb5617

Please sign in to comment.