Skip to content

Commit 6348dae

Browse files
InsanityAutomationOmkar Dhekne
authored and
Omkar Dhekne
committed
🩹 Fix and clean up E3V2 draw (MarlinFirmware#23979, MarlinFirmware#24013)
1 parent 102b328 commit 6348dae

File tree

3 files changed

+71
-62
lines changed

3 files changed

+71
-62
lines changed

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

-4
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ void DWIN_Frame_AreaMove(uint8_t mode, uint8_t dir, uint16_t dis,
235235
// rlimit: To limit the drawn string length
236236
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*/) {
237237
DWIN_Draw_Rectangle(1, bColor, x, y, x + (fontWidth(size) * strlen_P(string)), y + fontHeight(size));
238-
DWIN_UpdateLCD();
239238
constexpr uint8_t widthAdjust = 0;
240239
size_t i = 0;
241240
DWIN_Byte(i, 0x11);
@@ -250,7 +249,6 @@ void DWIN_Draw_String(bool bShow, uint8_t size, uint16_t color, uint16_t bColor,
250249
DWIN_Word(i, y);
251250
DWIN_Text(i, string, rlimit);
252251
DWIN_Send(i);
253-
DWIN_UpdateLCD();
254252
}
255253

256254
// Draw a positive integer
@@ -297,7 +295,6 @@ void DWIN_Draw_IntValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_t
297295
#endif
298296

299297
DWIN_Send(i);
300-
DWIN_UpdateLCD();
301298
}
302299

303300
// Draw a floating point number
@@ -332,7 +329,6 @@ void DWIN_Draw_FloatValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_
332329
DWIN_Byte(i, fvalue[0]);
333330
*/
334331
DWIN_Send(i);
335-
DWIN_UpdateLCD();
336332
}
337333

338334
// Draw a floating point number

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

-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ void MarlinUI::draw_status_message(const bool blink) {
181181
dwin_font.solid = true;
182182
dwin_font.fg = Color_White;
183183
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);
185184
lcd_moveto_xy(0, LCD_PIXEL_HEIGHT - (STAT_FONT_HEIGHT) - 1);
186185

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

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

+71-57
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,11 @@ FORCE_INLINE void _draw_heater_status(const heater_id_t heater, const uint16_t x
193193
#define HOTEND_STATS 3
194194
#elif HOTENDS > 1
195195
#define HOTEND_STATS 2
196-
#elif HAS_HOTEND
196+
#else
197197
#define HOTEND_STATS 1
198198
#endif
199199
static celsius_t old_temp[HOTEND_STATS] = ARRAY_N_1(HOTEND_STATS, 500),
200-
old_target[HOTEND_STATS] = ARRAY_N_1(HOTEND_STATS, 500);
200+
old_target[HOTEND_STATS] = ARRAY_N_1(HOTEND_STATS, 500);
201201
static bool old_on[HOTEND_STATS] = ARRAY_N_1(HOTEND_STATS, false);
202202
#endif
203203

@@ -210,25 +210,27 @@ FORCE_INLINE void _draw_heater_status(const heater_id_t heater, const uint16_t x
210210
#endif
211211

212212
#if HAS_HOTEND && HAS_HEATED_BED
213+
float tc, tt;
214+
bool c_draw, t_draw, i_draw, ta;
213215
const bool isBed = heater < 0;
214-
const float tc = isBed ? thermalManager.degBed() : thermalManager.degHotend(heater),
215-
tt = isBed ? thermalManager.degTargetBed() : thermalManager.degTargetHotend(heater);
216-
const bool ta = isBed ? thermalManager.isHeatingBed() : thermalManager.isHeatingHotend(heater);
217-
218-
bool c_draw = tc != (isBed ? old_bed_temp : old_temp[heater]),
219-
t_draw = tt != (isBed ? old_bed_target : old_target[heater]),
220-
i_draw = ta != (isBed ? old_bed_on : old_on[heater]);
221-
222216
if (isBed) {
223-
#if HAS_LEVELING
224-
if (!i_draw && planner.leveling_active != old_leveling_on) i_draw = true;
225-
old_leveling_on = planner.leveling_active;
226-
#endif
217+
tc = thermalManager.degBed();
218+
tt = thermalManager.degTargetBed();
219+
ta = thermalManager.isHeatingBed();
220+
c_draw = tc != old_bed_temp;
221+
t_draw = tt != old_bed_target;
222+
i_draw = ta != old_bed_on;
227223
old_bed_temp = tc;
228224
old_bed_target = tt;
229225
old_bed_on = ta;
230226
}
231227
else {
228+
tc = thermalManager.degHotend(heater);
229+
tt = thermalManager.degTargetHotend(heater);
230+
ta = thermalManager.isHeatingHotend(heater);
231+
c_draw = tc != old_temp[heater];
232+
t_draw = tt != old_target[heater];
233+
i_draw = ta != old_on[heater];
232234
old_temp[heater] = tc;
233235
old_target[heater] = tt;
234236
old_on[heater] = ta;
@@ -237,31 +239,41 @@ FORCE_INLINE void _draw_heater_status(const heater_id_t heater, const uint16_t x
237239
constexpr bool isBed = false;
238240
const float tc = thermalManager.degHotend(heater), tt = thermalManager.degTargetHotend(heater);
239241
const uint8_t ta = thermalManager.isHeatingHotend(heater);
240-
const bool c_draw = tc != old_bed_temp, t_draw = tt != old_bed_target, i_draw = ta != old_bed_on;
242+
bool c_draw = tc != old_temp[heater], t_draw = tt != old_target[heater], i_draw = ta != old_on[heater];
241243
old_temp[heater] = tc; old_target[heater] = tt; old_on[heater] = ta;
242244
#elif HAS_HEATED_BED
243245
constexpr bool isBed = true;
244246
const float tc = thermalManager.degBed(), tt = thermalManager.degTargetBed();
245247
const uint8_t ta = thermalManager.isHeatingBed();
246-
bool c_draw = tc != old_temp[heater], t_draw = tt != old_target[heater], i_draw = ta != old_on[heater];
247-
#if HAS_LEVELING
248-
if (!idraw && planner.leveling_active != old_leveling_on) i_draw = true;
249-
old_leveling_on = tl;
250-
#endif
248+
bool c_draw = tc != old_bed_temp, t_draw = tt != old_bed_target, i_draw = ta != old_bed_on;
251249
old_bed_temp = tc; old_bed_target = tt; old_bed_on = ta;
250+
#else
251+
bool c_draw = false, t_draw = false, i_draw = false;
252+
constexpr float tc = 0, tt = 0;
253+
constexpr uint8_t ta = 0;
252254
#endif
253255

256+
#if HAS_HEATED_BED && HAS_LEVELING
257+
if (isBed) {
258+
i_draw |= (planner.leveling_active != old_leveling_on);
259+
old_leveling_on = planner.leveling_active;
260+
}
261+
#endif
262+
263+
// Draw target temperature, if needed
254264
if (!ui.did_first_redraw || t_draw) {
255265
dwin_string.set(i16tostr3rj(tt + 0.5));
256266
dwin_string.add(LCD_STR_DEGREE);
257267
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y, S(dwin_string.string()));
258268
}
259269

260-
if (!ui.did_first_redraw || i_draw){
270+
// Draw heater icon with on / off / leveled states
271+
if (!ui.did_first_redraw || i_draw) {
261272
const uint8_t ico = isBed ? (TERN0(HAS_LEVELING, planner.leveling_active) ? ICON_BedLevelOff : ICON_BedOff) : ICON_HotendOff;
262273
DWIN_ICON_Show(ICON, ico + ta, x, y + STATUS_CHR_HEIGHT + 2);
263274
}
264275

276+
// Draw current temperature, if needed
265277
if (!ui.did_first_redraw || c_draw) {
266278
dwin_string.set(i16tostr3rj(tc + 0.5));
267279
dwin_string.add(LCD_STR_DEGREE);
@@ -412,43 +424,45 @@ void MarlinUI::draw_status_screen() {
412424
//
413425
// Progress Bar
414426
//
415-
constexpr int16_t pb_margin = 5,
416-
pb_left = pb_margin + TERN(DWIN_MARLINUI_PORTRAIT, 0, 90),
417-
pb_height = TERN(DWIN_MARLINUI_PORTRAIT, 60, 20),
418-
pb_right = LCD_PIXEL_WIDTH - pb_margin,
419-
pb_bottom = TERN(DWIN_MARLINUI_PORTRAIT, 410, 220),
420-
pb_top = pb_bottom - pb_height,
421-
pb_width = pb_right - pb_left;
422-
423-
const progress_t progress = TERN(HAS_PRINT_PROGRESS_PERMYRIAD, get_progress_permyriad, get_progress_percent)();
424-
425-
if (!ui.did_first_redraw)
426-
DWIN_Draw_Rectangle(0, Select_Color, pb_left, pb_top, pb_right, pb_bottom); // Outline
427-
428-
static uint16_t old_solid = 50;
429-
const uint16_t pb_solid = (pb_width - 2) * (progress / (PROGRESS_SCALE)) * 0.01f;
430-
const bool p_draw = !ui.did_first_redraw || old_solid != pb_solid;
431-
432-
if (p_draw) {
433-
//if (pb_solid)
434-
DWIN_Draw_Rectangle(1, Select_Color, pb_left + 1, pb_top + 1, pb_left + pb_solid, pb_bottom - 1); // Fill the solid part
435-
436-
//if (pb_solid < old_solid)
437-
DWIN_Draw_Rectangle(1, Color_Bg_Black, pb_left + 1 + pb_solid, pb_top + 1, pb_right - 1, pb_bottom - 1); // Erase the rest
438-
439-
#if ENABLED(SHOW_SD_PERCENT)
440-
dwin_string.set(TERN(PRINT_PROGRESS_SHOW_DECIMALS, permyriadtostr4(progress), ui8tostr3rj(progress / (PROGRESS_SCALE))));
441-
dwin_string.add(PSTR("%"));
442-
DWIN_Draw_String(
443-
false, font16x32, Percent_Color, Color_Bg_Black,
444-
pb_left + (pb_width - dwin_string.length() * 16) / 2,
445-
pb_top + (pb_height - 32) / 2,
446-
S(dwin_string.string())
447-
);
448-
#endif
427+
#if HAS_PRINT_PROGRESS
428+
constexpr int16_t pb_margin = 5,
429+
pb_left = pb_margin + TERN(DWIN_MARLINUI_PORTRAIT, 0, 90),
430+
pb_height = TERN(DWIN_MARLINUI_PORTRAIT, 60, 20),
431+
pb_right = LCD_PIXEL_WIDTH - pb_margin,
432+
pb_bottom = TERN(DWIN_MARLINUI_PORTRAIT, 410, 220),
433+
pb_top = pb_bottom - pb_height,
434+
pb_width = pb_right - pb_left;
435+
436+
const progress_t progress = TERN(HAS_PRINT_PROGRESS_PERMYRIAD, get_progress_permyriad, get_progress_percent)();
437+
438+
if (!ui.did_first_redraw)
439+
DWIN_Draw_Rectangle(0, Select_Color, pb_left, pb_top, pb_right, pb_bottom); // Outline
440+
441+
static uint16_t old_solid = 50;
442+
const uint16_t pb_solid = (pb_width - 2) * (progress / (PROGRESS_SCALE)) * 0.01f;
443+
const bool p_draw = !ui.did_first_redraw || old_solid != pb_solid;
444+
445+
if (p_draw) {
446+
//if (pb_solid)
447+
DWIN_Draw_Rectangle(1, Select_Color, pb_left + 1, pb_top + 1, pb_left + pb_solid, pb_bottom - 1); // Fill the solid part
448+
449+
//if (pb_solid < old_solid)
450+
DWIN_Draw_Rectangle(1, Color_Bg_Black, pb_left + 1 + pb_solid, pb_top + 1, pb_right - 1, pb_bottom - 1); // Erase the rest
451+
452+
#if ENABLED(SHOW_SD_PERCENT)
453+
dwin_string.set(TERN(PRINT_PROGRESS_SHOW_DECIMALS, permyriadtostr4(progress), ui8tostr3rj(progress / (PROGRESS_SCALE))));
454+
dwin_string.add(PSTR("%"));
455+
DWIN_Draw_String(
456+
false, font16x32, Percent_Color, Color_Bg_Black,
457+
pb_left + (pb_width - dwin_string.length() * 16) / 2,
458+
pb_top + (pb_height - 32) / 2,
459+
S(dwin_string.string())
460+
);
461+
#endif
449462

450-
old_solid = pb_solid;
451-
}
463+
old_solid = pb_solid;
464+
}
465+
#endif // HAS_PRINT_PROGRESS
452466

453467
//
454468
// Status Message

0 commit comments

Comments
 (0)