소스 검색

Touch-select MarlinUI menu items (#18239)

Victor 5 년 전
부모
커밋
c6f3511d84
No account linked to committer's email address
3개의 변경된 파일49개의 추가작업 그리고 6개의 파일을 삭제
  1. 22
    6
      Marlin/src/feature/touch/xpt2046.cpp
  2. 23
    0
      Marlin/src/lcd/ultralcd.cpp
  3. 4
    0
      Marlin/src/lcd/ultralcd.h

+ 22
- 6
Marlin/src/feature/touch/xpt2046.cpp 파일 보기

@@ -23,6 +23,12 @@
23 23
 
24 24
 #include "xpt2046.h"
25 25
 #include "../../inc/MarlinConfig.h"
26
+#include "../../lcd/dogm/ultralcd_DOGM.h" // for LCD_FULL_PIXEL_WIDTH, etc.
27
+
28
+#define BUTTON_AREA_TOP 175
29
+#define BUTTON_AREA_BOT 234
30
+#define SCREEN_START_TOP ((LCD_PIXEL_OFFSET_Y) * 240 / (LCD_FULL_PIXEL_HEIGHT))
31
+#define TOUCHABLE_Y_HEIGHT (BUTTON_AREA_TOP - (SCREEN_START_TOP))
26 32
 
27 33
 #ifndef TOUCH_INT_PIN
28 34
   #define TOUCH_INT_PIN  -1
@@ -78,13 +84,23 @@ uint8_t XPT2046::read_buttons() {
78 84
                  y = uint16_t(((uint32_t(getInTouch(XPT2046_Y))) * tsoffsets[2]) >> 16) + tsoffsets[3];
79 85
   if (!isTouched()) return 0; // Fingers must still be on the TS for a valid read.
80 86
 
81
-  if (y < 175 || y > 234) return 0;
87
+  // Touch within the button area simulates an encoder button
88
+  if (y > BUTTON_AREA_TOP && y < BUTTON_AREA_BOT)
89
+    return WITHIN(x,  14,  77) ? EN_D
90
+         : WITHIN(x,  90, 153) ? EN_A
91
+         : WITHIN(x, 166, 229) ? EN_B
92
+         : WITHIN(x, 242, 305) ? EN_C
93
+         : 0;
94
+
95
+  if (x > LCD_FULL_PIXEL_WIDTH || !WITHIN(y, SCREEN_START_TOP, BUTTON_AREA_TOP)) return 0;
96
+
97
+  // Column and row above BUTTON_AREA_TOP
98
+  int8_t col = x * (LCD_WIDTH) / (LCD_FULL_PIXEL_WIDTH),
99
+         row = (y - (SCREEN_START_TOP)) * (LCD_HEIGHT) / (TOUCHABLE_Y_HEIGHT);
82 100
 
83
-  return WITHIN(x,  14,  77) ? EN_D
84
-       : WITHIN(x,  90, 153) ? EN_A
85
-       : WITHIN(x, 166, 229) ? EN_B
86
-       : WITHIN(x, 242, 305) ? EN_C
87
-       : 0;
101
+  // Send the touch to the UI (which will simulate the encoder wheel)
102
+  MarlinUI::screen_click(row, col, x, y);
103
+  return 0;
88 104
 }
89 105
 
90 106
 bool XPT2046::isTouched() {

+ 23
- 0
Marlin/src/lcd/ultralcd.cpp 파일 보기

@@ -1438,6 +1438,29 @@ void MarlinUI::update() {
1438 1438
 
1439 1439
   #endif
1440 1440
 
1441
+  #if ENABLED(TOUCH_BUTTONS)
1442
+
1443
+    //
1444
+    // Screen Click
1445
+    //  - On menu screens move directly to the touched item
1446
+    //  - On menu screens, right side (last 3 cols) acts like a scroll - half up => prev page, half down = next page
1447
+    //  - On select screens (and others) touch the Right Half for +, Left Half for -
1448
+    //
1449
+    void MarlinUI::screen_click(const uint8_t row, const uint8_t col, const uint8_t x, const uint8_t y) {
1450
+      if (screen_items > 0) {
1451
+        //last 3 cols act as a scroll :-)
1452
+        if (col > (LCD_WIDTH) - 3)
1453
+          //2 * LCD_HEIGHT to scroll to bottom of next page. If we did 1 * LCD_HEIGHT, it just go 1 item down
1454
+          encoderDiff = ENCODER_PULSES_PER_STEP * (encoderLine - encoderTopLine + 2 * (LCD_HEIGHT)) * (row < (LCD_HEIGHT) / 2 ? -1 : 1);
1455
+        else
1456
+          encoderDiff = ENCODER_PULSES_PER_STEP * (row - encoderPosition + encoderTopLine);
1457
+      }
1458
+      else if (!on_status_screen())
1459
+        encoderDiff = ENCODER_PULSES_PER_STEP * (col < (LCD_WIDTH) / 2 ? -1 : 1);
1460
+    }
1461
+
1462
+  #endif
1463
+
1441 1464
 #else // !HAS_DISPLAY
1442 1465
 
1443 1466
   //

+ 4
- 0
Marlin/src/lcd/ultralcd.h 파일 보기

@@ -417,6 +417,10 @@ public:
417 417
         static void draw_hotend_status(const uint8_t row, const uint8_t extruder);
418 418
       #endif
419 419
 
420
+      #if ENABLED(TOUCH_BUTTONS)
421
+        static void screen_click(const uint8_t row, const uint8_t col, const uint8_t x, const uint8_t y);
422
+      #endif
423
+
420 424
       static void status_screen();
421 425
 
422 426
     #endif

Loading…
취소
저장