Merge upstream changes from Marlin 2.1.1

This commit is contained in:
Stefan Kalscheuer
2022-09-03 09:23:32 +02:00
parent 626283aadb
commit 986e416c7f
1610 changed files with 73839 additions and 40857 deletions

View File

@@ -46,6 +46,7 @@ void DWIN_Startup() {
if (success) DEBUG_ECHOLNPGM("ok."); else DEBUG_ECHOLNPGM("error.");
DWIN_Frame_SetDir(TERN(DWIN_MARLINUI_LANDSCAPE, 0, 1));
DWIN_Frame_Clear(Color_Bg_Black); // MarlinUI handles the bootscreen so just clear here
DWIN_JPG_ShowAndCache(3);
DWIN_UpdateLCD();
}

View File

@@ -28,11 +28,6 @@
#include "../../../inc/MarlinConfigPre.h"
#if ENABLED(DWIN_MARLINUI_LANDSCAPE)
#define DWIN_WIDTH 480
#define DWIN_HEIGHT 272
#endif
#include "../common/dwin_api.h"
// Picture ID
@@ -69,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

@@ -27,33 +27,35 @@
#include "dwin_string.h"
//#include "../../fontutils.h"
uint8_t DWIN_String::data[];
char DWIN_String::data[];
uint16_t DWIN_String::span;
uint8_t DWIN_String::len;
uint8_t DWIN_String::length;
void DWIN_String::set() {
//*data = 0x00;
memset(data, 0x00, sizeof(data));
span = 0;
len = 0;
length = 0;
}
uint8_t read_byte(uint8_t *byte) { return *byte; }
uint8_t read_byte(const uint8_t *byte) { return *byte; }
/**
* Add a string, applying substitutions for the following characters:
*
* $ displays the clipped string given by fstr or cstr
* = displays '0'....'10' for indexes 0 - 10
* ~ displays '1'....'11' for indexes 0 - 10
* * displays 'E1'...'E11' for indexes 0 - 10 (By default. Uses LCD_FIRST_TOOL)
* @ displays an axis name such as XYZUVW, or E for an extruder
*/
void DWIN_String::add(uint8_t *string, const int8_t index, uint8_t *itemString/*=nullptr*/) {
wchar_t wchar;
void DWIN_String::add(const char *tpl, const int8_t index, const char *cstr/*=nullptr*/, FSTR_P const fstr/*=nullptr*/) {
lchar_t wc;
while (*string) {
string = get_utf8_value_cb(string, read_byte, &wchar);
if (wchar > 255) wchar |= 0x0080;
uint8_t ch = uint8_t(wchar & 0x00FF);
while (*tpl) {
tpl = get_utf8_value_cb(tpl, read_byte, wc);
if (wc > 255) wc |= 0x0080;
const uint8_t ch = uint8_t(wc & 0x00FF);
if (ch == '=' || ch == '~' || ch == '*') {
if (index >= 0) {
@@ -62,48 +64,48 @@ void DWIN_String::add(uint8_t *string, const int8_t index, uint8_t *itemString/*
if (inum >= 10) { add_character('0' + (inum / 10)); inum %= 10; }
add_character('0' + inum);
}
else {
add(index == -2 ? GET_TEXT(MSG_CHAMBER) : GET_TEXT(MSG_BED));
}
continue;
else
add(index == -2 ? GET_TEXT_F(MSG_CHAMBER) : GET_TEXT_F(MSG_BED));
}
else if (ch == '$' && itemString) {
add(itemString);
continue;
}
add_character(ch);
else if (ch == '$' && fstr)
add(fstr);
else if (ch == '$' && cstr)
add(cstr);
else if (ch == '@')
add_character(AXIS_CHAR(index));
else
add_character(ch);
}
eol();
}
void DWIN_String::add(uint8_t *string, uint8_t max_len) {
wchar_t wchar;
while (*string && max_len) {
string = get_utf8_value_cb(string, read_byte, &wchar);
void DWIN_String::add(const char *cstr, uint8_t max_len/*=MAX_STRING_LENGTH*/) {
lchar_t wc;
while (*cstr && max_len) {
cstr = get_utf8_value_cb(cstr, read_byte, wc);
/*
if (wchar > 255) wchar |= 0x0080;
uint8_t ch = uint8_t(wchar & 0x00FF);
if (wc > 255) wc |= 0x0080;
const uint8_t ch = uint8_t(wc & 0x00FF);
add_character(ch);
*/
add(wchar);
add(wc);
max_len--;
}
eol();
}
void DWIN_String::add(wchar_t character) {
void DWIN_String::add(const lchar_t &wc) {
int ret;
size_t idx = 0;
dwin_charmap_t pinval;
dwin_charmap_t *copy_address = nullptr;
pinval.uchar = character;
pinval.uchar = wc;
pinval.idx = -1;
// For 8-bit ASCII just print the single character
char str[] = { '?', 0 };
if (character < 255) {
str[0] = (char)character;
if (wc < 255) {
str[0] = (char)wc;
}
else {
copy_address = nullptr;
@@ -127,18 +129,18 @@ void DWIN_String::add(wchar_t character) {
if (str[1]) add_character(str[1]);
}
void DWIN_String::add_character(const uint8_t character) {
if (len < MAX_STRING_LENGTH) {
data[len] = character;
len++;
void DWIN_String::add_character(const char character) {
if (length < MAX_STRING_LENGTH) {
data[length] = character;
length++;
//span += glyph(character)->DWidth;
}
}
void DWIN_String::rtrim(const uint8_t character) {
while (len) {
if (data[len - 1] == 0x20 || data[len - 1] == character) {
len--;
void DWIN_String::rtrim(const char character) {
while (length) {
if (data[length - 1] == 0x20 || data[length - 1] == character) {
length--;
//span -= glyph(data[length])->DWidth;
eol();
}
@@ -147,18 +149,18 @@ void DWIN_String::rtrim(const uint8_t character) {
}
}
void DWIN_String::ltrim(const uint8_t character) {
void DWIN_String::ltrim(const char character) {
uint16_t i, j;
for (i = 0; (i < len) && (data[i] == 0x20 || data[i] == character); i++) {
for (i = 0; (i < length) && (data[i] == 0x20 || data[i] == character); i++) {
//span -= glyph(data[i])->DWidth;
}
if (i == 0) return;
for (j = 0; i < len; data[j++] = data[i++]);
len = j;
for (j = 0; i < length; data[j++] = data[i++]);
length = j;
eol();
}
void DWIN_String::trim(const uint8_t character) {
void DWIN_String::trim(const char character) {
rtrim(character);
ltrim(character);
}

View File

@@ -21,13 +21,15 @@
*/
#pragma once
// TODO: Make AVR-compatible with separate ROM / RAM string methods
#include "../../fontutils.h"
#include "../../marlinui.h"
#include <stdint.h>
typedef struct _dwin_charmap_t {
wchar_t uchar; // the unicode char
lchar_t uchar; // the unicode char
uint8_t idx; // the glyph of the char in the ROM
uint8_t idx2; // the char used to be combined with the idx to simulate a single char
} dwin_charmap_t;
@@ -41,45 +43,87 @@ class DWIN_String {
//static glyph_t *glyphs[256];
//static font_t *font_header;
static uint8_t data[MAX_STRING_LENGTH + 1];
static char data[MAX_STRING_LENGTH + 1];
static uint16_t span; // in pixels
static uint8_t len; // in characters
static void add_character(const uint8_t character);
static void eol() { data[len] = 0x00; }
static void add_character(const char character);
static void eol() { data[length] = 0x00; }
public:
static uint8_t length; // in characters
//static void set_font(const uint8_t *font);
//static void add_glyphs(const uint8_t *font);
//static font_t *font() { return font_header; };
//static uint16_t font_height() { return font_header->FontAscent - font_header->FontDescent; }
//static glyph_t *glyph(uint8_t character) { return glyphs[character] ?: glyphs[0x3F]; } /* Use '?' for unknown glyphs */
//static inline glyph_t *glyph(uint8_t *character) { return glyph(*character); }
//static glyph_t *glyph(uint8_t *character) { return glyph(*character); }
/**
* @brief Set the string empty
*/
static void set();
//static void add(uint8_t character) { add_character(character); eol(); }
static void add(wchar_t character);
static void add(uint8_t *string, uint8_t max_len=MAX_STRING_LENGTH);
static void add(uint8_t *string, const int8_t index, uint8_t *itemString=nullptr);
static void set(uint8_t *string) { set(); add(string); }
static void set(wchar_t character) { set(); add(character); }
static void set(uint8_t *string, int8_t index, const char *itemString=nullptr) { set(); add(string, index, (uint8_t *)itemString); }
static inline void set(FSTR_P fstring) { set((uint8_t *)fstring); }
static inline void set(const char *string) { set((uint8_t *)string); }
static inline void set(const char *string, int8_t index, const char *itemString=nullptr) { set((uint8_t *)string, index, itemString); }
static inline void add(const char *string) { add((uint8_t *)string); }
static void trim(const uint8_t character=0x20);
static void rtrim(const uint8_t character=0x20);
static void ltrim(const uint8_t character=0x20);
//static void add(const char character) { add_character(character); eol(); }
static void truncate(uint8_t maxlen) { if (len > maxlen) { len = maxlen; eol(); } }
/**
* @brief Append a UTF-8 character
*
* @param wc The UTF-8 character
*/
static void add(const lchar_t &wc);
static void set(const lchar_t &wc) { set(); add(wc); }
static inline uint8_t length() { return len; }
static inline uint16_t width() { return span; }
static inline uint8_t *string() { return data; }
static uint16_t center(uint16_t width) { return span > width ? 0 : (width - span) / 2; }
/**
* @brief Append / Set C-string
*
* @param cstr The string
* @param max_len Character limit
*/
static void add(const char *cstr, uint8_t max_len=MAX_STRING_LENGTH);
static void set(const char *cstr) { set(); add(cstr); }
/**
* @brief Append / Set F-string
*
* @param fstr The string
* @param max_len Character limit
*/
static void add(FSTR_P const fstr, uint8_t max_len=MAX_STRING_LENGTH) { add(FTOP(fstr), max_len); }
static void set(FSTR_P const fstr) { set(FTOP(fstr)); }
/**
* @brief Append / Set C-string with optional substitution
*
* @param tpl A string with optional substitution
* @param index An index
* @param cstr An SRAM C-string to use for $ substitution
* @param fstr A ROM F-string to use for $ substitution
*/
static void add(const char *tpl, const int8_t index, const char *cstr=nullptr, FSTR_P const fstr=nullptr);
static void set(const char *tpl, const int8_t index, const char *cstr=nullptr, FSTR_P const fstr=nullptr) { set(); add(tpl, index, cstr, fstr); }
/**
* @brief Append / Set F-string with optional substitution
*
* @param ftpl A ROM F-string with optional substitution
* @param index An index
* @param cstr An SRAM C-string to use for $ substitution
* @param fstr A ROM F-string to use for $ substitution
*/
static void add(FSTR_P const ftpl, const int8_t index, const char *cstr=nullptr, FSTR_P const fstr=nullptr) { add(FTOP(ftpl), index, cstr, fstr); }
static void set(FSTR_P const ftpl, const int8_t index, const char *cstr=nullptr, FSTR_P const fstr=nullptr) { set(); add(ftpl, index, cstr, fstr); }
// Common string ops
static void trim(const char character=' ');
static void rtrim(const char character=' ');
static void ltrim(const char character=' ');
static void truncate(const uint8_t maxlen) { if (length > maxlen) { length = maxlen; eol(); } }
// Accessors
static char *string() { return data; }
static uint16_t width() { return span; }
static uint16_t center(const uint16_t width) { return span > width ? 0 : (width - span) / 2; }
};
int dwin_charmap_compare(dwin_charmap_t *v1, dwin_charmap_t *v2);

View File

@@ -16,7 +16,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
@@ -56,20 +56,20 @@ void lcd_put_int(const int i) {
}
int lcd_put_dwin_string() {
DWIN_Draw_String(dwin_font.solid, dwin_font.index, dwin_font.fg, dwin_font.bg, cursor.x, cursor.y, (char*)dwin_string.string());
lcd_advance_cursor(dwin_string.length());
return dwin_string.length();
DWIN_Draw_String(dwin_font.solid, dwin_font.index, dwin_font.fg, dwin_font.bg, cursor.x, cursor.y, dwin_string.string());
lcd_advance_cursor(dwin_string.length);
return dwin_string.length;
}
// return < 0 on error
// return the advanced cols
int lcd_put_wchar_max(wchar_t c, pixel_len_t max_length) {
int lcd_put_lchar_max(const lchar_t &c, const pixel_len_t max_length) {
dwin_string.set(c);
dwin_string.truncate(max_length);
// Draw the char(s) at the cursor and advance the cursor
DWIN_Draw_String(dwin_font.solid, dwin_font.index, dwin_font.fg, dwin_font.bg, cursor.x, cursor.y, (char*)dwin_string.string());
lcd_advance_cursor(dwin_string.length());
return dwin_string.length();
DWIN_Draw_String(dwin_font.solid, dwin_font.index, dwin_font.fg, dwin_font.bg, cursor.x, cursor.y, dwin_string.string());
lcd_advance_cursor(dwin_string.length);
return dwin_string.length;
}
/**
@@ -83,35 +83,34 @@ int lcd_put_wchar_max(wchar_t c, pixel_len_t max_length) {
*
* Draw a UTF-8 string
*/
static int lcd_put_u8str_max_cb(const char * utf8_str, uint8_t (*cb_read_byte)(uint8_t * str), pixel_len_t max_length) {
uint8_t *p = (uint8_t *)utf8_str;
static int lcd_put_u8str_max_cb(const char * utf8_str, read_byte_cb_t cb_read_byte, const pixel_len_t max_length) {
const uint8_t *p = (uint8_t *)utf8_str;
dwin_string.set();
while (dwin_string.length() < max_length) {
wchar_t ch = 0;
p = get_utf8_value_cb(p, cb_read_byte, &ch);
if (!ch) break;
dwin_string.add(ch);
while (dwin_string.length < max_length) {
lchar_t wc;
p = get_utf8_value_cb(p, cb_read_byte, wc);
if (!wc) break;
dwin_string.add(wc);
}
DWIN_Draw_String(dwin_font.solid, dwin_font.index, dwin_font.fg, dwin_font.bg, cursor.x, cursor.y, (char*)dwin_string.string());
lcd_advance_cursor(dwin_string.length());
return dwin_string.length();
DWIN_Draw_String(dwin_font.solid, dwin_font.index, dwin_font.fg, dwin_font.bg, cursor.x, cursor.y, dwin_string.string());
lcd_advance_cursor(dwin_string.length);
return dwin_string.length;
}
int lcd_put_u8str_max(const char * utf8_str, pixel_len_t max_length) {
int lcd_put_u8str_max(const char * utf8_str, const pixel_len_t max_length) {
return lcd_put_u8str_max_cb(utf8_str, read_byte_ram, max_length);
}
int lcd_put_u8str_max_P(PGM_P utf8_str_P, pixel_len_t max_length) {
return lcd_put_u8str_max_cb(utf8_str_P, read_byte_rom, max_length);
int lcd_put_u8str_max_P(PGM_P utf8_pstr, const pixel_len_t max_length) {
return lcd_put_u8str_max_cb(utf8_pstr, read_byte_rom, max_length);
}
lcd_uint_t lcd_put_u8str_ind_P(PGM_P const pstr, const int8_t ind, PGM_P const inStr/*=nullptr*/, const lcd_uint_t maxlen/*=LCD_WIDTH*/) {
dwin_string.set();
dwin_string.add((uint8_t*)pstr, ind, (uint8_t*)inStr);
lcd_uint_t lcd_put_u8str_P(PGM_P const ptpl, const int8_t ind, const char * const cstr/*=nullptr*/, FSTR_P const fstr/*=nullptr*/, const lcd_uint_t maxlen/*=LCD_WIDTH*/) {
dwin_string.set(ptpl, ind, cstr, fstr);
dwin_string.truncate(maxlen);
DWIN_Draw_String(dwin_font.solid, dwin_font.index, dwin_font.fg, dwin_font.bg, cursor.x, cursor.y, (char*)dwin_string.string());
lcd_advance_cursor(dwin_string.length());
return dwin_string.length();
DWIN_Draw_String(dwin_font.solid, dwin_font.index, dwin_font.fg, dwin_font.bg, cursor.x, cursor.y, dwin_string.string());
lcd_advance_cursor(dwin_string.length);
return dwin_string.length;
}
#if ENABLED(DEBUG_LCDPRINT)

View File

@@ -16,7 +16,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#pragma once

View File

@@ -16,7 +16,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
@@ -79,16 +79,12 @@ void MarlinUI::set_font(const uint8_t font_nr) {
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);
}
void MarlinUI::init_lcd() { DWIN_Startup(); }
// This LCD should clear where it will draw anew
void MarlinUI::clear_lcd() {
DWIN_ICON_AnimationControl(0x0000); // disable all icon animations
DWIN_JPG_ShowAndCache(3);
DWIN_Frame_Clear(Color_Bg_Black);
DWIN_UpdateLCD();
@@ -98,30 +94,40 @@ void MarlinUI::clear_lcd() {
#if ENABLED(SHOW_BOOTSCREEN)
void MarlinUI::show_bootscreen() {
clear_lcd();
dwin_string.set(F(SHORT_BUILD_VERSION));
#if ENABLED(SHOW_CUSTOM_BOOTSCREEN) && !defined(CUSTOM_BOOTSCREEN_TIMEOUT)
#define CUSTOM_BOOTSCREEN_TIMEOUT 3000
#endif
#if ENABLED(DWIN_MARLINUI_PORTRAIT)
#define LOGO_CENTER ((LCD_PIXEL_WIDTH) / 2)
#define INFO_CENTER LOGO_CENTER
#define VERSION_Y 330
DWIN_ICON_Show(BOOT_ICON, ICON_MarlinBoot, LOGO_CENTER - 266 / 2, 15);
#else
#define LOGO_CENTER (280 / 2)
#define INFO_CENTER ((LCD_PIXEL_WIDTH) - 200 / 2)
#define VERSION_Y 84
#endif
DWIN_Draw_String(false, font10x20, Color_Yellow, Color_Bg_Black, INFO_CENTER - (dwin_string.length * 10) / 2, VERSION_Y, S(dwin_string.string()));
TERN_(SHOW_CUSTOM_BOOTSCREEN, safe_delay(CUSTOM_BOOTSCREEN_TIMEOUT));
clear_lcd();
DWIN_ICON_Show(BOOT_ICON, ICON_MarlinBoot, LOGO_CENTER - 266 / 2, 15);
#if ENABLED(DWIN_MARLINUI_PORTRAIT)
DWIN_ICON_Show(BOOT_ICON, ICON_OpenSource, LOGO_CENTER - 174 / 2, 280);
DWIN_ICON_Show(BOOT_ICON, ICON_GitHubURL, LOGO_CENTER - 180 / 2, 420);
DWIN_ICON_Show(BOOT_ICON, ICON_MarlinURL, LOGO_CENTER - 100 / 2, 440);
DWIN_ICON_Show(BOOT_ICON, ICON_Copyright, LOGO_CENTER - 126 / 2, 460);
#else
#define LOGO_CENTER (280 / 2)
#define INFO_CENTER ((LCD_PIXEL_WIDTH) - 200 / 2)
#define VERSION_Y 84
DWIN_ICON_Show(BOOT_ICON, ICON_MarlinBoot, LOGO_CENTER - 266 / 2, 15);
DWIN_ICON_Show(BOOT_ICON, ICON_OpenSource, INFO_CENTER - 174 / 2, 60);
DWIN_ICON_Show(BOOT_ICON, ICON_GitHubURL, INFO_CENTER - 180 / 2, 130);
DWIN_ICON_Show(BOOT_ICON, ICON_MarlinURL, INFO_CENTER - 100 / 2, 152);
DWIN_ICON_Show(BOOT_ICON, ICON_Copyright, INFO_CENTER - 126 / 2, 200);
#endif
DWIN_Draw_String(false, font10x20, Color_Yellow, Color_Bg_Black, INFO_CENTER - (dwin_string.length() * 10) / 2, VERSION_Y, S(dwin_string.string()));
DWIN_Draw_String(false, font10x20, Color_Yellow, Color_Bg_Black, INFO_CENTER - (dwin_string.length * 10) / 2, VERSION_Y, S(dwin_string.string()));
DWIN_UpdateLCD();
}
@@ -160,11 +166,11 @@ void MarlinUI::draw_kill_screen() {
slen = utf8_strlen(S(GET_TEXT_F(MSG_HALTED)));
lcd_moveto(cx - (slen / 2), cy);
lcd_put_u8str_P((const char*)GET_TEXT_F(MSG_HALTED));
lcd_put_u8str(GET_TEXT_F(MSG_HALTED));
slen = utf8_strlen(S(GET_TEXT_F(MSG_HALTED)));
lcd_moveto(cx - (slen / 2), cy + 1);
lcd_put_u8str_P((const char*)GET_TEXT_F(MSG_HALTED));
lcd_put_u8str(GET_TEXT_F(MSG_HALTED));
}
//
@@ -207,7 +213,7 @@ void MarlinUI::draw_status_message(const bool blink) {
lcd_put_u8str(status_message);
// Fill the rest with spaces
while (slen < max_status_chars) { lcd_put_wchar(' '); ++slen; }
while (slen < max_status_chars) { lcd_put_lchar(' '); ++slen; }
}
}
else {
@@ -221,10 +227,10 @@ void MarlinUI::draw_status_message(const bool blink) {
// If the string doesn't completely fill the line...
if (rlen < max_status_chars) {
lcd_put_wchar('.'); // Always at 1+ spaces left, draw a dot
lcd_put_lchar('.'); // Always at 1+ spaces left, draw a dot
uint8_t chars = max_status_chars - rlen; // Amount of space left in characters
if (--chars) { // Draw a second dot if there's space
lcd_put_wchar('.');
lcd_put_lchar('.');
if (--chars)
lcd_put_u8str_max(status_message, chars); // Print a second copy of the message
}
@@ -248,7 +254,7 @@ void MarlinUI::draw_status_message(const bool blink) {
lcd_put_u8str_max(status_message, max_status_chars);
// Fill the rest with spaces if there are missing spaces
while (slen < max_status_chars) { lcd_put_wchar(' '); ++slen; }
while (slen < max_status_chars) { lcd_put_lchar(' '); ++slen; }
}
#endif
@@ -258,7 +264,7 @@ void MarlinUI::draw_status_message(const bool blink) {
void MarlinUI::_set_brightness() { DWIN_LCD_Brightness(backlight ? brightness : 0); }
#endif
#if HAS_LCD_MENU
#if HAS_MARLINUI_MENU
#include "../../menu/menu.h"
@@ -268,7 +274,7 @@ void MarlinUI::draw_status_message(const bool blink) {
dwin_font.solid = false;
dwin_font.fg = Color_White;
dwin_string.set("E");
dwin_string.set('E');
dwin_string.add('1' + extruder);
dwin_string.add(' ');
dwin_string.add(i16tostr3rj(thermalManager.degHotend(extruder)));
@@ -276,9 +282,9 @@ void MarlinUI::draw_status_message(const bool blink) {
if (get_blink() || !thermalManager.heater_idle[thermalManager.idle_index_for_id(extruder)].timed_out)
dwin_string.add(i16tostr3rj(thermalManager.degTargetHotend(extruder)));
else
dwin_string.add(PSTR(" "));
dwin_string.add(F(" "));
lcd_moveto(LCD_WIDTH - dwin_string.length(), row);
lcd_moveto(LCD_WIDTH - dwin_string.length, row);
lcd_put_dwin_string();
}
@@ -305,7 +311,7 @@ void MarlinUI::draw_status_message(const bool blink) {
// Draw a static line of text in the same idiom as a menu item
void MenuItem_static::draw(const uint8_t row, PGM_P const pstr, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) {
void MenuItem_static::draw(const uint8_t row, FSTR_P const ftpl, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) {
// Call mark_as_selected to draw a bigger selection box
// and draw the text without a background
if (mark_as_selected(row, (bool)(style & SS_INVERT), true)) {
@@ -314,15 +320,15 @@ void MarlinUI::draw_status_message(const bool blink) {
dwin_font.fg = Color_White;
dwin_string.set();
const int8_t plen = pstr ? utf8_strlen_P(pstr) : 0,
const int8_t plen = ftpl ? utf8_strlen(ftpl) : 0,
vlen = vstr ? utf8_strlen(vstr) : 0;
if (style & SS_CENTER) {
int8_t pad = (LCD_WIDTH - 1 - plen - vlen) / 2;
while (--pad) dwin_string.add(' ');
}
if (plen) dwin_string.add((uint8_t*)pstr, itemIndex, (uint8_t*)itemString);
if (vlen) dwin_string.add((uint8_t*)vstr);
if (plen) dwin_string.add(ftpl, itemIndex, itemStringC, itemStringF);
if (vlen) dwin_string.add(vstr);
if (style & SS_CENTER) {
int8_t pad = (LCD_WIDTH - 1 - plen - vlen) / 2;
while (--pad) dwin_string.add(' ');
@@ -334,15 +340,15 @@ void MarlinUI::draw_status_message(const bool blink) {
}
// Draw a generic menu item
void MenuItemBase::_draw(const bool sel, const uint8_t row, PGM_P const pstr, const char, const char post_char) {
void MenuItemBase::_draw(const bool sel, const uint8_t row, FSTR_P const ftpl, const char, const char post_char) {
if (mark_as_selected(row, sel)) {
ui.set_font(DWIN_FONT_MENU);
dwin_font.solid = false;
dwin_font.fg = Color_White;
dwin_string.set(pstr, itemIndex, itemString);
dwin_string.set(ftpl, itemIndex, itemStringC, itemStringF);
pixel_len_t n = LCD_WIDTH - 1 - dwin_string.length();
pixel_len_t n = LCD_WIDTH - 1 - dwin_string.length;
while (--n > 1) dwin_string.add(' ');
dwin_string.add(post_char);
@@ -355,15 +361,15 @@ void MarlinUI::draw_status_message(const bool blink) {
//
// Draw a menu item with an editable value
//
void MenuEditItemBase::draw(const bool sel, const uint8_t row, PGM_P const pstr, const char* const data, const bool pgm) {
void MenuEditItemBase::draw(const bool sel, const uint8_t row, FSTR_P const ftpl, const char * const inStr, const bool pgm) {
if (mark_as_selected(row, sel)) {
ui.set_font(DWIN_FONT_MENU);
dwin_font.solid = false;
dwin_font.fg = Color_White;
const uint8_t vallen = (pgm ? utf8_strlen_P(data) : utf8_strlen(S(data)));
const uint8_t vallen = (pgm ? utf8_strlen_P(inStr) : utf8_strlen(S(inStr)));
dwin_string.set(pstr, itemIndex, itemString);
dwin_string.set(ftpl, itemIndex, itemStringC, itemStringF);
if (vallen) dwin_string.add(':');
lcd_moveto(1, row);
@@ -371,7 +377,7 @@ void MarlinUI::draw_status_message(const bool blink) {
if (vallen) {
dwin_font.fg = Color_Yellow;
dwin_string.set(data);
dwin_string.set(inStr);
lcd_moveto(LCD_WIDTH - vallen - 1, row);
lcd_put_dwin_string();
}
@@ -381,13 +387,12 @@ void MarlinUI::draw_status_message(const bool blink) {
//
// Draw an edit screen with label and current value
//
void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char* const value/*=nullptr*/) {
void MenuEditItemBase::draw_edit_screen(FSTR_P const fstr, const char* const value/*=nullptr*/) {
ui.encoder_direction_normal();
const dwin_coord_t labellen = utf8_strlen_P(pstr), vallen = utf8_strlen(value);
const dwin_coord_t labellen = utf8_strlen(fstr), vallen = utf8_strlen(value);
dwin_string.set();
dwin_string.add((uint8_t*)pstr, itemIndex);
dwin_string.set(FTOP(fstr), itemIndex);
if (vallen) dwin_string.add(':'); // If a value is included, add a colon
// Assume the label is alpha-numeric (with a descender)
@@ -400,14 +405,12 @@ void MarlinUI::draw_status_message(const bool blink) {
// If a value is included, print the value in larger text below the label
if (vallen) {
dwin_string.set();
dwin_string.add(value);
dwin_string.set(value);
const dwin_coord_t by = (row * MENU_LINE_HEIGHT) + MENU_FONT_HEIGHT + EXTRA_ROW_HEIGHT / 2;
DWIN_Draw_String(true, font16x32, Color_Yellow, Color_Bg_Black, (LCD_PIXEL_WIDTH - vallen * 16) / 2, by, S(dwin_string.string()));
extern screenFunc_t _manual_move_func_ptr;
if (ui.currentScreen != _manual_move_func_ptr && !ui.external_control) {
if (ui.can_show_slider()) {
const dwin_coord_t slider_length = LCD_PIXEL_WIDTH - TERN(DWIN_MARLINUI_LANDSCAPE, 120, 20),
slider_height = 16,
@@ -424,31 +427,31 @@ void MarlinUI::draw_status_message(const bool blink) {
}
}
inline void draw_boxed_string(const bool yesopt, PGM_P const pstr, const bool inv) {
const uint8_t len = utf8_strlen_P(pstr),
inline void draw_boxed_string(const bool yesopt, FSTR_P const fstr, const bool inv) {
const uint8_t len = utf8_strlen(fstr),
mar = TERN(DWIN_MARLINUI_PORTRAIT, 1, 4),
col = yesopt ? LCD_WIDTH - mar - len : mar,
row = (LCD_HEIGHT >= 8 ? LCD_HEIGHT / 2 + 3 : LCD_HEIGHT - 1);
lcd_moveto(col, row);
DWIN_Draw_Box(1, inv ? Select_Color : Color_Bg_Black, cursor.x - dwin_font.width, cursor.y + 1, dwin_font.width * (len + 2), dwin_font.height + 2);
lcd_put_u8str_P(col, row, pstr);
lcd_put_u8str(col, row, fstr);
}
void MenuItem_confirm::draw_select_screen(
PGM_P const yes, PGM_P const no, const bool yesno,
PGM_P const pref, const char * const string/*=nullptr*/, PGM_P const suff/*=nullptr*/
FSTR_P const yes, FSTR_P const no, const bool yesno,
FSTR_P const pref, const char * const string/*=nullptr*/, FSTR_P const suff/*=nullptr*/
) {
ui.set_font(DWIN_FONT_MENU);
dwin_font.solid = false;
dwin_font.fg = Color_White;
ui.draw_select_screen_prompt(pref, string, suff);
draw_boxed_string(false, no, !yesno);
draw_boxed_string(true, yes, yesno);
if (no) draw_boxed_string(false, no, !yesno);
if (yes) draw_boxed_string(true, yes, yesno);
}
#if ENABLED(SDSUPPORT)
void MenuItem_sdbase::draw(const bool sel, const uint8_t row, PGM_P const, CardReader &theCard, const bool isDir) {
void MenuItem_sdbase::draw(const bool sel, const uint8_t row, FSTR_P const, CardReader &theCard, const bool isDir) {
if (mark_as_selected(row, sel)) {
dwin_string.set();
@@ -458,8 +461,8 @@ void MarlinUI::draw_status_message(const bool blink) {
maxlen -= 2;
}
dwin_string.add((uint8_t*)ui.scrolled_filename(theCard, maxlen, row, sel), maxlen);
uint8_t n = maxlen - dwin_string.length();
dwin_string.add(ui.scrolled_filename(theCard, maxlen, row, sel), maxlen);
uint8_t n = maxlen - dwin_string.length;
while (n > 0) { dwin_string.add(' '); --n; }
lcd_moveto(1, row);
lcd_put_dwin_string();
@@ -510,8 +513,8 @@ void MarlinUI::draw_status_message(const bool blink) {
// Display Mesh Point Locations
const dwin_coord_t sx = x_offset + pixels_per_x_mesh_pnt / 2;
dwin_coord_t y = y_offset + pixels_per_y_mesh_pnt / 2;
for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++, y += pixels_per_y_mesh_pnt)
for (uint8_t i = 0, x = sx; i < GRID_MAX_POINTS_X; i++, x += pixels_per_x_mesh_pnt)
for (uint8_t j = 0; j < (GRID_MAX_POINTS_Y); j++, y += pixels_per_y_mesh_pnt)
for (uint8_t i = 0, x = sx; i < (GRID_MAX_POINTS_X); i++, x += pixels_per_x_mesh_pnt)
DWIN_Draw_Point(Color_White, 1, 1, x, y);
// Put Relevant Text on Display
@@ -519,7 +522,7 @@ void MarlinUI::draw_status_message(const bool blink) {
// Show X and Y positions at top of screen
dwin_font.fg = Color_White;
dwin_font.solid = true;
const xy_pos_t pos = { ubl.mesh_index_to_xpos(x_plot), ubl.mesh_index_to_ypos(y_plot) },
const xy_pos_t pos = { bedlevel.get_mesh_x(x_plot), bedlevel.get_mesh_y(y_plot) },
lpos = pos.asLogical();
lcd_moveto(
@@ -536,25 +539,25 @@ void MarlinUI::draw_status_message(const bool blink) {
lcd_put_u8str(ftostr52(lpos.y));
// Print plot position
dwin_string.set("(");
dwin_string.set('(');
dwin_string.add(i8tostr3rj(x_plot));
dwin_string.add(",");
dwin_string.add(',');
dwin_string.add(i8tostr3rj(y_plot));
dwin_string.add(")");
dwin_string.add(')');
lcd_moveto(
TERN(DWIN_MARLINUI_LANDSCAPE, ((x_offset + x_map_pixels) / MENU_FONT_WIDTH) + 2, LCD_WIDTH - dwin_string.length()),
TERN(DWIN_MARLINUI_LANDSCAPE, ((x_offset + x_map_pixels) / MENU_FONT_WIDTH) + 2, LCD_WIDTH - dwin_string.length),
TERN(DWIN_MARLINUI_LANDSCAPE, LCD_HEIGHT - 2, ((y_offset + y_map_pixels) / MENU_LINE_HEIGHT) + 1)
);
lcd_put_dwin_string();
// Show the location value
dwin_string.set(Z_LBL);
if (!isnan(Z_VALUES_ARR[x_plot][y_plot]))
dwin_string.add(ftostr43sign(Z_VALUES_ARR[x_plot][y_plot]));
if (!isnan(bedlevel.z_values[x_plot][y_plot]))
dwin_string.add(ftostr43sign(bedlevel.z_values[x_plot][y_plot]));
else
dwin_string.add(PSTR(" -----"));
dwin_string.add(F(" -----"));
lcd_moveto(
TERN(DWIN_MARLINUI_LANDSCAPE, ((x_offset + x_map_pixels) / MENU_FONT_WIDTH) + 2, LCD_WIDTH - dwin_string.length()),
TERN(DWIN_MARLINUI_LANDSCAPE, ((x_offset + x_map_pixels) / MENU_FONT_WIDTH) + 2, LCD_WIDTH - dwin_string.length),
TERN(DWIN_MARLINUI_LANDSCAPE, LCD_HEIGHT - 1, ((y_offset + y_map_pixels) / MENU_LINE_HEIGHT) + 2)
);
lcd_put_dwin_string();
@@ -562,19 +565,11 @@ void MarlinUI::draw_status_message(const bool blink) {
#endif // AUTO_BED_LEVELING_UBL
#if ANY(BABYSTEP_ZPROBE_GFX_OVERLAY, MESH_EDIT_GFX_OVERLAY, BABYSTEP_GFX_OVERLAY)
void _lcd_zoffset_overlay_gfx(const float zvalue) {
// Determine whether the user is raising or lowering the nozzle.
static int8_t dir;
static float old_zvalue;
if (zvalue != old_zvalue) {
dir = zvalue ? zvalue < old_zvalue ? -1 : 1 : 0;
old_zvalue = zvalue;
}
#if EITHER(BABYSTEP_ZPROBE_GFX_OVERLAY, MESH_EDIT_GFX_OVERLAY)
void MarlinUI::zoffset_overlay(const int8_t dir) {
const int rot_up = TERN(OVERLAY_GFX_REVERSE, ICON_RotateCCW, ICON_RotateCW),
rot_down = TERN(OVERLAY_GFX_REVERSE, ICON_RotateCW, ICON_RotateCCW);
rot_down = TERN(OVERLAY_GFX_REVERSE, ICON_RotateCW, ICON_RotateCCW);
const int nozzle = (LCD_PIXEL_WIDTH / 2) - 20;
@@ -594,6 +589,6 @@ void MarlinUI::draw_status_message(const bool blink) {
#endif // BABYSTEP_ZPROBE_GFX_OVERLAY || MESH_EDIT_GFX_OVERLAY
#endif // HAS_LCD_MENU
#endif // HAS_MARLINUI_MENU
#endif // IS_DWIN_MARLINUI

View File

@@ -16,7 +16,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
@@ -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,61 @@
// 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('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(axes_homed, axis))
while (const char c = *value++) dwin_string.add(c <= '.' ? c : '?');
else if (NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING) && !TEST(axes_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(F(" "));
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('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(axes_homed, axis))
while (const char c = *value++) dwin_string.add(c <= '.' ? c : '?');
else {
#if NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING)
if (!TEST(axes_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(F(" "));
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 +129,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(F("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(F("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,69 +174,104 @@ 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_string.set(F(" "));
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y + STATUS_FAN_HEIGHT, S(dwin_string.string()));
}
}
#if HOTENDS > 2
#define HOTEND_STATS 3
#elif HOTENDS > 1
#define HOTEND_STATS 2
#elif HAS_HOTEND
#define HOTEND_STATS 1
#endif
/**
* Draw a single heater icon with current and target temperature, at the given XY
*/
FORCE_INLINE void _draw_heater_status(const heater_id_t heater, const uint16_t x, const uint16_t y) {
#if HAS_HOTEND
static celsius_t old_temp[HOTEND_STATS] = ARRAY_N_1(HOTEND_STATS, 500),
old_target[HOTEND_STATS] = ARRAY_N_1(HOTEND_STATS, 500);
static bool old_on[HOTEND_STATS] = ARRAY_N_1(HOTEND_STATS, false);
#if HOTENDS > 2
#define HOTEND_STATS 3
#elif HOTENDS > 1
#define HOTEND_STATS 2
#else
#define HOTEND_STATS 1
#endif
static celsius_t old_temp[HOTEND_STATS] = { 0 },
old_target[HOTEND_STATS] = { 0 };
static bool old_on[HOTEND_STATS] = { false };
#endif
#if HAS_HEATED_BED
static celsius_t old_bed_temp = 500, old_bed_target = 500;
static celsius_t old_bed_temp = 0, old_bed_target = 0;
static bool old_bed_on = false;
#if HAS_LEVELING
static bool old_leveling_on = false;
#endif
#endif
#if HAS_HOTEND && HAS_HEATED_BED
float tc, tt;
bool c_draw, t_draw, i_draw, ta;
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; }
if (isBed) {
tc = thermalManager.degBed();
tt = thermalManager.degTargetBed();
ta = thermalManager.isHeatingBed();
c_draw = tc != old_bed_temp;
t_draw = tt != old_bed_target;
i_draw = ta != old_bed_on;
old_bed_temp = tc;
old_bed_target = tt;
old_bed_on = ta;
}
else {
tc = thermalManager.degHotend(heater);
tt = thermalManager.degTargetHotend(heater);
ta = thermalManager.isHeatingHotend(heater);
c_draw = tc != old_temp[heater];
t_draw = tt != old_target[heater];
i_draw = ta != old_on[heater];
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);
const uint8_t ta = thermalManager.isHeatingHotend(heater);
const bool c_draw = tc != old_bed_temp, t_draw = tt != old_bed_target, i_draw = ta != old_bed_on;
bool c_draw = tc != old_temp[heater], t_draw = tt != old_target[heater], i_draw = ta != old_on[heater];
old_temp[heater] = tc; old_target[heater] = tt; old_on[heater] = ta;
#elif HAS_HEATED_BED
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_bed_temp, t_draw = tt != old_bed_target, i_draw = ta != old_bed_on;
old_bed_temp = tc; old_bed_target = tt; old_bed_on = ta;
#else
bool c_draw = false, t_draw = false, i_draw = false;
constexpr float tc = 0, tt = 0;
constexpr uint8_t ta = 0;
#endif
#if HAS_HEATED_BED && HAS_LEVELING
if (isBed) {
i_draw |= (planner.leveling_active != old_leveling_on);
old_leveling_on = planner.leveling_active;
}
#endif
// Draw target temperature, if needed
if (!ui.did_first_redraw || t_draw) {
dwin_string.set(i16tostr3rj(tt + 0.5));
dwin_string.add(LCD_STR_DEGREE);
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);
// Draw heater icon with on / off / leveled states
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);
}
// Draw current temperature, if needed
if (!ui.did_first_redraw || c_draw) {
dwin_string.set(i16tostr3rj(tc + 0.5));
dwin_string.add(LCD_STR_DEGREE);
@@ -206,7 +289,7 @@ FORCE_INLINE void _draw_feedrate_status(const char *value, uint16_t x, uint16_t
}
dwin_string.set(value);
dwin_string.add(PSTR("%"));
dwin_string.add('%');
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x + 14, y, S(dwin_string.string()));
}
@@ -221,14 +304,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;
@@ -245,33 +336,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;
@@ -279,9 +359,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
);
}
@@ -309,34 +389,32 @@ void MarlinUI::draw_status_screen() {
time.toDigital(buffer);
dwin_string.add(prefix);
dwin_string.add(buffer);
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, (LCD_PIXEL_WIDTH - ((dwin_string.length() + 1) * 14)), 290, S(dwin_string.string()));
DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, (LCD_PIXEL_WIDTH - ((dwin_string.length + 1) * 14)), 290, S(dwin_string.string()));
#else
// landscape mode shows both elapsed and remaining (if SHOW_REMAINING_TIME)
time = print_job_timer.duration();
time.toDigital(buffer);
dwin_string.set(" ");
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(F(" "));
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(F(" "));
DWIN_Draw_String(true, font14x28, Color_IconBlue, Color_Bg_Black, 336, 170, S(dwin_string.string()));
}
#endif
#endif
@@ -344,41 +422,45 @@ 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),
pb_top = pb_bottom - pb_height,
pb_width = pb_right - pb_left;
#if HAS_PRINT_PROGRESS
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;
const progress_t progress = TERN(HAS_PRINT_PROGRESS_PERMYRIAD, get_progress_permyriad, get_progress_percent)();
const progress_t progress = TERN(HAS_PRINT_PROGRESS_PERMYRIAD, get_progress_permyriad, get_progress_percent)();
if (!ui.did_first_redraw)
DWIN_Draw_Rectangle(0, Select_Color, pb_left, pb_top, pb_right, pb_bottom); // Outline
if (!ui.did_first_redraw)
DWIN_Draw_Rectangle(0, Select_Color, pb_left, pb_top, pb_right, pb_bottom); // Outline
static uint16_t old_solid = 50;
const uint16_t pb_solid = (pb_width - 2) * (progress / (PROGRESS_SCALE)) * 0.01f;
const bool p_draw = !ui.did_first_redraw || old_solid != pb_solid;
static uint16_t old_solid = 50;
const uint16_t pb_solid = (pb_width - 2) * (progress / (PROGRESS_SCALE)) * 0.01f;
const bool p_draw = !ui.did_first_redraw || old_solid != pb_solid;
if (p_draw) {
//if (pb_solid)
DWIN_Draw_Rectangle(1, Select_Color, pb_left + 1, pb_top + 1, pb_left + pb_solid, pb_bottom - 1); // Fill the solid part
if (p_draw) {
//if (pb_solid)
DWIN_Draw_Rectangle(1, Select_Color, pb_left + 1, pb_top + 1, pb_left + pb_solid, pb_bottom - 1); // Fill the solid part
//if (pb_solid < old_solid)
DWIN_Draw_Rectangle(1, Color_Bg_Black, pb_left + 1 + pb_solid, pb_top + 1, pb_right - 1, pb_bottom - 1); // Erase the rest
//if (pb_solid < old_solid)
DWIN_Draw_Rectangle(1, Color_Bg_Black, pb_left + 1 + pb_solid, pb_top + 1, pb_right - 1, pb_bottom - 1); // Erase the rest
#if ENABLED(SHOW_SD_PERCENT)
dwin_string.set(TERN(PRINT_PROGRESS_SHOW_DECIMALS, permyriadtostr4(progress), ui8tostr3rj(progress / (PROGRESS_SCALE))));
dwin_string.add(PSTR("%"));
DWIN_Draw_String(
false, font16x32, Percent_Color, Color_Bg_Black,
pb_left + (pb_width - dwin_string.length() * 16) / 2,
pb_top + (pb_height - 32) / 2,
S(dwin_string.string())
);
#endif
#if ENABLED(SHOW_SD_PERCENT)
dwin_string.set(TERN(PRINT_PROGRESS_SHOW_DECIMALS, permyriadtostr4(progress), ui8tostr3rj(progress / (PROGRESS_SCALE))));
dwin_string.add('%');
DWIN_Draw_String(
false, font16x32, Percent_Color, Color_Bg_Black,
pb_left + (pb_width - dwin_string.length * 16) / 2,
pb_top + (pb_height - 32) / 2,
S(dwin_string.string())
);
#endif
old_solid = pb_solid;
}
old_solid = pb_solid;
}
#endif // HAS_PRINT_PROGRESS
//
// Status Message
@@ -386,6 +468,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