💄 Improve Ender3 v2 DWIN MarlinUI (#23369)

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
This commit is contained in:
Taylor Talkington
2022-01-17 08:07:45 -05:00
committed by Scott Lahteine
parent 31ec8f2449
commit 3f4112aee4
140 changed files with 3024 additions and 99 deletions

View File

@ -64,6 +64,8 @@
#define ICON_UpArrow 14
#define ICON_DownArrow 15
#define ICON_BedLine 16
#define ICON_BedLevelOff 17
#define ICON_BedLevelOn 18
#include "../common/dwin_font.h"

View File

@ -81,9 +81,6 @@ bool MarlinUI::detected() { return true; }
// Initialize or re-initialize the LCD
void MarlinUI::init_lcd() {
DWIN_Startup();
// Load the assets JPG (currently just the status screen 'icon')
DWIN_JPG_CacheTo1(DWIN_MarlinUI_Assets);
}
// This LCD should clear where it will draw anew

View File

@ -37,6 +37,7 @@
#include "../../../module/motion.h"
#include "../../../module/temperature.h"
#include "../../../module/printcounter.h"
#include "../../../module/planner.h"
#if ENABLED(SDSUPPORT)
#include "../../../libs/duration_t.h"
@ -46,8 +47,13 @@
#include "../../../MarlinCore.h" // for printingIsActive
#endif
#define STATUS_HEATERS_X 15
#define STATUS_HEATERS_Y 56
#if ENABLED(DWIN_MARLINUI_PORTRAIT)
#define STATUS_HEATERS_X 15
#define STATUS_HEATERS_Y 56
#else
#define STATUS_HEATERS_X 154
#define STATUS_HEATERS_Y 10
#endif
#define STATUS_HEATERS_XSPACE 64
#define STATUS_FAN_WIDTH 48
#define STATUS_FAN_HEIGHT 48
@ -61,35 +67,63 @@
// Homed and known, display constantly.
//
FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const bool blink, const uint16_t x, const uint16_t y) {
uint8_t vallen = utf8_strlen(value);
if (!ui.did_first_redraw) {
dwin_string.set();
dwin_string.add('X' + axis);
DWIN_Draw_String(true, font16x32, Color_IconBlue, Color_Bg_Black, x + (vallen * 14 - 14) / 2, y + 2, S(dwin_string.string()));
}
#if ENABLED(DWIN_MARLINUI_PORTRAIT)
dwin_string.set();
if (blink)
dwin_string.add(value);
else {
if (!TEST(axis_homed, axis))
while (const char c = *value++) dwin_string.add(c <= '.' ? c : '?');
else {
#if NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING)
if (!TEST(axis_trusted, axis))
dwin_string.add(TERN1(DWIN_MARLINUI_PORTRAIT, axis == Z_AXIS) ? PSTR(" ") : PSTR(" "));
else
#endif
dwin_string.add(value);
uint8_t vallen = utf8_strlen(value);
if (!ui.did_first_redraw) {
dwin_string.set();
dwin_string.add('X' + axis);
DWIN_Draw_String(true, font16x32, Color_IconBlue, Color_Bg_Black, x + (vallen * 14 - 14) / 2, y + 2, S(dwin_string.string()));
}
}
// For E_TOTAL there may be some characters to cover up
if (BOTH(DWIN_MARLINUI_PORTRAIT, LCD_SHOW_E_TOTAL) && axis == X_AXIS)
dwin_string.add(" ");
dwin_string.set();
if (blink)
dwin_string.add(value);
else if (!TEST(axis_homed, axis))
while (const char c = *value++) dwin_string.add(c <= '.' ? c : '?');
else if (NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING) && !TEST(axis_trusted, axis))
dwin_string.add(TERN1(DWIN_MARLINUI_PORTRAIT, axis == Z_AXIS) ? PSTR(" ") : PSTR(" "));
else
dwin_string.add(value);
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y + 32, S(dwin_string.string()));
// For E_TOTAL there may be some characters to cover up
if (BOTH(DWIN_MARLINUI_PORTRAIT, LCD_SHOW_E_TOTAL) && axis == X_AXIS)
dwin_string.add(" ");
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y + 32, S(dwin_string.string()));
#else // !DWIN_MARLINUI_PORTRAIT
if (!ui.did_first_redraw || ui.old_is_printing != print_job_timer.isRunning()) {
dwin_string.set();
dwin_string.add('X' + axis);
DWIN_Draw_String(true, font16x32, Color_IconBlue, Color_Bg_Black, x, y, S(dwin_string.string()));
}
dwin_string.set();
if (blink)
dwin_string.add(value);
else {
if (!TEST(axis_homed, axis))
while (const char c = *value++) dwin_string.add(c <= '.' ? c : '?');
else {
#if NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING)
if (!TEST(axis_trusted, axis))
dwin_string.add(TERN1(DWIN_MARLINUI_PORTRAIT, axis == Z_AXIS) ? PSTR(" ") : PSTR(" "));
else
#endif
dwin_string.add(value);
}
}
// For E_TOTAL there may be some characters to cover up
if (ENABLED(LCD_SHOW_E_TOTAL) && (!ui.did_first_redraw || ui.old_is_printing != print_job_timer.isRunning()) && axis == X_AXIS)
dwin_string.add(" ");
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x + 32, y + 4, S(dwin_string.string()));
#endif // !DWIN_MARLINUI_PORTRAIT
}
#if ENABLED(LCD_SHOW_E_TOTAL)
@ -97,20 +131,36 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const
FORCE_INLINE void _draw_e_value(const_float_t value, const uint16_t x, const uint16_t y) {
const uint8_t scale = value >= 100000.0f ? 10 : 1; // show cm after 99,999mm
if (!ui.did_first_redraw) {
// Extra spaces so we don't have to clear the 'Y' label separately
dwin_string.set("E ");
DWIN_Draw_String(true, font16x32, Color_IconBlue, Color_Bg_Black, x + (4 * 14 / 2) - 7, y + 2, S(dwin_string.string()));
}
#if ENABLED(DWIN_MARLINUI_PORTRAIT)
dwin_string.set(ui16tostr5rj(value / scale));
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y + 32, S(dwin_string.string()));
if (!ui.did_first_redraw) {
// Extra spaces to erase previous value
dwin_string.set("E ");
DWIN_Draw_String(true, font16x32, Color_IconBlue, Color_Bg_Black, x + (4 * 14 / 2) - 7, y + 2, S(dwin_string.string()));
}
// Extra spaces so we don't have to clear out the Y value separately
DWIN_Draw_String(true, font14x28, Color_IconBlue, Color_Bg_Black, x + (5 * 14), y + 32, S(scale == 1 ? "mm " : "cm "));
dwin_string.set(ui16tostr5rj(value / scale));
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y + 32, S(dwin_string.string()));
// Extra spaces to erase previous value
DWIN_Draw_String(true, font14x28, Color_IconBlue, Color_Bg_Black, x + (5 * 14), y + 32, S(scale == 1 ? "mm " : "cm "));
#else // !DWIN_MARLINUI_PORTRAIT
if (!ui.did_first_redraw || ui.old_is_printing != print_job_timer.isRunning()) {
dwin_string.set("E ");
DWIN_Draw_String(true, font16x32, Color_IconBlue, Color_Bg_Black, x, y, S(dwin_string.string()));
}
dwin_string.set(ui16tostr5rj(value / scale));
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x + 32, y + 4, S(dwin_string.string()));
DWIN_Draw_String(true, font14x28, Color_IconBlue, Color_Bg_Black, x + (32 + 70), y + 4, S(scale == 1 ? "mm " : "cm "));
#endif // !DWIN_MARLINUI_PORTRAIT
}
#endif
#endif // LCD_SHOW_E_TOTAL
//
// Fan Icon and Percentage
@ -126,6 +176,7 @@ FORCE_INLINE void _draw_fan_status(const uint16_t x, const uint16_t y) {
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y + STATUS_FAN_HEIGHT, S(dwin_string.string()));
}
else {
DWIN_ICON_AnimationControl(0x0000); // disable all icon animations (this is the only one)
DWIN_ICON_Show(ICON, ICON_Fan0, x + fanx, y);
dwin_string.set(PSTR(" "));
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y + STATUS_FAN_HEIGHT, S(dwin_string.string()));
@ -153,18 +204,35 @@ FORCE_INLINE void _draw_heater_status(const heater_id_t heater, const uint16_t x
#if HAS_HEATED_BED
static celsius_t old_bed_temp = 500, old_bed_target = 500;
static bool old_bed_on = false;
#if HAS_LEVELING
static bool old_leveling_on = false;
#endif
#endif
#if HAS_HOTEND && HAS_HEATED_BED
const bool isBed = heater < 0;
const float tc = (isBed ? thermalManager.degBed() : thermalManager.degHotend(heater)),
tt = (isBed ? thermalManager.degTargetBed() : thermalManager.degTargetHotend(heater));
const uint8_t ta = isBed ? thermalManager.isHeatingBed() : thermalManager.isHeatingHotend(heater);
const bool c_draw = tc != (isBed ? old_bed_temp : old_temp[heater]),
t_draw = tt != (isBed ? old_bed_target : old_target[heater]),
i_draw = ta != (isBed ? old_bed_on : old_on[heater]);
if (isBed) { old_bed_temp = tc; old_bed_target = tt; old_bed_on = ta; }
else { old_temp[heater] = tc; old_target[heater] = tt; old_on[heater] = ta; }
const float tc = isBed ? thermalManager.degBed() : thermalManager.degHotend(heater),
tt = isBed ? thermalManager.degTargetBed() : thermalManager.degTargetHotend(heater);
const bool ta = isBed ? thermalManager.isHeatingBed() : thermalManager.isHeatingHotend(heater);
bool c_draw = tc != (isBed ? old_bed_temp : old_temp[heater]),
t_draw = tt != (isBed ? old_bed_target : old_target[heater]),
i_draw = ta != (isBed ? old_bed_on : old_on[heater]);
if (isBed) {
#if HAS_LEVELING
if (!i_draw && planner.leveling_active != old_leveling_on) i_draw = true;
old_leveling_on = planner.leveling_active;
#endif
old_bed_temp = tc;
old_bed_target = tt;
old_bed_on = ta;
}
else {
old_temp[heater] = tc;
old_target[heater] = tt;
old_on[heater] = ta;
}
#elif HAS_HOTEND
constexpr bool isBed = false;
const float tc = thermalManager.degHotend(heater), tt = thermalManager.degTargetHotend(heater);
@ -175,7 +243,11 @@ FORCE_INLINE void _draw_heater_status(const heater_id_t heater, const uint16_t x
constexpr bool isBed = true;
const float tc = thermalManager.degBed(), tt = thermalManager.degTargetBed();
const uint8_t ta = thermalManager.isHeatingBed();
const bool c_draw = tc != old_temp[heater], t_draw = tt != old_target[heater], i_draw = ta != old_on[heater];
bool c_draw = tc != old_temp[heater], t_draw = tt != old_target[heater], i_draw = ta != old_on[heater];
#if HAS_LEVELING
if (!idraw && planner.leveling_active != old_leveling_on) i_draw = true;
old_leveling_on = tl;
#endif
old_bed_temp = tc; old_bed_target = tt; old_bed_on = ta;
#endif
@ -185,8 +257,10 @@ FORCE_INLINE void _draw_heater_status(const heater_id_t heater, const uint16_t x
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y, S(dwin_string.string()));
}
if (!ui.did_first_redraw || i_draw)
DWIN_ICON_Show(ICON, (isBed ? ICON_BedOff : ICON_HotendOff) + ta, x, y + STATUS_CHR_HEIGHT + 2);
if (!ui.did_first_redraw || i_draw){
const uint8_t ico = isBed ? (TERN0(HAS_LEVELING, planner.leveling_active) ? ICON_BedLevelOff : ICON_BedOff) : ICON_HotendOff;
DWIN_ICON_Show(ICON, ico + ta, x, y + STATUS_CHR_HEIGHT + 2);
}
if (!ui.did_first_redraw || c_draw) {
dwin_string.set(i16tostr3rj(tc + 0.5));
@ -220,14 +294,22 @@ void MarlinUI::draw_status_screen() {
// Logo/Status Icon
#define STATUS_LOGO_WIDTH 128
#define STATUS_LOGO_HEIGHT 40
DWIN_ICON_Show(ICON, ICON_LOGO_Marlin, (LCD_PIXEL_WIDTH - (STATUS_LOGO_WIDTH)) / 2, ((STATUS_HEATERS_Y - 4) - (STATUS_LOGO_HEIGHT)) / 2);
DWIN_ICON_Show(ICON, ICON_LOGO_Marlin,
#if ENABLED(DWIN_MARLINUI_PORTRAIT)
(LCD_PIXEL_WIDTH - (STATUS_LOGO_WIDTH)) / 2, ((STATUS_HEATERS_Y - 4) - (STATUS_LOGO_HEIGHT)) / 2
#else
5, 42
#endif
);
// Draw a frame around the x/y/z values
#if ENABLED(DWIN_MARLINUI_PORTRAIT)
DWIN_Draw_Rectangle(0, Select_Color, 0, 193, LCD_PIXEL_WIDTH, 260);
#else
//DWIN_Draw_Rectangle(0, Select_Color, LCD_PIXEL_WIDTH - 106, 50, LCD_PIXEL_WIDTH - 1, 230);
#endif
DWIN_Draw_Rectangle(0, Select_Color,
#if ENABLED(DWIN_MARLINUI_PORTRAIT)
0, 193, LCD_PIXEL_WIDTH, 260
#else
0, 115, LCD_PIXEL_WIDTH - 1, 152
#endif
);
}
uint16_t hx = STATUS_HEATERS_X;
@ -244,33 +326,22 @@ void MarlinUI::draw_status_screen() {
#endif
#if HAS_FAN
// Fan display, pinned to the right side
#if ENABLED(DWIN_MARLINUI_PORTRAIT)
_draw_fan_status(LCD_PIXEL_WIDTH - STATUS_CHR_WIDTH * 4, STATUS_FAN_Y);
#else
_draw_fan_status(212, STATUS_FAN_Y);
#endif
_draw_fan_status(LCD_PIXEL_WIDTH - STATUS_CHR_WIDTH * 5, STATUS_FAN_Y);
#endif
// Axis values
const xyz_pos_t lpos = current_position.asLogical();
const bool show_e_total = TERN0(LCD_SHOW_E_TOTAL, printingIsActive()); UNUSED(show_e_total);
#if ENABLED(DWIN_MARLINUI_PORTRAIT)
constexpr int16_t cpy = 195;
if (show_e_total) {
TERN_(LCD_SHOW_E_TOTAL, _draw_e_value(e_move_accumulator, 6, cpy));
}
else {
_draw_axis_value(X_AXIS, ftostr4sign(lpos.x), blink, 6, cpy);
TERN_(HAS_Y_AXIS, _draw_axis_value(Y_AXIS, ftostr4sign(lpos.y), blink, 95, cpy));
}
TERN_(HAS_Z_AXIS, _draw_axis_value(Z_AXIS, ftostr52sp(lpos.z), blink, 165, cpy));
#else
constexpr int16_t cpx = LCD_PIXEL_WIDTH - 104;
_draw_axis_value(X_AXIS, ftostr52sp(lpos.x), blink, cpx, STATUS_HEATERS_Y);
TERN_(HAS_Y_AXIS, _draw_axis_value(Y_AXIS, ftostr52sp(lpos.y), blink, cpx, STATUS_HEATERS_Y + 59));
TERN_(HAS_Z_AXIS, _draw_axis_value(Z_AXIS, ftostr52sp(lpos.z), blink, cpx, STATUS_HEATERS_Y + 118));
#endif
constexpr int16_t cpy = TERN(DWIN_MARLINUI_PORTRAIT, 195, 117);
if (show_e_total) {
TERN_(LCD_SHOW_E_TOTAL, _draw_e_value(e_move_accumulator, TERN(DWIN_MARLINUI_PORTRAIT, 6, 75), cpy));
}
else {
_draw_axis_value(X_AXIS, ftostr4sign(lpos.x), blink, TERN(DWIN_MARLINUI_PORTRAIT, 6, 75), cpy);
TERN_(HAS_Y_AXIS, _draw_axis_value(Y_AXIS, ftostr4sign(lpos.y), blink, TERN(DWIN_MARLINUI_PORTRAIT, 95, 184), cpy));
}
TERN_(HAS_Z_AXIS, _draw_axis_value(Z_AXIS, ftostr52sp(lpos.z), blink, TERN(DWIN_MARLINUI_PORTRAIT, 165, 300), cpy));
// Feedrate
static uint16_t old_fp = 0;
@ -278,9 +349,9 @@ void MarlinUI::draw_status_screen() {
old_fp = feedrate_percentage;
_draw_feedrate_status(i16tostr3rj(feedrate_percentage),
#if ENABLED(DWIN_MARLINUI_PORTRAIT)
5, 290
5, 290
#else
294, STATUS_HEATERS_Y
14, 195
#endif
);
}
@ -317,25 +388,23 @@ void MarlinUI::draw_status_screen() {
time.toDigital(buffer);
dwin_string.set(" ");
dwin_string.add(buffer);
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, 280, 100, S(dwin_string.string()));
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, 230, 170, S(dwin_string.string()));
#if ENABLED(LCD_SHOW_E_TOTAL)
if (show_e_total && TERN1(SHOW_REMAINING_TIME, !blink)) { // if SHOW_REMAINING_TIME is also
const uint8_t escale = e_move_accumulator >= 100000.0f ? 10 : 1; // show cm after 99,000mm
DWIN_Draw_String(true, font14x28, Color_IconBlue, Color_Bg_Black, 249, 135, S("E"));
dwin_string.set(ui16tostr5rj(e_move_accumulator * escale));
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, 263, 135, S(dwin_string.string()));
DWIN_Draw_String(true, font14x28, Color_IconBlue, Color_Bg_Black, 333, 135, S(escale==1 ? "mm" : "cm"));
}
#endif
#if ENABLED(SHOW_REMAINING_TIME)
if (!show_e_total || blink) {
DWIN_Draw_String(true, font14x28, Color_IconBlue, Color_Bg_Black, 249, 135, S(" R "));
if (print_job_timer.isRunning()) {
time = get_remaining_time();
time.toDigital(buffer);
dwin_string.set(buffer);
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, 291, 135, S(dwin_string.string()));
DWIN_Draw_String(true, font14x28, Color_IconBlue, Color_Bg_Black, 336, 170, S(" R "));
if (print_job_timer.isPaused() && blink)
dwin_string.set(" ");
else {
time.toDigital(buffer);
dwin_string.set(buffer);
}
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, 378, 170, S(dwin_string.string()));
}
else if (!ui.did_first_redraw || ui.old_is_printing != print_job_timer.isRunning()) {
dwin_string.set(" ");
DWIN_Draw_String(true, font14x28, Color_IconBlue, Color_Bg_Black, 336, 170, S(dwin_string.string()));
}
#endif
#endif
@ -343,9 +412,11 @@ void MarlinUI::draw_status_screen() {
//
// Progress Bar
//
constexpr int16_t pb_margin = 5, pb_left = pb_margin, pb_height = 60,
pb_right = LCD_PIXEL_WIDTH - TERN(DWIN_MARLINUI_PORTRAIT, 0, 107) - pb_margin,
pb_bottom = TERN(DWIN_MARLINUI_PORTRAIT, 410, 230),
constexpr int16_t pb_margin = 5,
pb_left = pb_margin + TERN(DWIN_MARLINUI_PORTRAIT, 0, 90),
pb_height = TERN(DWIN_MARLINUI_PORTRAIT, 60, 20),
pb_right = LCD_PIXEL_WIDTH - pb_margin,
pb_bottom = TERN(DWIN_MARLINUI_PORTRAIT, 410, 220),
pb_top = pb_bottom - pb_height,
pb_width = pb_right - pb_left;
@ -385,6 +456,7 @@ void MarlinUI::draw_status_screen() {
draw_status_message(blink);
ui.did_first_redraw = true;
ui.old_is_printing = print_job_timer.isRunning();
}
#endif // IS_DWIN_MARLINUI

View File

@ -244,6 +244,7 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
#if IS_DWIN_MARLINUI
bool MarlinUI::did_first_redraw;
bool MarlinUI::old_is_printing;
#endif
// Encoder Handling

View File

@ -468,6 +468,7 @@ public:
#if IS_DWIN_MARLINUI
static bool did_first_redraw;
static bool old_is_printing;
#endif
#if EITHER(BABYSTEP_ZPROBE_GFX_OVERLAY, MESH_EDIT_GFX_OVERLAY)