Browse Source

✨ TFT Screen/Backlight Sleep (#22617)

Tanguy Pruvot 3 years ago
parent
commit
c2e4b1626f
No account linked to committer's email address

+ 2
- 0
Marlin/Configuration.h View File

2780
   #define BUTTON_DELAY_EDIT  50 // (ms) Button repeat delay for edit screens
2780
   #define BUTTON_DELAY_EDIT  50 // (ms) Button repeat delay for edit screens
2781
   #define BUTTON_DELAY_MENU 250 // (ms) Button repeat delay for menus
2781
   #define BUTTON_DELAY_MENU 250 // (ms) Button repeat delay for menus
2782
 
2782
 
2783
+  //#define TOUCH_IDLE_SLEEP 300 // (secs) Turn off the TFT backlight if set (5mn)
2784
+
2783
   #define TOUCH_SCREEN_CALIBRATION
2785
   #define TOUCH_SCREEN_CALIBRATION
2784
 
2786
 
2785
   //#define TOUCH_CALIBRATION_X 12316
2787
   //#define TOUCH_CALIBRATION_X 12316

+ 2
- 1
Marlin/src/MarlinCore.cpp View File

542
           next_cub_ms_##N = ms + CUB_DEBOUNCE_DELAY_##N;               \
542
           next_cub_ms_##N = ms + CUB_DEBOUNCE_DELAY_##N;               \
543
           CODE;                                                        \
543
           CODE;                                                        \
544
           queue.inject_P(PSTR(BUTTON##N##_GCODE));                     \
544
           queue.inject_P(PSTR(BUTTON##N##_GCODE));                     \
545
+          TERN_(HAS_LCD_MENU, ui.quick_feedback());                    \
545
         }                                                              \
546
         }                                                              \
546
       }                                                                \
547
       }                                                                \
547
     }while(0)
548
     }while(0)
1354
   #endif
1355
   #endif
1355
 
1356
 
1356
   #if HAS_TOUCH_BUTTONS
1357
   #if HAS_TOUCH_BUTTONS
1357
-    SETUP_RUN(touch.init());
1358
+    SETUP_RUN(touchBt.init());
1358
   #endif
1359
   #endif
1359
 
1360
 
1360
   TERN_(HAS_M206_COMMAND, current_position += home_offset); // Init current position based on home_offset
1361
   TERN_(HAS_M206_COMMAND, current_position += home_offset); // Init current position based on home_offset

+ 3
- 0
Marlin/src/inc/Conditionals_LCD.h View File

1360
 
1360
 
1361
 // This emulated DOGM has 'touch/xpt2046', not 'tft/xpt2046'
1361
 // This emulated DOGM has 'touch/xpt2046', not 'tft/xpt2046'
1362
 #if ENABLED(TOUCH_SCREEN)
1362
 #if ENABLED(TOUCH_SCREEN)
1363
+  #if TOUCH_IDLE_SLEEP
1364
+    #define HAS_TOUCH_SLEEP 1
1365
+  #endif
1363
   #if NONE(TFT_TOUCH_DEVICE_GT911, TFT_TOUCH_DEVICE_XPT2046)
1366
   #if NONE(TFT_TOUCH_DEVICE_GT911, TFT_TOUCH_DEVICE_XPT2046)
1364
     #define TFT_TOUCH_DEVICE_XPT2046          // ADS7843/XPT2046 ADC Touchscreen such as ILI9341 2.8
1367
     #define TFT_TOUCH_DEVICE_XPT2046          // ADS7843/XPT2046 ADC Touchscreen such as ILI9341 2.8
1365
   #endif
1368
   #endif

+ 36
- 14
Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp View File

73
 #define HEIGHT LCD_PIXEL_HEIGHT
73
 #define HEIGHT LCD_PIXEL_HEIGHT
74
 #define PAGE_HEIGHT 8
74
 #define PAGE_HEIGHT 8
75
 
75
 
76
-#include "../touch/touch_buttons.h"
77
-
78
 #if ENABLED(TOUCH_SCREEN_CALIBRATION)
76
 #if ENABLED(TOUCH_SCREEN_CALIBRATION)
79
   #include "../tft_io/touch_calibration.h"
77
   #include "../tft_io/touch_calibration.h"
80
   #include "../marlinui.h"
78
   #include "../marlinui.h"
81
 #endif
79
 #endif
82
 
80
 
81
+#if HAS_TOUCH_BUTTONS
82
+  #include "../touch/touch_buttons.h"
83
+  #if HAS_TOUCH_SLEEP
84
+    #define HAS_TOUCH_BUTTONS_SLEEP 1
85
+  #endif
86
+#endif
87
+
83
 #define X_HI (UPSCALE(TFT_PIXEL_OFFSET_X, WIDTH) - 1)
88
 #define X_HI (UPSCALE(TFT_PIXEL_OFFSET_X, WIDTH) - 1)
84
 #define Y_HI (UPSCALE(TFT_PIXEL_OFFSET_Y, HEIGHT) - 1)
89
 #define Y_HI (UPSCALE(TFT_PIXEL_OFFSET_Y, HEIGHT) - 1)
85
 
90
 
340
   }
345
   }
341
 #endif // HAS_TOUCH_BUTTONS
346
 #endif // HAS_TOUCH_BUTTONS
342
 
347
 
348
+static void u8g_upscale_clear_lcd(u8g_t *u8g, u8g_dev_t *dev, uint16_t *buffer) {
349
+  setWindow(u8g, dev, 0, 0, (TFT_WIDTH) - 1, (TFT_HEIGHT) - 1);
350
+  #if HAS_LCD_IO
351
+    UNUSED(buffer);
352
+    tftio.WriteMultiple(TFT_MARLINBG_COLOR, (TFT_WIDTH) * (TFT_HEIGHT));
353
+  #else
354
+    memset2(buffer, TFT_MARLINBG_COLOR, (TFT_WIDTH) / 2);
355
+    for (uint16_t i = 0; i < (TFT_HEIGHT) * sq(GRAPHICAL_TFT_UPSCALE); i++)
356
+      u8g_WriteSequence(u8g, dev, (TFT_WIDTH) / 2, (uint8_t *)buffer);
357
+  #endif
358
+}
359
+
343
 static uint8_t msgInitCount = 2; // Ignore all messages until 2nd U8G_COM_MSG_INIT
360
 static uint8_t msgInitCount = 2; // Ignore all messages until 2nd U8G_COM_MSG_INIT
344
 
361
 
345
 uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) {
362
 uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) {
365
       tftio.Init();
382
       tftio.Init();
366
       tftio.InitTFT();
383
       tftio.InitTFT();
367
       TERN_(TOUCH_SCREEN_CALIBRATION, touch_calibration.calibration_reset());
384
       TERN_(TOUCH_SCREEN_CALIBRATION, touch_calibration.calibration_reset());
368
-
369
-      // Clear Screen
370
-      setWindow(u8g, dev, 0, 0, (TFT_WIDTH) - 1, (TFT_HEIGHT) - 1);
371
-      #if HAS_LCD_IO
372
-        tftio.WriteMultiple(TFT_MARLINBG_COLOR, (TFT_WIDTH) * (TFT_HEIGHT));
373
-      #else
374
-        memset2(buffer, TFT_MARLINBG_COLOR, (TFT_WIDTH) / 2);
375
-        for (uint16_t i = 0; i < (TFT_HEIGHT) * sq(GRAPHICAL_TFT_UPSCALE); i++)
376
-          u8g_WriteSequence(u8g, dev, (TFT_WIDTH) / 2, (uint8_t *)buffer);
377
-      #endif
385
+      u8g_upscale_clear_lcd(u8g, dev, buffer);
378
       return 0;
386
       return 0;
379
 
387
 
380
     case U8G_DEV_MSG_STOP: preinit = true; break;
388
     case U8G_DEV_MSG_STOP: preinit = true; break;
381
 
389
 
382
-    case U8G_DEV_MSG_PAGE_FIRST:
390
+    case U8G_DEV_MSG_PAGE_FIRST: {
383
       page = 0;
391
       page = 0;
392
+      #if HAS_TOUCH_BUTTONS_SLEEP
393
+        static bool sleepCleared;
394
+        if (touchBt.isSleeping()) {
395
+          if (!sleepCleared) {
396
+            sleepCleared = true;
397
+            u8g_upscale_clear_lcd(u8g, dev, buffer);
398
+            IF_ENABLED(HAS_TOUCH_BUTTONS, redrawTouchButtons = true);
399
+          }
400
+          break;
401
+        }
402
+        else
403
+          sleepCleared = false;
404
+      #endif
384
       TERN_(HAS_TOUCH_BUTTONS, drawTouchButtons(u8g, dev));
405
       TERN_(HAS_TOUCH_BUTTONS, drawTouchButtons(u8g, dev));
385
       setWindow(u8g, dev, TFT_PIXEL_OFFSET_X, TFT_PIXEL_OFFSET_Y, X_HI, Y_HI);
406
       setWindow(u8g, dev, TFT_PIXEL_OFFSET_X, TFT_PIXEL_OFFSET_Y, X_HI, Y_HI);
386
-      break;
407
+    } break;
387
 
408
 
388
     case U8G_DEV_MSG_PAGE_NEXT:
409
     case U8G_DEV_MSG_PAGE_NEXT:
410
+      if (TERN0(HAS_TOUCH_BUTTONS_SLEEP, touchBt.isSleeping())) break;
389
       if (++page > (HEIGHT / PAGE_HEIGHT)) return 1;
411
       if (++page > (HEIGHT / PAGE_HEIGHT)) return 1;
390
 
412
 
391
       LOOP_L_N(y, PAGE_HEIGHT) {
413
       LOOP_L_N(y, PAGE_HEIGHT) {

+ 15
- 2
Marlin/src/lcd/marlinui.cpp View File

673
     draw_kill_screen();
673
     draw_kill_screen();
674
   }
674
   }
675
 
675
 
676
-  void MarlinUI::quick_feedback(const bool clear_buttons/*=true*/) {
676
+  #if HAS_TOUCH_SLEEP
677
+    #if HAS_TOUCH_BUTTONS
678
+      #include "touch/touch_buttons.h"
679
+    #else
680
+      #include "tft/touch.h"
681
+    #endif
682
+    // Wake up a sleeping TFT
683
+    void MarlinUI::wakeup_screen() {
684
+      TERN(HAS_TOUCH_BUTTONS, touchBt.wakeUp(), touch.wakeUp());
685
+    }
686
+  #endif
677
 
687
 
688
+  void MarlinUI::quick_feedback(const bool clear_buttons/*=true*/) {
689
+    TERN_(HAS_TOUCH_SLEEP, wakeup_screen()); // Wake up the TFT with most buttons
678
     TERN_(HAS_LCD_MENU, refresh());
690
     TERN_(HAS_LCD_MENU, refresh());
679
 
691
 
680
     #if HAS_ENCODER_ACTION
692
     #if HAS_ENCODER_ACTION
926
 
938
 
927
         if (on_status_screen()) next_lcd_update_ms += (LCD_UPDATE_INTERVAL) * 2;
939
         if (on_status_screen()) next_lcd_update_ms += (LCD_UPDATE_INTERVAL) * 2;
928
 
940
 
929
-        TERN_(HAS_ENCODER_ACTION, touch_buttons = touch.read_buttons());
941
+        TERN_(HAS_ENCODER_ACTION, touch_buttons = touchBt.read_buttons());
930
 
942
 
931
       #endif
943
       #endif
932
 
944
 
955
             abs_diff = epps;                                            // Treat as a full step size
967
             abs_diff = epps;                                            // Treat as a full step size
956
             encoderDiff = (encoderDiff < 0 ? -1 : 1) * abs_diff;        // ...in the spin direction.
968
             encoderDiff = (encoderDiff < 0 ? -1 : 1) * abs_diff;        // ...in the spin direction.
957
           }
969
           }
970
+          TERN_(HAS_TOUCH_SLEEP, if (lastEncoderDiff != encoderDiff) wakeup_screen());
958
           lastEncoderDiff = encoderDiff;
971
           lastEncoderDiff = encoderDiff;
959
         #endif
972
         #endif
960
 
973
 

+ 5
- 1
Marlin/src/lcd/marlinui.h View File

435
         static millis_t next_filament_display;
435
         static millis_t next_filament_display;
436
       #endif
436
       #endif
437
 
437
 
438
+      #if HAS_TOUCH_SLEEP
439
+        static void wakeup_screen();
440
+      #endif
441
+
438
       static void quick_feedback(const bool clear_buttons=true);
442
       static void quick_feedback(const bool clear_buttons=true);
439
       #if HAS_BUZZER
443
       #if HAS_BUZZER
440
         static void completion_feedback(const bool good=true);
444
         static void completion_feedback(const bool good=true);
441
       #else
445
       #else
442
-        static inline void completion_feedback(const bool=true) {}
446
+        static inline void completion_feedback(const bool=true) { TERN_(HAS_TOUCH_SLEEP, wakeup_screen()); }
443
       #endif
447
       #endif
444
 
448
 
445
       #if DISABLED(LIGHTWEIGHT_UI)
449
       #if DISABLED(LIGHTWEIGHT_UI)

+ 1
- 0
Marlin/src/lcd/menu/menu.cpp View File

285
 
285
 
286
 #if HAS_BUZZER
286
 #if HAS_BUZZER
287
   void MarlinUI::completion_feedback(const bool good/*=true*/) {
287
   void MarlinUI::completion_feedback(const bool good/*=true*/) {
288
+    TERN_(HAS_TOUCH_SLEEP, wakeup_screen()); // Wake up on rotary encoder click...
288
     if (good) {
289
     if (good) {
289
       BUZZ(100, 659);
290
       BUZZ(100, 659);
290
       BUZZ(100, 698);
291
       BUZZ(100, 698);

+ 31
- 2
Marlin/src/lcd/tft/touch.cpp View File

47
          Touch::time_to_hold,
47
          Touch::time_to_hold,
48
          Touch::repeat_delay,
48
          Touch::repeat_delay,
49
          Touch::touch_time;
49
          Touch::touch_time;
50
-TouchControlType  Touch::touch_control_type = NONE;
50
+TouchControlType Touch::touch_control_type = NONE;
51
+#if HAS_TOUCH_SLEEP
52
+  millis_t Touch::next_sleep_ms; // = 0
53
+#endif
51
 #if HAS_RESUME_CONTINUE
54
 #if HAS_RESUME_CONTINUE
52
   extern bool wait_for_user;
55
   extern bool wait_for_user;
53
 #endif
56
 #endif
56
   TERN_(TOUCH_SCREEN_CALIBRATION, touch_calibration.calibration_reset());
59
   TERN_(TOUCH_SCREEN_CALIBRATION, touch_calibration.calibration_reset());
57
   reset();
60
   reset();
58
   io.Init();
61
   io.Init();
62
+  TERN_(HAS_TOUCH_SLEEP, wakeUp());
59
   enable();
63
   enable();
60
 }
64
 }
61
 
65
 
271
   #elif ENABLED(TFT_TOUCH_DEVICE_GT911)
275
   #elif ENABLED(TFT_TOUCH_DEVICE_GT911)
272
     bool is_touched = (TOUCH_ORIENTATION == TOUCH_PORTRAIT ? io.getPoint(y, x) : io.getPoint(x, y));
276
     bool is_touched = (TOUCH_ORIENTATION == TOUCH_PORTRAIT ? io.getPoint(y, x) : io.getPoint(x, y));
273
   #endif
277
   #endif
274
-
278
+  #if HAS_TOUCH_SLEEP
279
+    if (is_touched)
280
+      wakeUp();
281
+    else if (!isSleeping() && ELAPSED(millis(), next_sleep_ms) && ui.on_status_screen())
282
+      sleepTimeout();
283
+  #endif
275
   return is_touched;
284
   return is_touched;
276
 }
285
 }
286
+
287
+#if HAS_TOUCH_SLEEP
288
+
289
+  void Touch::sleepTimeout() {
290
+    #if PIN_EXISTS(TFT_BACKLIGHT)
291
+      OUT_WRITE(TFT_BACKLIGHT_PIN, LOW);
292
+    #endif
293
+    next_sleep_ms = TSLP_SLEEPING;
294
+  }
295
+  void Touch::wakeUp() {
296
+    if (isSleeping()) {
297
+      #if PIN_EXISTS(TFT_BACKLIGHT)
298
+        WRITE(TFT_BACKLIGHT_PIN, HIGH);
299
+      #endif
300
+    }
301
+    next_sleep_ms = millis() + SEC_TO_MS(TOUCH_IDLE_SLEEP);
302
+  }
303
+
304
+#endif // HAS_TOUCH_SLEEP
305
+
277
 Touch touch;
306
 Touch touch;
278
 
307
 
279
 bool MarlinUI::touch_pressed() {
308
 bool MarlinUI::touch_pressed() {

+ 9
- 1
Marlin/src/lcd/tft/touch.h View File

90
 #define UBL_REPEAT_DELAY    125
90
 #define UBL_REPEAT_DELAY    125
91
 #define FREE_MOVE_RANGE     32
91
 #define FREE_MOVE_RANGE     32
92
 
92
 
93
+#define TSLP_PREINIT  0
94
+#define TSLP_SLEEPING 1
95
+
93
 class Touch {
96
 class Touch {
94
   private:
97
   private:
95
     static TOUCH_DRIVER_CLASS io;
98
     static TOUCH_DRIVER_CLASS io;
121
     }
124
     }
122
     static void disable() { enabled = false; }
125
     static void disable() { enabled = false; }
123
     static void enable() { enabled = true; }
126
     static void enable() { enabled = true; }
124
-
127
+    #if HAS_TOUCH_SLEEP
128
+      static millis_t next_sleep_ms;
129
+      static inline bool isSleeping() { return next_sleep_ms == TSLP_SLEEPING; }
130
+      static void sleepTimeout();
131
+      static void wakeUp();
132
+    #endif
125
     static void add_control(TouchControlType type, uint16_t x, uint16_t y, uint16_t width, uint16_t height, intptr_t data = 0);
133
     static void add_control(TouchControlType type, uint16_t x, uint16_t y, uint16_t width, uint16_t height, intptr_t data = 0);
126
 };
134
 };
127
 
135
 

+ 1
- 0
Marlin/src/lcd/tft/ui_1024x600.cpp View File

47
 
47
 
48
 void MarlinUI::tft_idle() {
48
 void MarlinUI::tft_idle() {
49
   #if ENABLED(TOUCH_SCREEN)
49
   #if ENABLED(TOUCH_SCREEN)
50
+    if (TERN0(HAS_TOUCH_SLEEP, lcd_sleep_task())) return;
50
     if (draw_menu_navigation) {
51
     if (draw_menu_navigation) {
51
       add_control(164, TFT_HEIGHT - 50, PAGE_UP, imgPageUp, encoderTopLine > 0);
52
       add_control(164, TFT_HEIGHT - 50, PAGE_UP, imgPageUp, encoderTopLine > 0);
52
       add_control(796, TFT_HEIGHT - 50, PAGE_DOWN, imgPageDown, encoderTopLine + LCD_HEIGHT < screen_items);
53
       add_control(796, TFT_HEIGHT - 50, PAGE_DOWN, imgPageDown, encoderTopLine + LCD_HEIGHT < screen_items);

+ 1
- 0
Marlin/src/lcd/tft/ui_320x240.cpp View File

47
 
47
 
48
 void MarlinUI::tft_idle() {
48
 void MarlinUI::tft_idle() {
49
   #if ENABLED(TOUCH_SCREEN)
49
   #if ENABLED(TOUCH_SCREEN)
50
+    if (TERN0(HAS_TOUCH_SLEEP, lcd_sleep_task())) return;
50
     if (draw_menu_navigation) {
51
     if (draw_menu_navigation) {
51
       add_control(48, 206, PAGE_UP, imgPageUp, encoderTopLine > 0);
52
       add_control(48, 206, PAGE_UP, imgPageUp, encoderTopLine > 0);
52
       add_control(240, 206, PAGE_DOWN, imgPageDown, encoderTopLine + LCD_HEIGHT < screen_items);
53
       add_control(240, 206, PAGE_DOWN, imgPageDown, encoderTopLine + LCD_HEIGHT < screen_items);

+ 1
- 0
Marlin/src/lcd/tft/ui_480x320.cpp View File

47
 
47
 
48
 void MarlinUI::tft_idle() {
48
 void MarlinUI::tft_idle() {
49
   #if ENABLED(TOUCH_SCREEN)
49
   #if ENABLED(TOUCH_SCREEN)
50
+    if (TERN0(HAS_TOUCH_SLEEP, lcd_sleep_task())) return;
50
     if (draw_menu_navigation) {
51
     if (draw_menu_navigation) {
51
       add_control(104, TFT_HEIGHT - 34, PAGE_UP, imgPageUp, encoderTopLine > 0);
52
       add_control(104, TFT_HEIGHT - 34, PAGE_UP, imgPageUp, encoderTopLine > 0);
52
       add_control(344, TFT_HEIGHT - 34, PAGE_DOWN, imgPageDown, encoderTopLine + LCD_HEIGHT < screen_items);
53
       add_control(344, TFT_HEIGHT - 34, PAGE_DOWN, imgPageDown, encoderTopLine + LCD_HEIGHT < screen_items);

+ 21
- 0
Marlin/src/lcd/tft/ui_common.cpp View File

37
   bool draw_menu_navigation = false;
37
   bool draw_menu_navigation = false;
38
 #endif
38
 #endif
39
 
39
 
40
+#if HAS_TOUCH_SLEEP
41
+
42
+  bool lcd_sleep_task() {
43
+    static bool sleepCleared;
44
+    if (touch.isSleeping()) {
45
+      tft.queue.reset();
46
+      if (!sleepCleared) {
47
+        sleepCleared = true;
48
+        ui.clear_lcd();
49
+        tft.queue.async();
50
+      }
51
+      touch.idle();
52
+      return true;
53
+    }
54
+    else
55
+      sleepCleared = false;
56
+    return false;
57
+  }
58
+
59
+#endif
60
+
40
 void menu_line(const uint8_t row, uint16_t color) {
61
 void menu_line(const uint8_t row, uint16_t color) {
41
   cursor.set(0, row);
62
   cursor.set(0, row);
42
   tft.canvas(0, TFT_TOP_LINE_Y + cursor.y * MENU_LINE_HEIGHT, TFT_WIDTH, MENU_ITEM_HEIGHT);
63
   tft.canvas(0, TFT_TOP_LINE_Y + cursor.y * MENU_LINE_HEIGHT, TFT_WIDTH, MENU_ITEM_HEIGHT);

+ 4
- 0
Marlin/src/lcd/tft/ui_common.h View File

51
 void menu_line(const uint8_t row, uint16_t color=COLOR_BACKGROUND);
51
 void menu_line(const uint8_t row, uint16_t color=COLOR_BACKGROUND);
52
 void menu_item(const uint8_t row, bool sel = false);
52
 void menu_item(const uint8_t row, bool sel = false);
53
 
53
 
54
+#if HAS_TOUCH_SLEEP
55
+  bool lcd_sleep_task();
56
+#endif
57
+
54
 #define ABSOLUTE_ZERO     -273.15
58
 #define ABSOLUTE_ZERO     -273.15
55
 
59
 
56
 #if HAS_TEMP_CHAMBER && HOTENDS > 1
60
 #if HAS_TEMP_CHAMBER && HOTENDS > 1

+ 0
- 1
Marlin/src/lcd/tft_io/tft_io.h View File

59
   #define TFT_ROTATION TFT_NO_ROTATION
59
   #define TFT_ROTATION TFT_NO_ROTATION
60
 #endif
60
 #endif
61
 
61
 
62
-
63
 // TFT_ORIENTATION is the "sum" of TFT_DEFAULT_ORIENTATION plus user TFT_ROTATION
62
 // TFT_ORIENTATION is the "sum" of TFT_DEFAULT_ORIENTATION plus user TFT_ROTATION
64
 #define TFT_ORIENTATION ((TFT_DEFAULT_ORIENTATION) ^ (TFT_ROTATION))
63
 #define TFT_ORIENTATION ((TFT_DEFAULT_ORIENTATION) ^ (TFT_ROTATION))
65
 
64
 

+ 34
- 2
Marlin/src/lcd/touch/touch_buttons.cpp View File

38
   #include "../tft_io/touch_calibration.h"
38
   #include "../tft_io/touch_calibration.h"
39
 #endif
39
 #endif
40
 
40
 
41
+#if HAS_TOUCH_SLEEP
42
+  millis_t TouchButtons::next_sleep_ms;
43
+#endif
44
+
41
 #include "../buttons.h" // For EN_C bit mask
45
 #include "../buttons.h" // For EN_C bit mask
42
 #include "../marlinui.h" // For ui.refresh
46
 #include "../marlinui.h" // For ui.refresh
43
 #include "../tft_io/tft_io.h"
47
 #include "../tft_io/tft_io.h"
50
 #define BUTTON_AREA_TOP BUTTON_Y_LO
54
 #define BUTTON_AREA_TOP BUTTON_Y_LO
51
 #define BUTTON_AREA_BOT BUTTON_Y_HI
55
 #define BUTTON_AREA_BOT BUTTON_Y_HI
52
 
56
 
53
-TouchButtons touch;
57
+TouchButtons touchBt;
54
 
58
 
55
-void TouchButtons::init() { touchIO.Init(); }
59
+void TouchButtons::init() {
60
+  touchIO.Init();
61
+  TERN_(HAS_TOUCH_SLEEP, next_sleep_ms = millis() + SEC_TO_MS(TOUCH_IDLE_SLEEP));
62
+}
56
 
63
 
57
 uint8_t TouchButtons::read_buttons() {
64
 uint8_t TouchButtons::read_buttons() {
58
   #ifdef HAS_WIRED_LCD
65
   #ifdef HAS_WIRED_LCD
59
     int16_t x, y;
66
     int16_t x, y;
60
 
67
 
61
     const bool is_touched = (TERN(TOUCH_SCREEN_CALIBRATION, touch_calibration.calibration.orientation, TOUCH_ORIENTATION) == TOUCH_PORTRAIT ? touchIO.getRawPoint(&y, &x) : touchIO.getRawPoint(&x, &y));
68
     const bool is_touched = (TERN(TOUCH_SCREEN_CALIBRATION, touch_calibration.calibration.orientation, TOUCH_ORIENTATION) == TOUCH_PORTRAIT ? touchIO.getRawPoint(&y, &x) : touchIO.getRawPoint(&x, &y));
69
+    #if HAS_TOUCH_SLEEP
70
+      if (is_touched)
71
+        wakeUp();
72
+      else if (!isSleeping() && ELAPSED(millis(), next_sleep_ms) && ui.on_status_screen())
73
+        sleepTimeout();
74
+    #endif
62
     if (!is_touched) return 0;
75
     if (!is_touched) return 0;
63
 
76
 
64
     #if ENABLED(TOUCH_SCREEN_CALIBRATION)
77
     #if ENABLED(TOUCH_SCREEN_CALIBRATION)
96
   return 0;
109
   return 0;
97
 }
110
 }
98
 
111
 
112
+#if HAS_TOUCH_SLEEP
113
+
114
+  void TouchButtons::sleepTimeout() {
115
+    #if PIN_EXISTS(TFT_BACKLIGHT)
116
+      OUT_WRITE(TFT_BACKLIGHT_PIN, LOW);
117
+    #endif
118
+    next_sleep_ms = TSLP_SLEEPING;
119
+  }
120
+  void TouchButtons::wakeUp() {
121
+    if (isSleeping()) {
122
+      #if PIN_EXISTS(TFT_BACKLIGHT)
123
+        WRITE(TFT_BACKLIGHT_PIN, HIGH);
124
+      #endif
125
+    }
126
+    next_sleep_ms = millis() + SEC_TO_MS(TOUCH_IDLE_SLEEP);
127
+  }
128
+
129
+#endif // HAS_TOUCH_SLEEP
130
+
99
 #endif // HAS_TOUCH_BUTTONS
131
 #endif // HAS_TOUCH_BUTTONS

+ 10
- 1
Marlin/src/lcd/touch/touch_buttons.h View File

50
 #define BUTTON_Y_HI (TFT_HEIGHT) - BUTTON_SPACING
50
 #define BUTTON_Y_HI (TFT_HEIGHT) - BUTTON_SPACING
51
 #define BUTTON_Y_LO BUTTON_Y_HI - BUTTON_HEIGHT
51
 #define BUTTON_Y_LO BUTTON_Y_HI - BUTTON_HEIGHT
52
 
52
 
53
+#define TSLP_PREINIT  0
54
+#define TSLP_SLEEPING 1
55
+
53
 class TouchButtons {
56
 class TouchButtons {
54
 public:
57
 public:
55
   static void init();
58
   static void init();
56
   static uint8_t read_buttons();
59
   static uint8_t read_buttons();
60
+  #if HAS_TOUCH_SLEEP
61
+    static millis_t next_sleep_ms;
62
+    static bool isSleeping() { return next_sleep_ms == TSLP_SLEEPING; }
63
+    static void sleepTimeout();
64
+    static void wakeUp();
65
+  #endif
57
 };
66
 };
58
 
67
 
59
-extern TouchButtons touch;
68
+extern TouchButtons touchBt;

Loading…
Cancel
Save