ソースを参照

Graphical TFT fixes, cleanup (#20861)

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
Tanguy Pruvot 3年前
コミット
c12be1f98c
コミッターのメールアドレスに関連付けられたアカウントが存在しません

+ 22
- 21
Marlin/src/inc/Conditionals_LCD.h ファイルの表示

@@ -1155,36 +1155,37 @@
1155 1155
   #endif
1156 1156
 #endif
1157 1157
 
1158
-#if ENABLED(TFT_COLOR_UI) && TFT_HEIGHT == 240
1159
-  #if ENABLED(TFT_INTERFACE_SPI)
1160
-    #define TFT_320x240_SPI
1161
-  #elif ENABLED(TFT_INTERFACE_FSMC)
1162
-    #define TFT_320x240
1163
-  #endif
1164
-#elif ENABLED(TFT_COLOR_UI) && TFT_HEIGHT == 320
1165
-  #if ENABLED(TFT_INTERFACE_SPI)
1166
-    #define TFT_480x320_SPI
1167
-  #elif ENABLED(TFT_INTERFACE_FSMC)
1168
-    #define TFT_480x320
1169
-  #endif
1170
-#elif ENABLED(TFT_COLOR_UI) && TFT_HEIGHT == 272
1171
-  #if ENABLED(TFT_INTERFACE_SPI)
1172
-    #define TFT_480x272_SPI
1173
-  #elif ENABLED(TFT_INTERFACE_FSMC)
1174
-    #define TFT_480x272
1158
+#if ENABLED(TFT_COLOR_UI)
1159
+  #if TFT_HEIGHT == 240
1160
+    #if ENABLED(TFT_INTERFACE_SPI)
1161
+      #define TFT_320x240_SPI
1162
+    #elif ENABLED(TFT_INTERFACE_FSMC)
1163
+      #define TFT_320x240
1164
+    #endif
1165
+  #elif TFT_HEIGHT == 320
1166
+    #if ENABLED(TFT_INTERFACE_SPI)
1167
+      #define TFT_480x320_SPI
1168
+    #elif ENABLED(TFT_INTERFACE_FSMC)
1169
+      #define TFT_480x320
1170
+    #endif
1171
+  #elif TFT_HEIGHT == 272
1172
+    #if ENABLED(TFT_INTERFACE_SPI)
1173
+      #define TFT_480x272_SPI
1174
+    #elif ENABLED(TFT_INTERFACE_FSMC)
1175
+      #define TFT_480x272
1176
+    #endif
1175 1177
   #endif
1176 1178
 #endif
1177 1179
 
1178
-// Fewer lines with touch buttons on-screen
1179 1180
 #if EITHER(TFT_320x240, TFT_320x240_SPI)
1180 1181
   #define HAS_UI_320x240 1
1181
-  #define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7)
1182 1182
 #elif EITHER(TFT_480x320, TFT_480x320_SPI)
1183 1183
   #define HAS_UI_480x320 1
1184
-  #define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7)
1185 1184
 #elif EITHER(TFT_480x272, TFT_480x272_SPI)
1186 1185
   #define HAS_UI_480x272 1
1187
-  #define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7)
1186
+#endif
1187
+#if ANY(HAS_UI_320x240, HAS_UI_480x320, HAS_UI_480x272)
1188
+  #define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7) // Fewer lines with touch buttons onscreen
1188 1189
 #endif
1189 1190
 
1190 1191
 // This emulated DOGM has 'touch/xpt2046', not 'tft/xpt2046'

+ 0
- 2
Marlin/src/inc/SanityCheck.h ファイルの表示

@@ -802,8 +802,6 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
802 802
     #if ENABLED(BABYSTEP_XY)
803 803
       static_assert(BABYSTEP_MULTIPLICATOR_XY <= 0.25f, "BABYSTEP_MULTIPLICATOR_XY must be less than or equal to 0.25mm.");
804 804
     #endif
805
-  #elif ENABLED(BABYSTEP_DISPLAY_TOTAL) && ANY(TFT_320x240, TFT_320x240_SPI, TFT_480x320, TFT_480x320_SPI)
806
-    #error "New Color UI (TFT_320x240, TFT_320x240_SPI, TFT_480x320, TFT_480x320_SPI) does not support BABYSTEP_DISPLAY_TOTAL yet."
807 805
   #endif
808 806
 #endif
809 807
 

+ 5
- 3
Marlin/src/lcd/menu/menu_bed_corners.cpp ファイルの表示

@@ -174,12 +174,13 @@ static inline void _lcd_level_bed_corners_get_next_position() {
174 174
 
175 175
     MenuItem_static::draw(0, GET_TEXT(MSG_PROBING_MESH), SS_INVERT); // "Probing Mesh" heading
176 176
 
177
-    uint8_t cy = LCD_HEIGHT - 1, y = LCD_ROW_Y(cy);
177
+    uint8_t cy = TERN(TFT_COLOR_UI, 3, LCD_HEIGHT - 1), y = LCD_ROW_Y(cy);
178 178
 
179 179
     // Display # of good points found vs total needed
180 180
     if (PAGE_CONTAINS(y - (MENU_FONT_HEIGHT), y)) {
181
-      SETCURSOR(0, cy);
181
+      SETCURSOR(TERN(TFT_COLOR_UI, 2, 0), cy);
182 182
       lcd_put_u8str_P(GET_TEXT(MSG_LEVEL_CORNERS_GOOD_POINTS));
183
+      IF_ENABLED(TFT_COLOR_UI, lcd_moveto(12, cy));
183 184
       lcd_put_u8str(GOOD_POINTS_TO_STR(good_points));
184 185
       lcd_put_wchar('/');
185 186
       lcd_put_u8str(GOOD_POINTS_TO_STR(nr_edge_points));
@@ -190,8 +191,9 @@ static inline void _lcd_level_bed_corners_get_next_position() {
190 191
 
191 192
     // Display the Last Z value
192 193
     if (PAGE_CONTAINS(y - (MENU_FONT_HEIGHT), y)) {
193
-      SETCURSOR(0, cy);
194
+      SETCURSOR(TERN(TFT_COLOR_UI, 2, 0), cy);
194 195
       lcd_put_u8str_P(GET_TEXT(MSG_LEVEL_CORNERS_LAST_Z));
196
+      IF_ENABLED(TFT_COLOR_UI, lcd_moveto(12, 2));
195 197
       lcd_put_u8str(LAST_Z_TO_STR(last_z));
196 198
     }
197 199
   }

+ 10
- 3
Marlin/src/lcd/menu/menu_tune.cpp ファイルの表示

@@ -71,9 +71,16 @@
71 71
         const bool in_view = TERN1(HAS_MARLINUI_U8GLIB, PAGE_CONTAINS(LCD_PIXEL_HEIGHT - MENU_FONT_HEIGHT, LCD_PIXEL_HEIGHT - 1));
72 72
         if (in_view) {
73 73
           TERN_(HAS_MARLINUI_U8GLIB, ui.set_font(FONT_MENU));
74
-          lcd_moveto(0, TERN(HAS_MARLINUI_U8GLIB, LCD_PIXEL_HEIGHT - MENU_FONT_DESCENT, LCD_HEIGHT - 1));
75
-          lcd_put_u8str_P(GET_TEXT(MSG_BABYSTEP_TOTAL));
76
-          lcd_put_wchar(':');
74
+          #if ENABLED(TFT_COLOR_UI)
75
+            lcd_moveto(4, 3);
76
+            lcd_put_u8str_P(GET_TEXT(MSG_BABYSTEP_TOTAL));
77
+            lcd_put_wchar(':');
78
+            lcd_moveto(10, 3);
79
+          #else
80
+            lcd_moveto(0, TERN(HAS_MARLINUI_U8GLIB, LCD_PIXEL_HEIGHT - MENU_FONT_DESCENT, LCD_HEIGHT - 1));
81
+            lcd_put_u8str_P(GET_TEXT(MSG_BABYSTEP_TOTAL));
82
+            lcd_put_wchar(':');
83
+          #endif
77 84
           lcd_put_u8str(BABYSTEP_TO_STR(spm * babystep.axis_total[BS_TOTAL_IND(axis)]));
78 85
         }
79 86
       #endif

+ 39
- 2
Marlin/src/lcd/tft/tft_image.cpp ファイルの表示

@@ -20,8 +20,11 @@
20 20
  *
21 21
  */
22 22
 
23
+#include "../../inc/MarlinConfigPre.h"
24
+
25
+#if HAS_GRAPHICAL_TFT
26
+
23 27
 #include "tft_image.h"
24
-#include <stddef.h>
25 28
 
26 29
 const tImage NoLogo                 = { nullptr, 0, 0, NOCOLORS };
27 30
 
@@ -70,4 +73,38 @@ const tImage Leveling_32x32x4       = { (void *)leveling_32x32x4, 32, 32, GREYSC
70 73
 
71 74
 const tImage Slider8x16x4           = { (void *)slider_8x16x4, 8, 16, GREYSCALE4 };
72 75
 
73
-extern const tImage Images[imgCount];
76
+const tImage Images[imgCount] = {
77
+  TERN(SHOW_BOOTSCREEN, TERN(BOOT_MARLIN_LOGO_SMALL, MarlinLogo195x59x16, MARLIN_LOGO_FULL_SIZE), NoLogo),
78
+  HotEnd_64x64x4,
79
+  Bed_64x64x4,
80
+  Bed_Heated_64x64x4,
81
+  Chamber_64x64x4,
82
+  Chamber_Heated_64x64x4,
83
+  Fan0_64x64x4,
84
+  Fan_Slow0_64x64x4,
85
+  Fan_Slow1_64x64x4,
86
+  Fan_Fast0_64x64x4,
87
+  Fan_Fast1_64x64x4,
88
+  Feedrate_32x32x4,
89
+  Flowrate_32x32x4,
90
+  SD_64x64x4,
91
+  Menu_64x64x4,
92
+  Settings_64x64x4,
93
+  Directory_32x32x4,
94
+  Confirm_64x64x4,
95
+  Cancel_64x64x4,
96
+  Increase_64x64x4,
97
+  Decrease_64x64x4,
98
+  Back_32x32x4,
99
+  Up_32x32x4,
100
+  Down_32x32x4,
101
+  Left_32x32x4,
102
+  Right_32x32x4,
103
+  Refresh_32x32x4,
104
+  Leveling_32x32x4,
105
+  Slider8x16x4,
106
+  Home_64x64x4,
107
+  BtnRounded_64x52x4,
108
+};
109
+
110
+#endif // HAS_GRAPHICAL_TFT

+ 2
- 1
Marlin/src/lcd/tft/tft_image.h ファイルの表示

@@ -21,9 +21,10 @@
21 21
  */
22 22
 #pragma once
23 23
 
24
-#include "stdint.h"
25 24
 #include "../../inc/MarlinConfigPre.h"
26 25
 
26
+#include <stdint.h>
27
+
27 28
 extern const uint8_t marlin_logo_112x38x1[];
28 29
 extern const uint8_t marlin_logo_228x255x2[];
29 30
 extern const uint8_t marlin_logo_228x255x4[];

+ 4
- 3
Marlin/src/lcd/tft/tft_string.cpp ファイルの表示

@@ -36,7 +36,7 @@ font_t *TFT_String::font_header;
36 36
 
37 37
 uint8_t TFT_String::data[];
38 38
 uint16_t TFT_String::span;
39
-uint16_t TFT_String::length;
39
+uint8_t TFT_String::length;
40 40
 
41 41
 void TFT_String::set_font(const uint8_t *font) {
42 42
   font_header = (font_t *)font;
@@ -122,13 +122,14 @@ void TFT_String::add(uint8_t *string, int8_t index, uint8_t *itemString) {
122 122
   eol();
123 123
 }
124 124
 
125
-void TFT_String::add(uint8_t *string) {
125
+void TFT_String::add(uint8_t *string, uint8_t max_len) {
126 126
   wchar_t wchar;
127
-  while (*string) {
127
+  while (*string && max_len) {
128 128
     string = get_utf8_value_cb(string, read_byte, &wchar);
129 129
     if (wchar > 255) wchar |= 0x0080;
130 130
     uint8_t ch = uint8_t(wchar & 0x00FF);
131 131
     add_character(ch);
132
+    max_len--;
132 133
   }
133 134
   eol();
134 135
 }

+ 5
- 2
Marlin/src/lcd/tft/tft_string.h ファイルの表示

@@ -69,7 +69,7 @@ class TFT_String {
69 69
 
70 70
     static uint8_t data[MAX_STRING_LENGTH + 1];
71 71
     static uint16_t span;   // in pixels
72
-    static uint16_t length; // in characters
72
+    static uint8_t length;  // in characters
73 73
 
74 74
     static void add_character(uint8_t character);
75 75
     static void eol() { data[length] = 0x00; }
@@ -85,7 +85,7 @@ class TFT_String {
85 85
 
86 86
     static void set();
87 87
     static void add(uint8_t character) { add_character(character); eol(); }
88
-    static void add(uint8_t *string);
88
+    static void add(uint8_t *string, uint8_t max_len=MAX_STRING_LENGTH);
89 89
     static void add(uint8_t *string, int8_t index, uint8_t *itemString=nullptr);
90 90
     static void set(uint8_t *string) { set(); add(string); };
91 91
     static void set(uint8_t *string, int8_t index, const char *itemString=nullptr) { set(); add(string, index, (uint8_t *)itemString); };
@@ -96,6 +96,9 @@ class TFT_String {
96 96
     static void trim(uint8_t character=0x20);
97 97
     static void rtrim(uint8_t character=0x20);
98 98
     static void ltrim(uint8_t character=0x20);
99
+
100
+    static void truncate(uint8_t maxlen) { if (length > maxlen) { length = maxlen; eol(); } }
101
+
99 102
     static uint16_t width() { return span; }
100 103
     static uint8_t *string() { return data; }
101 104
     static uint16_t center(uint16_t width) { return span > width ? 0 : (width - span) / 2; }

+ 37
- 214
Marlin/src/lcd/tft/ui_320x240.cpp ファイルの表示

@@ -24,7 +24,7 @@
24 24
 
25 25
 #if HAS_UI_320x240
26 26
 
27
-#include "ui_320x240.h"
27
+#include "ui_common.h"
28 28
 
29 29
 #include "../marlinui.h"
30 30
 #include "../menu/menu.h"
@@ -45,12 +45,6 @@
45 45
   #include "../../feature/bedlevel/bedlevel.h"
46 46
 #endif
47 47
 
48
-#if !HAS_LCD_MENU
49
-  #error "Seriously? High resolution TFT screen without menu?"
50
-#endif
51
-
52
-static bool draw_menu_navigation = false;
53
-
54 48
 void MarlinUI::tft_idle() {
55 49
   #if ENABLED(TOUCH_SCREEN)
56 50
     if (draw_menu_navigation) {
@@ -65,28 +59,6 @@ void MarlinUI::tft_idle() {
65 59
   TERN_(TOUCH_SCREEN, touch.idle());
66 60
 }
67 61
 
68
-void MarlinUI::init_lcd() {
69
-  tft.init();
70
-  tft.set_font(MENU_FONT_NAME);
71
-  #ifdef SYMBOLS_FONT_NAME
72
-    tft.add_glyphs(SYMBOLS_FONT_NAME);
73
-  #endif
74
-  TERN_(TOUCH_SCREEN, touch.init());
75
-  clear_lcd();
76
-}
77
-
78
-bool MarlinUI::detected() { return true; }
79
-
80
-void MarlinUI::clear_lcd() {
81
-  #if ENABLED(TOUCH_SCREEN)
82
-    touch.reset();
83
-    draw_menu_navigation = false;
84
-  #endif
85
-
86
-  tft.queue.reset();
87
-  tft.fill(0, 0, TFT_WIDTH, TFT_HEIGHT, COLOR_BACKGROUND);
88
-}
89
-
90 62
 #if ENABLED(SHOW_BOOTSCREEN)
91 63
   void MarlinUI::show_bootscreen() {
92 64
     tft.queue.reset();
@@ -98,8 +70,8 @@ void MarlinUI::clear_lcd() {
98 70
       #define SITE_URL_Y (TFT_HEIGHT - 46)
99 71
       tft.set_background(COLOR_BACKGROUND);
100 72
     #else
101
-      #define BOOT_LOGO_W 320   // MarlinLogo320x240x16
102
-      #define BOOT_LOGO_H 240
73
+      #define BOOT_LOGO_W TFT_WIDTH   // MarlinLogo320x240x16
74
+      #define BOOT_LOGO_H TFT_HEIGHT
103 75
       #define SITE_URL_Y (TFT_HEIGHT - 52)
104 76
     #endif
105 77
     tft.add_image((TFT_WIDTH - BOOT_LOGO_W) / 2, (TFT_HEIGHT - BOOT_LOGO_H) / 2, imgBootScreen);
@@ -148,22 +120,22 @@ void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater) {
148 120
     currentTemperature = thermalManager.degHotend(Heater);
149 121
     targetTemperature = thermalManager.degTargetHotend(Heater);
150 122
   }
151
-#if HAS_HEATED_BED
152
-  else if (Heater == H_BED) {
153
-    currentTemperature = thermalManager.degBed();
154
-    targetTemperature = thermalManager.degTargetBed();
155
-  }
156
-#endif // HAS_HEATED_BED
157
-#if HAS_TEMP_CHAMBER
158
-  else if (Heater == H_CHAMBER) {
159
-    currentTemperature = thermalManager.degChamber();
160
-    #if HAS_HEATED_CHAMBER
161
-      targetTemperature = thermalManager.degTargetChamber();
162
-    #else
163
-      targetTemperature = ABSOLUTE_ZERO;
164
-    #endif
165
-  }
166
-#endif // HAS_TEMP_CHAMBER
123
+  #if HAS_HEATED_BED
124
+    else if (Heater == H_BED) {
125
+      currentTemperature = thermalManager.degBed();
126
+      targetTemperature = thermalManager.degTargetBed();
127
+    }
128
+  #endif
129
+  #if HAS_TEMP_CHAMBER
130
+    else if (Heater == H_CHAMBER) {
131
+      currentTemperature = thermalManager.degChamber();
132
+      #if HAS_HEATED_CHAMBER
133
+        targetTemperature = thermalManager.degTargetChamber();
134
+      #else
135
+        targetTemperature = ABSOLUTE_ZERO;
136
+      #endif
137
+    }
138
+  #endif
167 139
   else return;
168 140
 
169 141
   TERN_(TOUCH_SCREEN, if (targetTemperature >= 0) touch.add_control(HEATER, x, y, 64, 100, Heater));
@@ -176,17 +148,17 @@ void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater) {
176 148
     if (currentTemperature >= 50) Color = COLOR_HOTEND;
177 149
   }
178 150
   #if HAS_HEATED_BED
179
-  else if (Heater == H_BED) {
180
-    if (currentTemperature >= 50) Color = COLOR_HEATED_BED;
181
-    image = targetTemperature > 0 ? imgBedHeated : imgBed;
182
-  }
183
-  #endif // HAS_HEATED_BED
151
+    else if (Heater == H_BED) {
152
+      if (currentTemperature >= 50) Color = COLOR_HEATED_BED;
153
+      image = targetTemperature > 0 ? imgBedHeated : imgBed;
154
+    }
155
+  #endif
184 156
   #if HAS_TEMP_CHAMBER
185
-  else if (Heater == H_CHAMBER) {
186
-    if (currentTemperature >= 50) Color = COLOR_CHAMBER;
187
-    image = targetTemperature > 0 ? imgChamberHeated : imgChamber;
188
-  }
189
-  #endif // HAS_TEMP_CHAMBER
157
+    else if (Heater == H_CHAMBER) {
158
+      if (currentTemperature >= 50) Color = COLOR_CHAMBER;
159
+      image = targetTemperature > 0 ? imgChamberHeated : imgChamber;
160
+    }
161
+  #endif
190 162
 
191 163
   tft.add_image(0, 18, image, Color);
192 164
 
@@ -200,7 +172,6 @@ void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater) {
200 172
     tft_string.add(LCD_STR_DEGREE);
201 173
     tft_string.trim();
202 174
     tft.add_text(tft_string.center(64) + 2, 8, Color, tft_string);
203
-
204 175
   }
205 176
 }
206 177
 
@@ -232,7 +203,7 @@ void MarlinUI::draw_status_screen() {
232 203
   TERN_(TOUCH_SCREEN, touch.clear());
233 204
 
234 205
   // heaters and fan
235
-  uint16_t i, x, y = POS_Y;
206
+  uint16_t i, x, y = TFT_STATUS_TOP_Y;
236 207
 
237 208
   for (i = 0 ; i < ITEMS_COUNT; i++) {
238 209
     x = (320 / ITEMS_COUNT - 64) / 2  + (320 * i / ITEMS_COUNT);
@@ -341,49 +312,6 @@ void MarlinUI::draw_status_screen() {
341 312
   #endif
342 313
 }
343 314
 
344
-// Draw a static item with no left-right margin required. Centered by default.
345
-void MenuItem_static::draw(const uint8_t row, PGM_P const pstr, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) {
346
-  menu_item(row);
347
-  tft_string.set(pstr, itemIndex, itemString);
348
-  if (vstr)
349
-    tft_string.add(vstr);
350
-  tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_YELLOW, tft_string);
351
-}
352
-
353
-// Draw a generic menu item with pre_char (if selected) and post_char
354
-void MenuItemBase::_draw(const bool sel, const uint8_t row, PGM_P const pstr, const char pre_char, const char post_char) {
355
-  menu_item(row, sel);
356
-
357
-  uint8_t *string = (uint8_t *)pstr;
358
-  MarlinImage image = noImage;
359
-  switch (*string) {
360
-    case 0x01: image = imgRefresh; break;  // LCD_STR_REFRESH
361
-    case 0x02: image = imgDirectory; break;  // LCD_STR_FOLDER
362
-  }
363
-
364
-  uint8_t offset = MENU_TEXT_X_OFFSET;
365
-  if (image != noImage) {
366
-    string++;
367
-    offset = 32;
368
-    tft.add_image(0, 0, image, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND);
369
-  }
370
-
371
-  tft_string.set(string, itemIndex, itemString);
372
-  tft.add_text(offset, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
373
-}
374
-
375
-// Draw a menu item with a (potentially) editable value
376
-void MenuEditItemBase::draw(const bool sel, const uint8_t row, PGM_P const pstr, const char* const data, const bool pgm) {
377
-  menu_item(row, sel);
378
-
379
-  tft_string.set(pstr, itemIndex, itemString);
380
-  tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
381
-  if (data) {
382
-    tft_string.set(data);
383
-    tft.add_text(TFT_WIDTH - MENU_TEXT_X_OFFSET - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
384
-  }
385
-}
386
-
387 315
 // Low-level draw_edit_screen can be used to draw an edit screen from anyplace
388 316
 void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char* const value/*=nullptr*/) {
389 317
   ui.encoder_direction_normal();
@@ -483,16 +411,8 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
483 411
   #endif
484 412
 }
485 413
 
486
-#if ENABLED(SDSUPPORT)
487
-  void MenuItem_sdbase::draw(const bool sel, const uint8_t row, PGM_P const, CardReader &theCard, const bool isDir) {
488
-    menu_item(row, sel);
489
-    if (isDir)
490
-      tft.add_image(0, 0, imgDirectory, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND);
491
-    tft.add_text(32, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, theCard.longest_filename());
492
-  }
493
-#endif
494
-
495 414
 #if ENABLED(ADVANCED_PAUSE_FEATURE)
415
+
496 416
   void MarlinUI::draw_hotend_status(const uint8_t row, const uint8_t extruder) {
497 417
     #if ENABLED(TOUCH_SCREEN)
498 418
       touch.clear();
@@ -513,6 +433,7 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
513 433
     tft_string.trim();
514 434
     tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
515 435
   }
436
+
516 437
 #endif // ADVANCED_PAUSE_FEATURE
517 438
 
518 439
 #if ENABLED(AUTO_BED_LEVELING_UBL)
@@ -562,18 +483,18 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
562 483
     tft_string.trim();
563 484
     tft.add_text(96 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
564 485
 
565
-
566
-    tft.canvas(GRID_OFFSET_X + (GRID_WIDTH - 32) / 2, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET - 1, 32, 32);
486
+    constexpr uint8_t w = (TFT_WIDTH) / 10;
487
+    tft.canvas(GRID_OFFSET_X + (GRID_WIDTH - w) / 2, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET - 1, w, 32);
567 488
     tft.set_background(COLOR_BACKGROUND);
568 489
     tft_string.set(ui8tostr3rj(x_plot));
569 490
     tft_string.trim();
570
-    tft.add_text(tft_string.center(32), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
491
+    tft.add_text(tft_string.center(w), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
571 492
 
572
-    tft.canvas(GRID_OFFSET_X + GRID_WIDTH + CONTROL_OFFSET, GRID_OFFSET_Y + (GRID_HEIGHT - 27) / 2, 32, 32);
493
+    tft.canvas(GRID_OFFSET_X + GRID_WIDTH + CONTROL_OFFSET, GRID_OFFSET_Y + (GRID_HEIGHT - 27) / 2, w, 32);
573 494
     tft.set_background(COLOR_BACKGROUND);
574 495
     tft_string.set(ui8tostr3rj(y_plot));
575 496
     tft_string.trim();
576
-    tft.add_text(tft_string.center(32), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
497
+    tft.add_text(tft_string.center(w), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
577 498
 
578 499
     #if ENABLED(TOUCH_SCREEN)
579 500
       touch.clear();
@@ -588,104 +509,6 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
588 509
   }
589 510
 #endif // AUTO_BED_LEVELING_UBL
590 511
 
591
-#if ENABLED(TOUCH_SCREEN_CALIBRATION)
592
-  void MarlinUI::touch_calibration_screen() {
593
-    uint16_t x, y;
594
-
595
-    calibrationState calibration_stage = touch_calibration.get_calibration_state();
596
-
597
-    if (calibration_stage == CALIBRATION_NONE) {
598
-      defer_status_screen(true);
599
-      clear_lcd();
600
-      calibration_stage = touch_calibration.calibration_start();
601
-    }
602
-    else {
603
-      x = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].x;
604
-      y = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].y;
605
-      tft.canvas(x - 15, y - 15, 31, 31);
606
-      tft.set_background(COLOR_BACKGROUND);
607
-    }
608
-
609
-    touch.clear();
610
-
611
-    if (calibration_stage < CALIBRATION_SUCCESS) {
612
-      switch (calibration_stage) {
613
-        case CALIBRATION_TOP_LEFT: tft_string.set(GET_TEXT(MSG_TOP_LEFT)); break;
614
-        case CALIBRATION_BOTTOM_LEFT: tft_string.set(GET_TEXT(MSG_BOTTOM_LEFT)); break;
615
-        case CALIBRATION_TOP_RIGHT: tft_string.set(GET_TEXT(MSG_TOP_RIGHT)); break;
616
-        case CALIBRATION_BOTTOM_RIGHT: tft_string.set(GET_TEXT(MSG_BOTTOM_RIGHT)); break;
617
-        default: break;
618
-      }
619
-
620
-      x = touch_calibration.calibration_points[calibration_stage].x;
621
-      y = touch_calibration.calibration_points[calibration_stage].y;
622
-
623
-      tft.canvas(x - 15, y - 15, 31, 31);
624
-      tft.set_background(COLOR_BACKGROUND);
625
-      tft.add_bar(0, 15, 31, 1, COLOR_TOUCH_CALIBRATION);
626
-      tft.add_bar(15, 0, 1, 31, COLOR_TOUCH_CALIBRATION);
627
-
628
-      touch.add_control(CALIBRATE, 0, 0, TFT_WIDTH, TFT_HEIGHT, uint32_t(x) << 16 | uint32_t(y));
629
-    }
630
-    else {
631
-      tft_string.set(calibration_stage == CALIBRATION_SUCCESS ? GET_TEXT(MSG_CALIBRATION_COMPLETED) : GET_TEXT(MSG_CALIBRATION_FAILED));
632
-      defer_status_screen(false);
633
-      touch_calibration.calibration_end();
634
-      touch.add_control(BACK, 0, 0, TFT_WIDTH, TFT_HEIGHT);
635
-    }
636
-
637
-    tft.canvas(0, (TFT_HEIGHT - tft_string.font_height()) >> 1, TFT_WIDTH, tft_string.font_height());
638
-    tft.set_background(COLOR_BACKGROUND);
639
-    tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_MENU_TEXT, tft_string);
640
-  }
641
-#endif // TOUCH_SCREEN_CALIBRATION
642
-
643
-void menu_line(const uint8_t row, uint16_t color) {
644
-  tft.canvas(0, 2 + 34 * row, TFT_WIDTH, 32);
645
-  tft.set_background(color);
646
-}
647
-
648
-void menu_pause_option();
649
-
650
-void menu_item(const uint8_t row, bool sel ) {
651
-  #if ENABLED(TOUCH_SCREEN)
652
-    if (row == 0) {
653
-      touch.clear();
654
-      draw_menu_navigation = TERN(ADVANCED_PAUSE_FEATURE, ui.currentScreen != menu_pause_option, true);
655
-    }
656
-  #endif
657
-
658
-  menu_line(row, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND);
659
-  #if ENABLED(TOUCH_SCREEN)
660
-    const TouchControlType tct = TERN(SINGLE_TOUCH_NAVIGATION, true, sel) ? MENU_CLICK : MENU_ITEM;
661
-    touch.add_control(tct, 0, 2 + 34 * row, TFT_WIDTH, 32, encoderTopLine + row);
662
-  #endif
663
-}
664
-
665
-void lcd_moveto(const lcd_uint_t col, const lcd_uint_t row) {
666
-  #define TFT_COL_WIDTH ((TFT_WIDTH) / (LCD_WIDTH))
667
-  tft.canvas(col * TFT_COL_WIDTH, 4 + 45 * row, TFT_WIDTH - (col * TFT_COL_WIDTH), 43);
668
-  tft.set_background(COLOR_BACKGROUND);
669
-}
670
-
671
-int lcd_put_wchar_max(wchar_t c, pixel_len_t max_length) {
672
-  tft_string.set();
673
-  tft_string.add(c);
674
-  tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
675
-  return tft_string.width();
676
-}
677
-
678
-int lcd_put_u8str_max_P(PGM_P utf8_str_P, pixel_len_t max_length) {
679
-  tft_string.set(utf8_str_P);
680
-  tft_string.trim();
681
-  tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
682
-  return tft_string.width();
683
-}
684
-
685
-int lcd_put_u8str_max(const char * utf8_str, pixel_len_t max_length) {
686
-  return lcd_put_u8str_max_P(utf8_str, max_length);
687
-}
688
-
689 512
 void MarlinUI::move_axis_screen() {
690 513
 }
691 514
 

+ 13
- 79
Marlin/src/lcd/tft/ui_320x240.h ファイルの表示

@@ -21,88 +21,22 @@
21 21
  */
22 22
 #pragma once
23 23
 
24
-#include "../../inc/MarlinConfigPre.h"
24
+#define MARLIN_LOGO_FULL_SIZE MarlinLogo320x240x16
25 25
 
26
-#include "tft.h"
27
-#include "tft_image.h"
26
+#define TFT_STATUS_TOP_Y       0
27
+#define TFT_TOP_LINE_Y         2
28 28
 
29
-#if ENABLED(TOUCH_SCREEN)
30
-  #include "touch.h"
31
-#endif
29
+#define MENU_TEXT_X_OFFSET    10
30
+#define MENU_TEXT_Y_OFFSET     7
32 31
 
33
-void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater);
34
-void draw_fan_status(uint16_t x, uint16_t y, const bool blink);
32
+#define MENU_ITEM_ICON_X       0
33
+#define MENU_ITEM_ICON_Y       0
34
+#define MENU_ITEM_ICON_SPACE  32
35 35
 
36
-#define MENU_TEXT_X_OFFSET  10
37
-#define MENU_TEXT_Y_OFFSET   7
38
-void menu_line(const uint8_t row, uint16_t color = COLOR_BACKGROUND);
39
-void menu_item(const uint8_t row, bool sel = false);
36
+#define MENU_ITEM_HEIGHT      32
37
+#define MENU_LINE_HEIGHT      (MENU_ITEM_HEIGHT + 2)
40 38
 
41
-#define MENU_FONT_NAME    Helvetica14
42
-#define SYMBOLS_FONT_NAME Helvetica14_symbols
39
+#define MENU_FONT_NAME        Helvetica14
40
+#define SYMBOLS_FONT_NAME     Helvetica14_symbols
43 41
 
44
-#define ABSOLUTE_ZERO     -273.15
45
-
46
-const tImage Images[imgCount] = {
47
-  TERN(SHOW_BOOTSCREEN, TERN(BOOT_MARLIN_LOGO_SMALL, MarlinLogo195x59x16, MarlinLogo320x240x16), NoLogo),
48
-  HotEnd_64x64x4,
49
-  Bed_64x64x4,
50
-  Bed_Heated_64x64x4,
51
-  Chamber_64x64x4,
52
-  Chamber_Heated_64x64x4,
53
-  Fan0_64x64x4,
54
-  Fan_Slow0_64x64x4,
55
-  Fan_Slow1_64x64x4,
56
-  Fan_Fast0_64x64x4,
57
-  Fan_Fast1_64x64x4,
58
-  Feedrate_32x32x4,
59
-  Flowrate_32x32x4,
60
-  SD_64x64x4,
61
-  Menu_64x64x4,
62
-  Settings_64x64x4,
63
-  Directory_32x32x4,
64
-  Confirm_64x64x4,
65
-  Cancel_64x64x4,
66
-  Increase_64x64x4,
67
-  Decrease_64x64x4,
68
-  Back_32x32x4,
69
-  Up_32x32x4,
70
-  Down_32x32x4,
71
-  Left_32x32x4,
72
-  Right_32x32x4,
73
-  Refresh_32x32x4,
74
-  Leveling_32x32x4,
75
-  Slider8x16x4,
76
-  Home_64x64x4,
77
-  BtnRounded_64x52x4,
78
-};
79
-
80
-#if HAS_TEMP_CHAMBER && HOTENDS > 1
81
-  #define ITEM_E0         0
82
-  #define ITEM_E1         1
83
-  #define ITEM_BED        2
84
-  #define ITEM_CHAMBER    3
85
-  #define ITEM_FAN        4
86
-  #define ITEMS_COUNT     5
87
-  #define POS_Y           0
88
-#elif HAS_TEMP_CHAMBER
89
-  #define ITEM_E0         0
90
-  #define ITEM_BED        1
91
-  #define ITEM_CHAMBER    2
92
-  #define ITEM_FAN        3
93
-  #define ITEMS_COUNT     4
94
-  #define POS_Y           0
95
-#elif HOTENDS > 1
96
-  #define ITEM_E0         0
97
-  #define ITEM_E1         1
98
-  #define ITEM_BED        2
99
-  #define ITEM_FAN        3
100
-  #define ITEMS_COUNT     4
101
-  #define POS_Y           0
102
-#else
103
-  #define ITEM_E0         0
104
-  #define ITEM_BED        1
105
-  #define ITEM_FAN        2
106
-  #define ITEMS_COUNT     3
107
-  #define POS_Y           0
108
-#endif
42
+#include "ui_common.h"

+ 49
- 242
Marlin/src/lcd/tft/ui_480x320.cpp ファイルの表示

@@ -24,7 +24,7 @@
24 24
 
25 25
 #if HAS_UI_480x320 || HAS_UI_480x272
26 26
 
27
-#include "ui_480x320.h"
27
+#include "ui_common.h"
28 28
 
29 29
 #include "../marlinui.h"
30 30
 #include "../menu/menu.h"
@@ -45,14 +45,6 @@
45 45
   #include "../../feature/bedlevel/bedlevel.h"
46 46
 #endif
47 47
 
48
-#if !HAS_LCD_MENU
49
-  #error "Seriously? High resolution TFT screen without menu?"
50
-#endif
51
-
52
-#if ENABLED(TOUCH_SCREEN)
53
-  static bool draw_menu_navigation = false;
54
-#endif
55
-
56 48
 void MarlinUI::tft_idle() {
57 49
   #if ENABLED(TOUCH_SCREEN)
58 50
     if (draw_menu_navigation) {
@@ -67,28 +59,6 @@ void MarlinUI::tft_idle() {
67 59
   TERN_(TOUCH_SCREEN, touch.idle());
68 60
 }
69 61
 
70
-void MarlinUI::init_lcd() {
71
-  tft.init();
72
-  tft.set_font(MENU_FONT_NAME);
73
-  #ifdef SYMBOLS_FONT_NAME
74
-    tft.add_glyphs(SYMBOLS_FONT_NAME);
75
-  #endif
76
-  TERN_(TOUCH_SCREEN, touch.init());
77
-  clear_lcd();
78
-}
79
-
80
-bool MarlinUI::detected() { return true; }
81
-
82
-void MarlinUI::clear_lcd() {
83
-  #if ENABLED(TOUCH_SCREEN)
84
-    touch.reset();
85
-    draw_menu_navigation = false;
86
-  #endif
87
-
88
-  tft.queue.reset();
89
-  tft.fill(0, 0, TFT_WIDTH, TFT_HEIGHT, COLOR_BACKGROUND);
90
-}
91
-
92 62
 #if ENABLED(SHOW_BOOTSCREEN)
93 63
   void MarlinUI::show_bootscreen() {
94 64
     tft.queue.reset();
@@ -100,8 +70,8 @@ void MarlinUI::clear_lcd() {
100 70
       #define SITE_URL_Y (TFT_HEIGHT - 70)
101 71
       tft.set_background(COLOR_BACKGROUND);
102 72
     #else
103
-      #define BOOT_LOGO_W 480   // MarlinLogo480x320x16
104
-      #define BOOT_LOGO_H 320
73
+      #define BOOT_LOGO_W TFT_WIDTH   // MarlinLogo480x320x16
74
+      #define BOOT_LOGO_H TFT_HEIGHT
105 75
       #define SITE_URL_Y (TFT_HEIGHT - 90)
106 76
     #endif
107 77
     tft.add_image((TFT_WIDTH - BOOT_LOGO_W) / 2, (TFT_HEIGHT - BOOT_LOGO_H) / 2, imgBootScreen);
@@ -150,22 +120,22 @@ void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater) {
150 120
     currentTemperature = thermalManager.degHotend(Heater);
151 121
     targetTemperature = thermalManager.degTargetHotend(Heater);
152 122
   }
153
-#if HAS_HEATED_BED
154
-  else if (Heater == H_BED) {
155
-    currentTemperature = thermalManager.degBed();
156
-    targetTemperature = thermalManager.degTargetBed();
157
-  }
158
-#endif // HAS_HEATED_BED
159
-#if HAS_TEMP_CHAMBER
160
-  else if (Heater == H_CHAMBER) {
161
-    currentTemperature = thermalManager.degChamber();
162
-    #if HAS_HEATED_CHAMBER
163
-      targetTemperature = thermalManager.degTargetChamber();
164
-    #else
165
-      targetTemperature = ABSOLUTE_ZERO;
166
-    #endif
167
-  }
168
-#endif // HAS_TEMP_CHAMBER
123
+  #if HAS_HEATED_BED
124
+    else if (Heater == H_BED) {
125
+      currentTemperature = thermalManager.degBed();
126
+      targetTemperature = thermalManager.degTargetBed();
127
+    }
128
+  #endif
129
+  #if HAS_TEMP_CHAMBER
130
+    else if (Heater == H_CHAMBER) {
131
+      currentTemperature = thermalManager.degChamber();
132
+      #if HAS_HEATED_CHAMBER
133
+        targetTemperature = thermalManager.degTargetChamber();
134
+      #else
135
+        targetTemperature = ABSOLUTE_ZERO;
136
+      #endif
137
+    }
138
+  #endif
169 139
   else return;
170 140
 
171 141
   TERN_(TOUCH_SCREEN, if (targetTemperature >= 0) touch.add_control(HEATER, x, y, 80, 120, Heater));
@@ -178,17 +148,17 @@ void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater) {
178 148
     if (currentTemperature >= 50) Color = COLOR_HOTEND;
179 149
   }
180 150
   #if HAS_HEATED_BED
181
-  else if (Heater == H_BED) {
182
-    if (currentTemperature >= 50) Color = COLOR_HEATED_BED;
183
-    image = targetTemperature > 0 ? imgBedHeated : imgBed;
184
-  }
185
-  #endif // HAS_HEATED_BED
151
+    else if (Heater == H_BED) {
152
+      if (currentTemperature >= 50) Color = COLOR_HEATED_BED;
153
+      image = targetTemperature > 0 ? imgBedHeated : imgBed;
154
+    }
155
+  #endif
186 156
   #if HAS_TEMP_CHAMBER
187
-  else if (Heater == H_CHAMBER) {
188
-    if (currentTemperature >= 50) Color = COLOR_CHAMBER;
189
-    image = targetTemperature > 0 ? imgChamberHeated : imgChamber;
190
-  }
191
-  #endif // HAS_TEMP_CHAMBER
157
+    else if (Heater == H_CHAMBER) {
158
+      if (currentTemperature >= 50) Color = COLOR_CHAMBER;
159
+      image = targetTemperature > 0 ? imgChamberHeated : imgChamber;
160
+    }
161
+  #endif
192 162
 
193 163
   tft.add_image(8, 28, image, Color);
194 164
 
@@ -233,7 +203,7 @@ void MarlinUI::draw_status_screen() {
233 203
   TERN_(TOUCH_SCREEN, touch.clear());
234 204
 
235 205
   // heaters and fan
236
-  uint16_t i, x, y = POS_Y;
206
+  uint16_t i, x, y = TFT_STATUS_TOP_Y;
237 207
 
238 208
   for (i = 0 ; i < ITEMS_COUNT; i++) {
239 209
     x = (TFT_WIDTH / ITEMS_COUNT - 80) / 2  + (TFT_WIDTH * i / ITEMS_COUNT);
@@ -349,49 +319,6 @@ void MarlinUI::draw_status_screen() {
349 319
   tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_STATUS_MESSAGE, tft_string);
350 320
 }
351 321
 
352
-// Draw a static item with no left-right margin required. Centered by default.
353
-void MenuItem_static::draw(const uint8_t row, PGM_P const pstr, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) {
354
-  menu_item(row);
355
-  tft_string.set(pstr, itemIndex, itemString);
356
-  if (vstr)
357
-    tft_string.add(vstr);
358
-  tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_YELLOW, tft_string);
359
-}
360
-
361
-// Draw a generic menu item with pre_char (if selected) and post_char
362
-void MenuItemBase::_draw(const bool sel, const uint8_t row, PGM_P const pstr, const char pre_char, const char post_char) {
363
-  menu_item(row, sel);
364
-
365
-  uint8_t *string = (uint8_t *)pstr;
366
-  MarlinImage image = noImage;
367
-  switch (*string) {
368
-    case 0x01: image = imgRefresh; break;  // LCD_STR_REFRESH
369
-    case 0x02: image = imgDirectory; break;  // LCD_STR_FOLDER
370
-  }
371
-
372
-  uint8_t offset = MENU_TEXT_X_OFFSET;
373
-  if (image != noImage) {
374
-    string++;
375
-    offset = 42;
376
-    tft.add_image(5, 5, image, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND);
377
-  }
378
-
379
-  tft_string.set(string, itemIndex, itemString);
380
-  tft.add_text(offset, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
381
-}
382
-
383
-// Draw a menu item with a (potentially) editable value
384
-void MenuEditItemBase::draw(const bool sel, const uint8_t row, PGM_P const pstr, const char* const data, const bool pgm) {
385
-  menu_item(row, sel);
386
-
387
-  tft_string.set(pstr, itemIndex, itemString);
388
-  tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
389
-  if (data) {
390
-    tft_string.set(data);
391
-    tft.add_text(TFT_WIDTH - MENU_TEXT_X_OFFSET - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
392
-  }
393
-}
394
-
395 322
 // Low-level draw_edit_screen can be used to draw an edit screen from anyplace
396 323
 void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char* const value/*=nullptr*/) {
397 324
   ui.encoder_direction_normal();
@@ -491,16 +418,8 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
491 418
   #endif
492 419
 }
493 420
 
494
-#if ENABLED(SDSUPPORT)
495
-  void MenuItem_sdbase::draw(const bool sel, const uint8_t row, PGM_P const, CardReader &theCard, const bool isDir) {
496
-    menu_item(row, sel);
497
-    if (isDir)
498
-      tft.add_image(5, 5, imgDirectory, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND);
499
-    tft.add_text(42, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, theCard.longest_filename());
500
-  }
501
-#endif
502
-
503 421
 #if ENABLED(ADVANCED_PAUSE_FEATURE)
422
+
504 423
   void MarlinUI::draw_hotend_status(const uint8_t row, const uint8_t extruder) {
505 424
     #if ENABLED(TOUCH_SCREEN)
506 425
       touch.clear();
@@ -521,6 +440,7 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
521 440
     tft_string.trim();
522 441
     tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_MENU_TEXT, tft_string);
523 442
   }
443
+
524 444
 #endif // ADVANCED_PAUSE_FEATURE
525 445
 
526 446
 #if ENABLED(AUTO_BED_LEVELING_UBL)
@@ -570,18 +490,18 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
570 490
     tft_string.trim();
571 491
     tft.add_text(120 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
572 492
 
573
-
574
-    tft.canvas(GRID_OFFSET_X + (GRID_WIDTH - 48) / 2, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET - 5, 48, MENU_ITEM_HEIGHT);
493
+    constexpr uint8_t w = (TFT_WIDTH) / 10;
494
+    tft.canvas(GRID_OFFSET_X + (GRID_WIDTH - w) / 2, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET - 5, w, MENU_ITEM_HEIGHT);
575 495
     tft.set_background(COLOR_BACKGROUND);
576 496
     tft_string.set(ui8tostr3rj(x_plot));
577 497
     tft_string.trim();
578
-    tft.add_text(tft_string.center(48), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
498
+    tft.add_text(tft_string.center(w), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
579 499
 
580
-    tft.canvas(GRID_OFFSET_X + GRID_WIDTH + CONTROL_OFFSET + 16 - 24, GRID_OFFSET_Y + (GRID_HEIGHT - MENU_ITEM_HEIGHT) / 2, 48, MENU_ITEM_HEIGHT);
500
+    tft.canvas(GRID_OFFSET_X + GRID_WIDTH + CONTROL_OFFSET + 16 - 24, GRID_OFFSET_Y + (GRID_HEIGHT - MENU_ITEM_HEIGHT) / 2, w, MENU_ITEM_HEIGHT);
581 501
     tft.set_background(COLOR_BACKGROUND);
582 502
     tft_string.set(ui8tostr3rj(y_plot));
583 503
     tft_string.trim();
584
-    tft.add_text(tft_string.center(48), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
504
+    tft.add_text(tft_string.center(w), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
585 505
 
586 506
     #if ENABLED(TOUCH_SCREEN)
587 507
       touch.clear();
@@ -596,97 +516,6 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const
596 516
   }
597 517
 #endif // AUTO_BED_LEVELING_UBL
598 518
 
599
-#if ENABLED(TOUCH_SCREEN_CALIBRATION)
600
-  void MarlinUI::touch_calibration_screen() {
601
-    uint16_t x, y;
602
-
603
-    calibrationState calibration_stage = touch_calibration.get_calibration_state();
604
-
605
-    if (calibration_stage == CALIBRATION_NONE) {
606
-      defer_status_screen(true);
607
-      clear_lcd();
608
-      calibration_stage = touch_calibration.calibration_start();
609
-    }
610
-    else {
611
-      x = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].x;
612
-      y = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].y;
613
-      tft.canvas(x - 15, y - 15, 31, 31);
614
-      tft.set_background(COLOR_BACKGROUND);
615
-    }
616
-
617
-    touch.clear();
618
-
619
-    if (calibration_stage < CALIBRATION_SUCCESS) {
620
-      switch (calibration_stage) {
621
-        case CALIBRATION_TOP_LEFT: tft_string.set(GET_TEXT(MSG_TOP_LEFT)); break;
622
-        case CALIBRATION_BOTTOM_LEFT: tft_string.set(GET_TEXT(MSG_BOTTOM_LEFT)); break;
623
-        case CALIBRATION_TOP_RIGHT: tft_string.set(GET_TEXT(MSG_TOP_RIGHT)); break;
624
-        case CALIBRATION_BOTTOM_RIGHT: tft_string.set(GET_TEXT(MSG_BOTTOM_RIGHT)); break;
625
-        default: break;
626
-      }
627
-
628
-      x = touch_calibration.calibration_points[calibration_stage].x;
629
-      y = touch_calibration.calibration_points[calibration_stage].y;
630
-
631
-      tft.canvas(x - 15, y - 15, 31, 31);
632
-      tft.set_background(COLOR_BACKGROUND);
633
-      tft.add_bar(0, 15, 31, 1, COLOR_TOUCH_CALIBRATION);
634
-      tft.add_bar(15, 0, 1, 31, COLOR_TOUCH_CALIBRATION);
635
-
636
-      touch.add_control(CALIBRATE, 0, 0, TFT_WIDTH, TFT_HEIGHT, uint32_t(x) << 16 | uint32_t(y));
637
-    }
638
-    else {
639
-      tft_string.set(calibration_stage == CALIBRATION_SUCCESS ? GET_TEXT(MSG_CALIBRATION_COMPLETED) : GET_TEXT(MSG_CALIBRATION_FAILED));
640
-      defer_status_screen(false);
641
-      touch_calibration.calibration_end();
642
-      touch.add_control(BACK, 0, 0, TFT_WIDTH, TFT_HEIGHT);
643
-    }
644
-
645
-    tft.canvas(0, (TFT_HEIGHT - tft_string.font_height()) >> 1, TFT_WIDTH, tft_string.font_height());
646
-    tft.set_background(COLOR_BACKGROUND);
647
-    tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_MENU_TEXT, tft_string);
648
-  }
649
-#endif // TOUCH_SCREEN_CALIBRATION
650
-
651
-void menu_line(const uint8_t row, uint16_t color) {
652
-  tft.canvas(0, 4 + (MENU_ITEM_HEIGHT + 2) * row, TFT_WIDTH, MENU_ITEM_HEIGHT);
653
-  tft.set_background(color);
654
-}
655
-
656
-void menu_pause_option();
657
-
658
-void menu_item(const uint8_t row, bool sel ) {
659
-  #if ENABLED(TOUCH_SCREEN)
660
-    if (row == 0) {
661
-      touch.clear();
662
-      draw_menu_navigation = TERN(ADVANCED_PAUSE_FEATURE, ui.currentScreen != menu_pause_option, true);
663
-    }
664
-  #endif
665
-
666
-  menu_line(row, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND);
667
-  #if ENABLED(TOUCH_SCREEN)
668
-    const TouchControlType tct = TERN(SINGLE_TOUCH_NAVIGATION, true, sel) ? MENU_CLICK : MENU_ITEM;
669
-    touch.add_control(tct, 0, 4 + (MENU_ITEM_HEIGHT + 2) * row, TFT_WIDTH, MENU_ITEM_HEIGHT, encoderTopLine + row);
670
-  #endif
671
-}
672
-
673
-void lcd_moveto(const lcd_uint_t col, const lcd_uint_t row) {
674
-  #define TFT_COL_WIDTH ((TFT_WIDTH) / (LCD_WIDTH))
675
-  tft.canvas(col * TFT_COL_WIDTH, 4 + 45 * row, TFT_WIDTH - (col * TFT_COL_WIDTH), 43);
676
-  tft.set_background(COLOR_BACKGROUND);
677
-}
678
-
679
-int lcd_put_u8str_max_P(PGM_P utf8_str_P, pixel_len_t max_length) {
680
-  tft_string.set(utf8_str_P);
681
-  tft_string.trim();
682
-  tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
683
-  return tft_string.width();
684
-}
685
-
686
-int lcd_put_u8str_max(const char * utf8_str, pixel_len_t max_length) {
687
-  return lcd_put_u8str_max_P(utf8_str, max_length);
688
-}
689
-
690 519
 #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
691 520
   #include "../../feature/babystep.h"
692 521
 #endif
@@ -889,37 +718,14 @@ static void moveAxis(AxisEnum axis, const int8_t direction) {
889 718
   drawAxisValue(axis);
890 719
 }
891 720
 
892
-static void e_plus() {
893
-  moveAxis(E_AXIS, 1);
894
-}
895
-
896
-static void e_minus() {
897
-  moveAxis(E_AXIS, -1);
898
-}
899
-
900
-static void x_minus() {
901
-  moveAxis(X_AXIS, -1);
902
-}
903
-
904
-static void x_plus() {
905
-  moveAxis(X_AXIS, 1);
906
-}
907
-
908
-static void y_plus() {
909
-  moveAxis(Y_AXIS, 1);
910
-}
911
-
912
-static void y_minus() {
913
-  moveAxis(Y_AXIS, -1);
914
-}
915
-
916
-static void z_plus() {
917
-  moveAxis(Z_AXIS, 1);
918
-}
919
-
920
-static void z_minus() {
921
-  moveAxis(Z_AXIS, -1);
922
-}
721
+static void e_plus()  { moveAxis(E_AXIS, 1);  }
722
+static void e_minus() { moveAxis(E_AXIS, -1); }
723
+static void x_minus() { moveAxis(X_AXIS, -1); }
724
+static void x_plus()  { moveAxis(X_AXIS, 1);  }
725
+static void y_plus()  { moveAxis(Y_AXIS, 1);  }
726
+static void y_minus() { moveAxis(Y_AXIS, -1); }
727
+static void z_plus()  { moveAxis(Z_AXIS, 1);  }
728
+static void z_minus() { moveAxis(Z_AXIS, -1); }
923 729
 
924 730
 #if ENABLED(TOUCH_SCREEN)
925 731
   static void e_select() {
@@ -1002,8 +808,9 @@ void MarlinUI::move_axis_screen() {
1002 808
 
1003 809
   const bool busy = printingIsActive();
1004 810
 
1005
-  // if we have baby step and we are printing, select baby step
1006
-  if (busy && ENABLED(BABYSTEP_ZPROBE_OFFSET)) motionAxisState.z_selection = Z_SELECTION_Z_PROBE;
811
+  // Babysteps during printing? Select babystep for Z probe offset
812
+  if (busy && ENABLED(BABYSTEP_ZPROBE_OFFSET))
813
+    motionAxisState.z_selection = Z_SELECTION_Z_PROBE;
1007 814
 
1008 815
   // ROW 1 -> E- Y- CurY Z+
1009 816
   int x = X_MARGIN, y = Y_MARGIN, spacing = 0;
@@ -1089,7 +896,7 @@ void MarlinUI::move_axis_screen() {
1089 896
     TERN_(HAS_TFT_XPT2046, touch.add_control(BUTTON, motionAxisState.stepValuePos.x, motionAxisState.stepValuePos.y, CUR_STEP_VALUE_WIDTH, BTN_HEIGHT, (intptr_t)step_size));
1090 897
   }
1091 898
 
1092
-  // alinged with x+
899
+  // aligned with x+
1093 900
   drawBtn(xplus_x, TFT_HEIGHT - Y_MARGIN - BTN_HEIGHT, "off", (intptr_t)disable_steppers, imgCancel, COLOR_WHITE, !busy);
1094 901
 
1095 902
   TERN_(HAS_TFT_XPT2046, add_control(TFT_WIDTH - X_MARGIN - BTN_WIDTH, y, BACK, imgBack));

+ 18
- 86
Marlin/src/lcd/tft/ui_480x320.h ファイルの表示

@@ -21,97 +21,29 @@
21 21
  */
22 22
 #pragma once
23 23
 
24
-#include "../../inc/MarlinConfigPre.h"
24
+#define MARLIN_LOGO_FULL_SIZE MarlinLogo480x320x16
25 25
 
26
-#include "tft.h"
27
-#include "tft_image.h"
26
+#include "ui_common.h"
28 27
 
29
-#if ENABLED(TOUCH_SCREEN)
30
-  #include "touch.h"
31
-#endif
28
+#define TFT_STATUS_TOP_Y       4
29
+#define TFT_TOP_LINE_Y         4
32 30
 
33
-void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater);
34
-void draw_fan_status(uint16_t x, uint16_t y, const bool blink);
31
+#define MENU_TEXT_X_OFFSET    16
32
+#define MENU_TEXT_Y_OFFSET     7
35 33
 
36
-#define MENU_TEXT_X_OFFSET  16
37
-#define MENU_TEXT_Y_OFFSET   7
38
-void menu_line(const uint8_t row, uint16_t color = COLOR_BACKGROUND);
39
-void menu_item(const uint8_t row, bool sel = false);
34
+#define MENU_ITEM_ICON_X       5
35
+#define MENU_ITEM_ICON_Y       5
36
+#define MENU_ITEM_ICON_SPACE  42
40 37
 
41 38
 #if HAS_UI_480x320
42
-  #define MENU_FONT_NAME    Helvetica18
43
-  #define SYMBOLS_FONT_NAME Helvetica18_symbols
44
-  #define MENU_ITEM_HEIGHT  43
45
-  #define FONT_LINE_HEIGHT  34
39
+  #define MENU_FONT_NAME      Helvetica18
40
+  #define SYMBOLS_FONT_NAME   Helvetica18_symbols
41
+  #define MENU_ITEM_HEIGHT    43
42
+  #define FONT_LINE_HEIGHT    34
46 43
 #elif HAS_UI_480x272
47
-  #define MENU_FONT_NAME    Helvetica14
48
-  #define SYMBOLS_FONT_NAME Helvetica14_symbols
49
-  #define MENU_ITEM_HEIGHT  36
50
-  #define FONT_LINE_HEIGHT  24
51
-#endif
52
-
53
-#define ABSOLUTE_ZERO     -273.15
54
-
55
-const tImage Images[imgCount] = {
56
-  TERN(SHOW_BOOTSCREEN, TERN(BOOT_MARLIN_LOGO_SMALL, MarlinLogo195x59x16, MarlinLogo480x320x16), NoLogo),
57
-  HotEnd_64x64x4,
58
-  Bed_64x64x4,
59
-  Bed_Heated_64x64x4,
60
-  Chamber_64x64x4,
61
-  Chamber_Heated_64x64x4,
62
-  Fan0_64x64x4,
63
-  Fan_Slow0_64x64x4,
64
-  Fan_Slow1_64x64x4,
65
-  Fan_Fast0_64x64x4,
66
-  Fan_Fast1_64x64x4,
67
-  Feedrate_32x32x4,
68
-  Flowrate_32x32x4,
69
-  SD_64x64x4,
70
-  Menu_64x64x4,
71
-  Settings_64x64x4,
72
-  Directory_32x32x4,
73
-  Confirm_64x64x4,
74
-  Cancel_64x64x4,
75
-  Increase_64x64x4,
76
-  Decrease_64x64x4,
77
-  Back_32x32x4,
78
-  Up_32x32x4,
79
-  Down_32x32x4,
80
-  Left_32x32x4,
81
-  Right_32x32x4,
82
-  Refresh_32x32x4,
83
-  Leveling_32x32x4,
84
-  Slider8x16x4,
85
-  Home_64x64x4,
86
-  BtnRounded_64x52x4,
87
-};
88
-
89
-#if HAS_TEMP_CHAMBER && HOTENDS > 1
90
-  #define ITEM_E0         0
91
-  #define ITEM_E1         1
92
-  #define ITEM_BED        2
93
-  #define ITEM_CHAMBER    3
94
-  #define ITEM_FAN        4
95
-  #define ITEMS_COUNT     5
96
-  #define POS_Y           4
97
-#elif HAS_TEMP_CHAMBER
98
-  #define ITEM_E0         0
99
-  #define ITEM_BED        1
100
-  #define ITEM_CHAMBER    2
101
-  #define ITEM_FAN        3
102
-  #define ITEMS_COUNT     4
103
-  #define POS_Y           4
104
-#elif HOTENDS > 1
105
-  #define ITEM_E0         0
106
-  #define ITEM_E1         1
107
-  #define ITEM_BED        2
108
-  #define ITEM_FAN        3
109
-  #define ITEMS_COUNT     4
110
-  #define POS_Y           4
111
-#else
112
-  #define ITEM_E0         0
113
-  #define ITEM_BED        1
114
-  #define ITEM_FAN        2
115
-  #define ITEMS_COUNT     3
116
-  #define POS_Y           4
44
+  #define MENU_FONT_NAME      Helvetica14
45
+  #define SYMBOLS_FONT_NAME   Helvetica14_symbols
46
+  #define MENU_ITEM_HEIGHT    36
47
+  #define FONT_LINE_HEIGHT    24
117 48
 #endif
49
+#define MENU_LINE_HEIGHT      (MENU_ITEM_HEIGHT + 2)

+ 246
- 0
Marlin/src/lcd/tft/ui_common.cpp ファイルの表示

@@ -0,0 +1,246 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#include "../../inc/MarlinConfigPre.h"
24
+
25
+#if HAS_GRAPHICAL_TFT
26
+
27
+#include "ui_common.h"
28
+#include "../lcdprint.h"
29
+#include "../../libs/numtostr.h"
30
+#include "../menu/menu.h"
31
+
32
+void menu_pause_option();
33
+
34
+static xy_uint_t cursor;
35
+
36
+#if ENABLED(TOUCH_SCREEN)
37
+  bool draw_menu_navigation = false;
38
+#endif
39
+
40
+void menu_line(const uint8_t row, uint16_t color) {
41
+  cursor.set(0, row);
42
+  tft.canvas(0, TFT_TOP_LINE_Y + cursor.y * MENU_LINE_HEIGHT, TFT_WIDTH, MENU_ITEM_HEIGHT);
43
+  tft.set_background(color);
44
+}
45
+
46
+void menu_item(const uint8_t row, bool sel ) {
47
+  #if ENABLED(TOUCH_SCREEN)
48
+    if (row == 0) {
49
+      touch.clear();
50
+      draw_menu_navigation = TERN(ADVANCED_PAUSE_FEATURE, ui.currentScreen != menu_pause_option, true);
51
+    }
52
+  #endif
53
+
54
+  menu_line(row, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND);
55
+  #if ENABLED(TOUCH_SCREEN)
56
+    const TouchControlType tct = TERN(SINGLE_TOUCH_NAVIGATION, true, sel) ? MENU_CLICK : MENU_ITEM;
57
+    touch.add_control(tct, 0, TFT_TOP_LINE_Y + row * MENU_LINE_HEIGHT, TFT_WIDTH, MENU_ITEM_HEIGHT, encoderTopLine + row);
58
+  #endif
59
+}
60
+
61
+//
62
+// lcdprint.h functions
63
+//
64
+
65
+#define TFT_COL_WIDTH ((TFT_WIDTH) / (LCD_WIDTH))
66
+
67
+void lcd_gotopixel(const uint16_t x, const uint16_t y) {
68
+  if (x >= TFT_WIDTH) return;
69
+  cursor.set(x / (TFT_COL_WIDTH), y / MENU_LINE_HEIGHT);
70
+  tft.canvas(x, TFT_TOP_LINE_Y + y, (TFT_WIDTH) - x, MENU_ITEM_HEIGHT);
71
+  tft.set_background(COLOR_BACKGROUND);
72
+}
73
+
74
+void lcd_moveto(const lcd_uint_t col, const lcd_uint_t row) {
75
+  lcd_gotopixel(int(col) * (TFT_COL_WIDTH), int(row) * MENU_LINE_HEIGHT);
76
+}
77
+
78
+int lcd_put_wchar_max(wchar_t c, pixel_len_t max_length) {
79
+  if (max_length < 1) return 0;
80
+  tft_string.set();
81
+  tft_string.add(c);
82
+  tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
83
+  lcd_gotopixel((cursor.x + 1) * (TFT_COL_WIDTH) + tft_string.width(), cursor.y * MENU_LINE_HEIGHT);
84
+  return tft_string.width();
85
+}
86
+
87
+int lcd_put_u8str_max_P(PGM_P utf8_str_P, pixel_len_t max_length) {
88
+  if (max_length < 1) return 0;
89
+  tft_string.set(utf8_str_P);
90
+  tft_string.trim();
91
+  tft_string.truncate(max_length);
92
+  tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
93
+  lcd_gotopixel((cursor.x + 1) * (TFT_COL_WIDTH) + tft_string.width(), cursor.y * MENU_LINE_HEIGHT);
94
+  return tft_string.width();
95
+}
96
+
97
+int lcd_put_u8str_max(const char * utf8_str, pixel_len_t max_length) {
98
+  return lcd_put_u8str_max_P(utf8_str, max_length);
99
+}
100
+
101
+void lcd_put_int(const int i) {
102
+  // 3 digits max for this one...
103
+  const char* str = i16tostr3left(int16_t(i));
104
+  lcd_put_u8str_max(str, 3);
105
+}
106
+
107
+//
108
+// Menu Item methods
109
+//
110
+
111
+// Draw a generic menu item with pre_char (if selected) and post_char
112
+void MenuItemBase::_draw(const bool sel, const uint8_t row, PGM_P const pstr, const char pre_char, const char post_char) {
113
+  menu_item(row, sel);
114
+
115
+  uint8_t *string = (uint8_t *)pstr;
116
+  MarlinImage image = noImage;
117
+  switch (*string) {
118
+    case 0x01: image = imgRefresh; break;  // LCD_STR_REFRESH
119
+    case 0x02: image = imgDirectory; break;  // LCD_STR_FOLDER
120
+  }
121
+
122
+  uint8_t offset = MENU_TEXT_X_OFFSET;
123
+  if (image != noImage) {
124
+    string++;
125
+    offset = MENU_ITEM_ICON_SPACE;
126
+    tft.add_image(MENU_ITEM_ICON_X, MENU_ITEM_ICON_Y, image, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND);
127
+  }
128
+
129
+  tft_string.set(string, itemIndex, itemString);
130
+  tft.add_text(offset, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
131
+}
132
+
133
+// Draw a menu item with a (potentially) editable value
134
+void MenuEditItemBase::draw(const bool sel, const uint8_t row, PGM_P const pstr, const char* const data, const bool pgm) {
135
+  menu_item(row, sel);
136
+
137
+  tft_string.set(pstr, itemIndex, itemString);
138
+  tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string);
139
+  if (data) {
140
+    tft_string.set(data);
141
+    tft.add_text(TFT_WIDTH - MENU_TEXT_X_OFFSET - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string);
142
+  }
143
+}
144
+
145
+// Draw a static item with no left-right margin required. Centered by default.
146
+void MenuItem_static::draw(const uint8_t row, PGM_P const pstr, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) {
147
+  menu_item(row);
148
+  tft_string.set(pstr, itemIndex, itemString);
149
+  if (vstr)
150
+    tft_string.add(vstr);
151
+  tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_YELLOW, tft_string);
152
+}
153
+
154
+#if ENABLED(SDSUPPORT)
155
+
156
+  void MenuItem_sdbase::draw(const bool sel, const uint8_t row, PGM_P const, CardReader &theCard, const bool isDir) {
157
+    menu_item(row, sel);
158
+    if (isDir)
159
+      tft.add_image(MENU_ITEM_ICON_X, MENU_ITEM_ICON_Y, imgDirectory, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND);
160
+    tft.add_text(MENU_ITEM_ICON_SPACE, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, theCard.longest_filename());
161
+  }
162
+
163
+#endif
164
+
165
+//
166
+// MarlinUI methods
167
+//
168
+
169
+bool MarlinUI::detected() { return true; }
170
+
171
+void MarlinUI::init_lcd() {
172
+  tft.init();
173
+  tft.set_font(MENU_FONT_NAME);
174
+  #ifdef SYMBOLS_FONT_NAME
175
+    tft.add_glyphs(SYMBOLS_FONT_NAME);
176
+  #endif
177
+  TERN_(TOUCH_SCREEN, touch.init());
178
+  clear_lcd();
179
+}
180
+
181
+void MarlinUI::clear_lcd() {
182
+  #if ENABLED(TOUCH_SCREEN)
183
+    touch.reset();
184
+    draw_menu_navigation = false;
185
+  #endif
186
+
187
+  tft.queue.reset();
188
+  tft.fill(0, 0, TFT_WIDTH, TFT_HEIGHT, COLOR_BACKGROUND);
189
+  cursor.set(0, 0);
190
+}
191
+
192
+#if ENABLED(TOUCH_SCREEN_CALIBRATION)
193
+
194
+  void MarlinUI::touch_calibration_screen() {
195
+    uint16_t x, y;
196
+
197
+    calibrationState calibration_stage = touch_calibration.get_calibration_state();
198
+
199
+    if (calibration_stage == CALIBRATION_NONE) {
200
+      defer_status_screen(true);
201
+      clear_lcd();
202
+      calibration_stage = touch_calibration.calibration_start();
203
+    }
204
+    else {
205
+      x = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].x;
206
+      y = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].y;
207
+      tft.canvas(x - 15, y - 15, 31, 31);
208
+      tft.set_background(COLOR_BACKGROUND);
209
+    }
210
+
211
+    touch.clear();
212
+
213
+    if (calibration_stage < CALIBRATION_SUCCESS) {
214
+      switch (calibration_stage) {
215
+        case CALIBRATION_TOP_LEFT: tft_string.set(GET_TEXT(MSG_TOP_LEFT)); break;
216
+        case CALIBRATION_BOTTOM_LEFT: tft_string.set(GET_TEXT(MSG_BOTTOM_LEFT)); break;
217
+        case CALIBRATION_TOP_RIGHT: tft_string.set(GET_TEXT(MSG_TOP_RIGHT)); break;
218
+        case CALIBRATION_BOTTOM_RIGHT: tft_string.set(GET_TEXT(MSG_BOTTOM_RIGHT)); break;
219
+        default: break;
220
+      }
221
+
222
+      x = touch_calibration.calibration_points[calibration_stage].x;
223
+      y = touch_calibration.calibration_points[calibration_stage].y;
224
+
225
+      tft.canvas(x - 15, y - 15, 31, 31);
226
+      tft.set_background(COLOR_BACKGROUND);
227
+      tft.add_bar(0, 15, 31, 1, COLOR_TOUCH_CALIBRATION);
228
+      tft.add_bar(15, 0, 1, 31, COLOR_TOUCH_CALIBRATION);
229
+
230
+      touch.add_control(CALIBRATE, 0, 0, TFT_WIDTH, TFT_HEIGHT, uint32_t(x) << 16 | uint32_t(y));
231
+    }
232
+    else {
233
+      tft_string.set(calibration_stage == CALIBRATION_SUCCESS ? GET_TEXT(MSG_CALIBRATION_COMPLETED) : GET_TEXT(MSG_CALIBRATION_FAILED));
234
+      defer_status_screen(false);
235
+      touch_calibration.calibration_end();
236
+      touch.add_control(BACK, 0, 0, TFT_WIDTH, TFT_HEIGHT);
237
+    }
238
+
239
+    tft.canvas(0, (TFT_HEIGHT - tft_string.font_height()) >> 1, TFT_WIDTH, tft_string.font_height());
240
+    tft.set_background(COLOR_BACKGROUND);
241
+    tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_MENU_TEXT, tft_string);
242
+  }
243
+
244
+#endif // TOUCH_SCREEN_CALIBRATION
245
+
246
+#endif // HAS_GRAPHICAL_TFT

+ 76
- 0
Marlin/src/lcd/tft/ui_common.h ファイルの表示

@@ -0,0 +1,76 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+#include "../../inc/MarlinConfigPre.h"
25
+
26
+#if !HAS_LCD_MENU
27
+  #error "Seriously? High resolution TFT screen without menu?"
28
+#endif
29
+
30
+#include "tft.h"
31
+#include "tft_image.h"
32
+
33
+#if ENABLED(TOUCH_SCREEN)
34
+  #include "touch.h"
35
+  extern bool draw_menu_navigation;
36
+#endif
37
+
38
+#if HAS_UI_320x240
39
+  #include "ui_320x240.h"
40
+#elif HAS_UI_480x320 || HAS_UI_480x272
41
+  #include "ui_480x320.h"
42
+#endif
43
+
44
+void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater);
45
+void draw_fan_status(uint16_t x, uint16_t y, const bool blink);
46
+
47
+void menu_line(const uint8_t row, uint16_t color=COLOR_BACKGROUND);
48
+void menu_item(const uint8_t row, bool sel = false);
49
+
50
+#define ABSOLUTE_ZERO     -273.15
51
+
52
+#if HAS_TEMP_CHAMBER && HOTENDS > 1
53
+  #define ITEM_E0         0
54
+  #define ITEM_E1         1
55
+  #define ITEM_BED        2
56
+  #define ITEM_CHAMBER    3
57
+  #define ITEM_FAN        4
58
+  #define ITEMS_COUNT     5
59
+#elif HAS_TEMP_CHAMBER
60
+  #define ITEM_E0         0
61
+  #define ITEM_BED        1
62
+  #define ITEM_CHAMBER    2
63
+  #define ITEM_FAN        3
64
+  #define ITEMS_COUNT     4
65
+#elif HOTENDS > 1
66
+  #define ITEM_E0         0
67
+  #define ITEM_E1         1
68
+  #define ITEM_BED        2
69
+  #define ITEM_FAN        3
70
+  #define ITEMS_COUNT     4
71
+#else
72
+  #define ITEM_E0         0
73
+  #define ITEM_BED        1
74
+  #define ITEM_FAN        2
75
+  #define ITEMS_COUNT     3
76
+#endif

読み込み中…
キャンセル
保存