Bläddra i källkod

✨ TFT Screen/Backlight Sleep (#22617)

Tanguy Pruvot 3 år sedan
förälder
incheckning
c2e4b1626f
Inget konto är kopplat till bidragsgivarens mejladress

+ 2
- 0
Marlin/Configuration.h Visa fil

@@ -2780,6 +2780,8 @@
2780 2780
   #define BUTTON_DELAY_EDIT  50 // (ms) Button repeat delay for edit screens
2781 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 2785
   #define TOUCH_SCREEN_CALIBRATION
2784 2786
 
2785 2787
   //#define TOUCH_CALIBRATION_X 12316

+ 2
- 1
Marlin/src/MarlinCore.cpp Visa fil

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

+ 3
- 0
Marlin/src/inc/Conditionals_LCD.h Visa fil

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

+ 36
- 14
Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp Visa fil

@@ -73,13 +73,18 @@ TFT_IO tftio;
73 73
 #define HEIGHT LCD_PIXEL_HEIGHT
74 74
 #define PAGE_HEIGHT 8
75 75
 
76
-#include "../touch/touch_buttons.h"
77
-
78 76
 #if ENABLED(TOUCH_SCREEN_CALIBRATION)
79 77
   #include "../tft_io/touch_calibration.h"
80 78
   #include "../marlinui.h"
81 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 88
 #define X_HI (UPSCALE(TFT_PIXEL_OFFSET_X, WIDTH) - 1)
84 89
 #define Y_HI (UPSCALE(TFT_PIXEL_OFFSET_Y, HEIGHT) - 1)
85 90
 
@@ -340,6 +345,18 @@ static uint8_t page;
340 345
   }
341 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 360
 static uint8_t msgInitCount = 2; // Ignore all messages until 2nd U8G_COM_MSG_INIT
344 361
 
345 362
 uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) {
@@ -365,27 +382,32 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u
365 382
       tftio.Init();
366 383
       tftio.InitTFT();
367 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 386
       return 0;
379 387
 
380 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 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 405
       TERN_(HAS_TOUCH_BUTTONS, drawTouchButtons(u8g, dev));
385 406
       setWindow(u8g, dev, TFT_PIXEL_OFFSET_X, TFT_PIXEL_OFFSET_Y, X_HI, Y_HI);
386
-      break;
407
+    } break;
387 408
 
388 409
     case U8G_DEV_MSG_PAGE_NEXT:
410
+      if (TERN0(HAS_TOUCH_BUTTONS_SLEEP, touchBt.isSleeping())) break;
389 411
       if (++page > (HEIGHT / PAGE_HEIGHT)) return 1;
390 412
 
391 413
       LOOP_L_N(y, PAGE_HEIGHT) {

+ 15
- 2
Marlin/src/lcd/marlinui.cpp Visa fil

@@ -673,8 +673,20 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
673 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 690
     TERN_(HAS_LCD_MENU, refresh());
679 691
 
680 692
     #if HAS_ENCODER_ACTION
@@ -926,7 +938,7 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
926 938
 
927 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 943
       #endif
932 944
 
@@ -955,6 +967,7 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
955 967
             abs_diff = epps;                                            // Treat as a full step size
956 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 971
           lastEncoderDiff = encoderDiff;
959 972
         #endif
960 973
 

+ 5
- 1
Marlin/src/lcd/marlinui.h Visa fil

@@ -435,11 +435,15 @@ public:
435 435
         static millis_t next_filament_display;
436 436
       #endif
437 437
 
438
+      #if HAS_TOUCH_SLEEP
439
+        static void wakeup_screen();
440
+      #endif
441
+
438 442
       static void quick_feedback(const bool clear_buttons=true);
439 443
       #if HAS_BUZZER
440 444
         static void completion_feedback(const bool good=true);
441 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 447
       #endif
444 448
 
445 449
       #if DISABLED(LIGHTWEIGHT_UI)

+ 1
- 0
Marlin/src/lcd/menu/menu.cpp Visa fil

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

+ 31
- 2
Marlin/src/lcd/tft/touch.cpp Visa fil

@@ -47,7 +47,10 @@ millis_t Touch::last_touch_ms = 0,
47 47
          Touch::time_to_hold,
48 48
          Touch::repeat_delay,
49 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 54
 #if HAS_RESUME_CONTINUE
52 55
   extern bool wait_for_user;
53 56
 #endif
@@ -56,6 +59,7 @@ void Touch::init() {
56 59
   TERN_(TOUCH_SCREEN_CALIBRATION, touch_calibration.calibration_reset());
57 60
   reset();
58 61
   io.Init();
62
+  TERN_(HAS_TOUCH_SLEEP, wakeUp());
59 63
   enable();
60 64
 }
61 65
 
@@ -271,9 +275,34 @@ bool Touch::get_point(int16_t *x, int16_t *y) {
271 275
   #elif ENABLED(TFT_TOUCH_DEVICE_GT911)
272 276
     bool is_touched = (TOUCH_ORIENTATION == TOUCH_PORTRAIT ? io.getPoint(y, x) : io.getPoint(x, y));
273 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 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 306
 Touch touch;
278 307
 
279 308
 bool MarlinUI::touch_pressed() {

+ 9
- 1
Marlin/src/lcd/tft/touch.h Visa fil

@@ -90,6 +90,9 @@ typedef struct __attribute__((__packed__)) {
90 90
 #define UBL_REPEAT_DELAY    125
91 91
 #define FREE_MOVE_RANGE     32
92 92
 
93
+#define TSLP_PREINIT  0
94
+#define TSLP_SLEEPING 1
95
+
93 96
 class Touch {
94 97
   private:
95 98
     static TOUCH_DRIVER_CLASS io;
@@ -121,7 +124,12 @@ class Touch {
121 124
     }
122 125
     static void disable() { enabled = false; }
123 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 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 Visa fil

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

+ 1
- 0
Marlin/src/lcd/tft/ui_320x240.cpp Visa fil

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

+ 1
- 0
Marlin/src/lcd/tft/ui_480x320.cpp Visa fil

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

+ 21
- 0
Marlin/src/lcd/tft/ui_common.cpp Visa fil

@@ -37,6 +37,27 @@ static xy_uint_t cursor;
37 37
   bool draw_menu_navigation = false;
38 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 61
 void menu_line(const uint8_t row, uint16_t color) {
41 62
   cursor.set(0, row);
42 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 Visa fil

@@ -51,6 +51,10 @@ void draw_fan_status(uint16_t x, uint16_t y, const bool blink);
51 51
 void menu_line(const uint8_t row, uint16_t color=COLOR_BACKGROUND);
52 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 58
 #define ABSOLUTE_ZERO     -273.15
55 59
 
56 60
 #if HAS_TEMP_CHAMBER && HOTENDS > 1

+ 0
- 1
Marlin/src/lcd/tft_io/tft_io.h Visa fil

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

+ 34
- 2
Marlin/src/lcd/touch/touch_buttons.cpp Visa fil

@@ -38,6 +38,10 @@
38 38
   #include "../tft_io/touch_calibration.h"
39 39
 #endif
40 40
 
41
+#if HAS_TOUCH_SLEEP
42
+  millis_t TouchButtons::next_sleep_ms;
43
+#endif
44
+
41 45
 #include "../buttons.h" // For EN_C bit mask
42 46
 #include "../marlinui.h" // For ui.refresh
43 47
 #include "../tft_io/tft_io.h"
@@ -50,15 +54,24 @@
50 54
 #define BUTTON_AREA_TOP BUTTON_Y_LO
51 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 64
 uint8_t TouchButtons::read_buttons() {
58 65
   #ifdef HAS_WIRED_LCD
59 66
     int16_t x, y;
60 67
 
61 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 75
     if (!is_touched) return 0;
63 76
 
64 77
     #if ENABLED(TOUCH_SCREEN_CALIBRATION)
@@ -96,4 +109,23 @@ uint8_t TouchButtons::read_buttons() {
96 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 131
 #endif // HAS_TOUCH_BUTTONS

+ 10
- 1
Marlin/src/lcd/touch/touch_buttons.h Visa fil

@@ -50,10 +50,19 @@
50 50
 #define BUTTON_Y_HI (TFT_HEIGHT) - BUTTON_SPACING
51 51
 #define BUTTON_Y_LO BUTTON_Y_HI - BUTTON_HEIGHT
52 52
 
53
+#define TSLP_PREINIT  0
54
+#define TSLP_SLEEPING 1
55
+
53 56
 class TouchButtons {
54 57
 public:
55 58
   static void init();
56 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;

Laddar…
Avbryt
Spara