Skip to content

Commit 4953946

Browse files
🐛 Fix MarlinUI on Ender 3 S1 (MarlinFirmware#23949)
1 parent 6015ee2 commit 4953946

File tree

4 files changed

+62
-8
lines changed

4 files changed

+62
-8
lines changed

Marlin/src/inc/SanityCheck.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
853853
/**
854854
* Custom Boot and Status screens
855855
*/
856-
#if ENABLED(SHOW_CUSTOM_BOOTSCREEN) && NONE(HAS_MARLINUI_U8GLIB, TOUCH_UI_FTDI_EVE)
856+
#if ENABLED(SHOW_CUSTOM_BOOTSCREEN) && NONE(HAS_MARLINUI_U8GLIB, TOUCH_UI_FTDI_EVE, IS_DWIN_MARLINUI)
857857
#error "SHOW_CUSTOM_BOOTSCREEN requires Graphical LCD or TOUCH_UI_FTDI_EVE."
858858
#elif ENABLED(SHOW_CUSTOM_BOOTSCREEN) && DISABLED(SHOW_BOOTSCREEN)
859859
#error "SHOW_CUSTOM_BOOTSCREEN requires SHOW_BOOTSCREEN."

Marlin/src/lcd/e3v2/common/dwin_api.cpp

+42
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "dwin_api.h"
2727
#include "dwin_set.h"
28+
#include "dwin_font.h"
2829

2930
#include "../../../inc/MarlinConfig.h"
3031

@@ -89,6 +90,40 @@ bool DWIN_Handshake() {
8990
}
9091
#endif
9192

93+
// Get font character width
94+
uint8_t fontWidth(uint8_t cfont) {
95+
switch (cfont) {
96+
case font6x12 : return 6;
97+
case font8x16 : return 8;
98+
case font10x20: return 10;
99+
case font12x24: return 12;
100+
case font14x28: return 14;
101+
case font16x32: return 16;
102+
case font20x40: return 20;
103+
case font24x48: return 24;
104+
case font28x56: return 28;
105+
case font32x64: return 32;
106+
default: return 0;
107+
}
108+
}
109+
110+
// Get font character height
111+
uint8_t fontHeight(uint8_t cfont) {
112+
switch (cfont) {
113+
case font6x12 : return 12;
114+
case font8x16 : return 16;
115+
case font10x20: return 20;
116+
case font12x24: return 24;
117+
case font14x28: return 28;
118+
case font16x32: return 32;
119+
case font20x40: return 40;
120+
case font24x48: return 48;
121+
case font28x56: return 56;
122+
case font32x64: return 64;
123+
default: return 0;
124+
}
125+
}
126+
92127
// Set screen display direction
93128
// dir: 0=0°, 1=90°, 2=180°, 3=270°
94129
void DWIN_Frame_SetDir(uint8_t dir) {
@@ -199,6 +234,8 @@ void DWIN_Frame_AreaMove(uint8_t mode, uint8_t dir, uint16_t dis,
199234
// *string: The string
200235
// rlimit: To limit the drawn string length
201236
void DWIN_Draw_String(bool bShow, uint8_t size, uint16_t color, uint16_t bColor, uint16_t x, uint16_t y, const char * const string, uint16_t rlimit/*=0xFFFF*/) {
237+
DWIN_Draw_Rectangle(1, bColor, x, y, x + (fontWidth(size) * strlen_P(string)), y + fontHeight(size));
238+
DWIN_UpdateLCD();
202239
constexpr uint8_t widthAdjust = 0;
203240
size_t i = 0;
204241
DWIN_Byte(i, 0x11);
@@ -213,6 +250,7 @@ void DWIN_Draw_String(bool bShow, uint8_t size, uint16_t color, uint16_t bColor,
213250
DWIN_Word(i, y);
214251
DWIN_Text(i, string, rlimit);
215252
DWIN_Send(i);
253+
DWIN_UpdateLCD();
216254
}
217255

218256
// Draw a positive integer
@@ -228,6 +266,7 @@ void DWIN_Draw_String(bool bShow, uint8_t size, uint16_t color, uint16_t bColor,
228266
void DWIN_Draw_IntValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_t size, uint16_t color,
229267
uint16_t bColor, uint8_t iNum, uint16_t x, uint16_t y, uint32_t value) {
230268
size_t i = 0;
269+
DWIN_Draw_Rectangle(1, bColor, x, y, x + fontWidth(size) * iNum + 1, y + fontHeight(size));
231270
DWIN_Byte(i, 0x14);
232271
// Bit 7: bshow
233272
// Bit 6: 1 = signed; 0 = unsigned number;
@@ -258,6 +297,7 @@ void DWIN_Draw_IntValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_t
258297
#endif
259298

260299
DWIN_Send(i);
300+
DWIN_UpdateLCD();
261301
}
262302

263303
// Draw a floating point number
@@ -275,6 +315,7 @@ void DWIN_Draw_FloatValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_
275315
uint16_t bColor, uint8_t iNum, uint8_t fNum, uint16_t x, uint16_t y, int32_t value) {
276316
//uint8_t *fvalue = (uint8_t*)&value;
277317
size_t i = 0;
318+
DWIN_Draw_Rectangle(1, bColor, x, y, x + fontWidth(size) * (iNum+fNum+1), y + fontHeight(size));
278319
DWIN_Byte(i, 0x14);
279320
DWIN_Byte(i, (bShow * 0x80) | (zeroFill * 0x20) | (zeroMode * 0x10) | size);
280321
DWIN_Word(i, color);
@@ -291,6 +332,7 @@ void DWIN_Draw_FloatValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_
291332
DWIN_Byte(i, fvalue[0]);
292333
*/
293334
DWIN_Send(i);
335+
DWIN_UpdateLCD();
294336
}
295337

296338
// Draw a floating point number

Marlin/src/lcd/e3v2/marlinui/dwin_lcd.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ void DWIN_Startup() {
4545
const bool success = DWIN_Handshake();
4646
if (success) DEBUG_ECHOLNPGM("ok."); else DEBUG_ECHOLNPGM("error.");
4747
DWIN_Frame_SetDir(TERN(DWIN_MARLINUI_LANDSCAPE, 0, 1));
48-
DWIN_JPG_ShowAndCache(3);
4948
DWIN_Frame_Clear(Color_Bg_Black); // MarlinUI handles the bootscreen so just clear here
49+
DWIN_JPG_ShowAndCache(3);
5050
DWIN_UpdateLCD();
5151
}
5252

Marlin/src/lcd/e3v2/marlinui/ui_common.cpp

+18-6
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ void MarlinUI::init_lcd() { DWIN_Startup(); }
8484
// This LCD should clear where it will draw anew
8585
void MarlinUI::clear_lcd() {
8686
DWIN_ICON_AnimationControl(0x0000); // disable all icon animations
87+
DWIN_JPG_ShowAndCache(3);
8788
DWIN_Frame_Clear(Color_Bg_Black);
8889
DWIN_UpdateLCD();
8990

@@ -93,29 +94,39 @@ void MarlinUI::clear_lcd() {
9394
#if ENABLED(SHOW_BOOTSCREEN)
9495

9596
void MarlinUI::show_bootscreen() {
96-
clear_lcd();
9797
dwin_string.set(F(SHORT_BUILD_VERSION));
9898

99+
#if ENABLED(SHOW_CUSTOM_BOOTSCREEN) && !defined(CUSTOM_BOOTSCREEN_TIMEOUT)
100+
#define CUSTOM_BOOTSCREEN_TIMEOUT 3000
101+
#endif
102+
99103
#if ENABLED(DWIN_MARLINUI_PORTRAIT)
100104
#define LOGO_CENTER ((LCD_PIXEL_WIDTH) / 2)
101105
#define INFO_CENTER LOGO_CENTER
102106
#define VERSION_Y 330
103-
DWIN_ICON_Show(BOOT_ICON, ICON_MarlinBoot, LOGO_CENTER - 266 / 2, 15);
107+
#else
108+
#define LOGO_CENTER (280 / 2)
109+
#define INFO_CENTER ((LCD_PIXEL_WIDTH) - 200 / 2)
110+
#define VERSION_Y 84
111+
#endif
112+
113+
DWIN_Draw_String(false, font10x20, Color_Yellow, Color_Bg_Black, INFO_CENTER - (dwin_string.length() * 10) / 2, VERSION_Y, S(dwin_string.string()));
114+
TERN_(SHOW_CUSTOM_BOOTSCREEN, safe_delay(CUSTOM_BOOTSCREEN_TIMEOUT));
115+
clear_lcd();
116+
117+
DWIN_ICON_Show(BOOT_ICON, ICON_MarlinBoot, LOGO_CENTER - 266 / 2, 15);
118+
#if ENABLED(DWIN_MARLINUI_PORTRAIT)
104119
DWIN_ICON_Show(BOOT_ICON, ICON_OpenSource, LOGO_CENTER - 174 / 2, 280);
105120
DWIN_ICON_Show(BOOT_ICON, ICON_GitHubURL, LOGO_CENTER - 180 / 2, 420);
106121
DWIN_ICON_Show(BOOT_ICON, ICON_MarlinURL, LOGO_CENTER - 100 / 2, 440);
107122
DWIN_ICON_Show(BOOT_ICON, ICON_Copyright, LOGO_CENTER - 126 / 2, 460);
108123
#else
109-
#define LOGO_CENTER (280 / 2)
110-
#define INFO_CENTER ((LCD_PIXEL_WIDTH) - 200 / 2)
111-
#define VERSION_Y 84
112124
DWIN_ICON_Show(BOOT_ICON, ICON_MarlinBoot, LOGO_CENTER - 266 / 2, 15);
113125
DWIN_ICON_Show(BOOT_ICON, ICON_OpenSource, INFO_CENTER - 174 / 2, 60);
114126
DWIN_ICON_Show(BOOT_ICON, ICON_GitHubURL, INFO_CENTER - 180 / 2, 130);
115127
DWIN_ICON_Show(BOOT_ICON, ICON_MarlinURL, INFO_CENTER - 100 / 2, 152);
116128
DWIN_ICON_Show(BOOT_ICON, ICON_Copyright, INFO_CENTER - 126 / 2, 200);
117129
#endif
118-
119130
DWIN_Draw_String(false, font10x20, Color_Yellow, Color_Bg_Black, INFO_CENTER - (dwin_string.length() * 10) / 2, VERSION_Y, S(dwin_string.string()));
120131
DWIN_UpdateLCD();
121132
}
@@ -170,6 +181,7 @@ void MarlinUI::draw_status_message(const bool blink) {
170181
dwin_font.solid = true;
171182
dwin_font.fg = Color_White;
172183
dwin_font.bg = Color_Bg_Black;
184+
DWIN_Draw_Box(1, Color_Bg_Black, 0, (LCD_PIXEL_HEIGHT - (STAT_FONT_HEIGHT) - 1), 272, STAT_FONT_HEIGHT + 1);
173185
lcd_moveto_xy(0, LCD_PIXEL_HEIGHT - (STAT_FONT_HEIGHT) - 1);
174186

175187
constexpr uint8_t max_status_chars = (LCD_PIXEL_WIDTH) / (STAT_FONT_WIDTH);

0 commit comments

Comments
 (0)