Skip to content

Commit

Permalink
🚸 Expose sub-options for E3V2 Enhanced (MarlinFirmware#23099)
Browse files Browse the repository at this point in the history
  • Loading branch information
mriscoc authored and thinkyhead committed Dec 25, 2021
1 parent 2a90d93 commit 7269990
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@

#endif // HAS_LCD_MENU

#if HAS_DISPLAY
#if EITHER(HAS_DISPLAY, DWIN_CREALITY_LCD_ENHANCED)
// The timeout (in ms) to return to the status screen from sub-menus
//#define LCD_TIMEOUT_TO_STATUS 15000

Expand Down
1 change: 0 additions & 1 deletion Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1565,7 +1565,6 @@ void setup() {
HMI_Init();
HMI_SetLanguageCache();
HMI_StartFrame(true);
DWIN_StatusChanged(GET_TEXT_F(WELCOME_MSG));
#endif

#if HAS_SERVICE_INTERVALS && !HAS_DWIN_E3V2_BASIC
Expand Down
111 changes: 90 additions & 21 deletions Marlin/src/lcd/e3v2/enhanced/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ select_t select_page{0}, select_file{0}, select_print{0};
uint8_t index_file = MROWS;

bool dwin_abort_flag = false; // Flag to reset feedrate, return to Home
bool hash_changed = true; // Flag to know if message status was changed

constexpr float default_max_feedrate[] = DEFAULT_MAX_FEEDRATE;
constexpr float default_max_acceleration[] = DEFAULT_MAX_ACCELERATION;
Expand Down Expand Up @@ -610,6 +611,86 @@ void Popup_window_PauseOrStop() {
}
#endif

// Draw status line
void DWIN_DrawStatusLine(const uint16_t color, const uint16_t bgcolor, const char *text, const bool center = true) {
DWIN_Draw_Rectangle(1, bgcolor, 0, STATUS_Y, DWIN_WIDTH, STATUS_Y + 20);
if (text) {
if (center) DWINUI::Draw_CenteredString(color, STATUS_Y + 2, text);
else DWINUI::Draw_String(color, 0, STATUS_Y + 2, text);
}
DWIN_UpdateLCD();
}
void DWIN_DrawStatusLine(const char *text, const bool center = true) {
DWIN_DrawStatusLine(HMI_data.StatusTxt_Color, HMI_data.StatusBg_Color, text, center);
}

// Clear & reset status line
void DWIN_ResetStatusLine() {
ui.status_message[0] = 0;
DWIN_CheckStatusMessage();
}

// Djb2 hash algorithm
void DWIN_CheckStatusMessage() {
static uint32_t old_hash = 0;
char * str = &ui.status_message[0];
uint32_t hash = 5381;
char c;
while ((c = *str++)) hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
hash_changed = hash != old_hash;
old_hash = hash;
};

void DWIN_DrawStatusMessage() {
const uint8_t max_status_chars = DWIN_WIDTH / DWINUI::fontWidth(DWINUI::font);

#if ENABLED(STATUS_MESSAGE_SCROLLING)

// Get the UTF8 character count of the string
uint8_t slen = utf8_strlen(ui.status_message);

// If the string fits the status line do not scroll it
if (slen <= max_status_chars) {
if (hash_changed) {
DWIN_DrawStatusLine(HMI_data.StatusTxt_Color, HMI_data.StatusBg_Color, ui.status_message);
hash_changed = false;
}
}
else {
// String is larger than the available line space

// Get a pointer to the next valid UTF8 character
// and the string remaining length
uint8_t rlen;
const char *stat = MarlinUI::status_and_len(rlen);
DWIN_Draw_Rectangle(1, HMI_data.StatusBg_Color, 0, STATUS_Y, DWIN_WIDTH, STATUS_Y + 20);
DWINUI::MoveTo(0, STATUS_Y + 2);
DWINUI::Draw_String(stat, max_status_chars);

// If the string doesn't completely fill the line...
if (rlen < max_status_chars) {
DWINUI::Draw_Char('.'); // 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
DWINUI::Draw_Char('.');
if (--chars)
DWINUI::Draw_String(ui.status_message, chars); // Print a second copy of the message
}
}
MarlinUI::advance_status_scroll();
}

#else

if (hash_changed) {
ui.status_message[max_status_chars] = 0;
DWIN_DrawStatusLine(HMI_data.StatusTxt_Color, HMI_data.StatusBg_Color, ui.status_message);
hash_changed = false;
}

#endif
}

void Draw_Print_Labels() {
if (HMI_IsChinese()) {
Title.FrameCopy(30, 1, 42, 14); // "Printing"
Expand Down Expand Up @@ -715,7 +796,7 @@ void Draw_Main_Menu() {
void Goto_Main_Menu() {
if (checkkey == MainMenu) return;
checkkey = MainMenu;
DWIN_StatusChanged();
ui.reset_status(true);
Draw_Main_Menu();
}

Expand Down Expand Up @@ -1079,6 +1160,7 @@ void Draw_Status_Area(const bool with_update) {

void HMI_StartFrame(const bool with_update) {
Goto_Main_Menu();
DWIN_DrawStatusLine(nullptr);
Draw_Status_Area(with_update);
}

Expand Down Expand Up @@ -1475,14 +1557,19 @@ void DWIN_Update() {
}

void EachMomentUpdate() {
static millis_t next_var_update_ms = 0, next_rts_update_ms = 0;
static millis_t next_var_update_ms = 0, next_rts_update_ms = 0, next_status_update_ms = 0;

const millis_t ms = millis();
if (ELAPSED(ms, next_var_update_ms)) {
next_var_update_ms = ms + DWIN_VAR_UPDATE_INTERVAL;
update_variable();
}

if (ELAPSED(ms, next_status_update_ms)) {
next_status_update_ms = ms + 500;
DWIN_DrawStatusMessage();
}

if (PENDING(ms, next_rts_update_ms)) return;
next_rts_update_ms = ms + DWIN_SCROLL_UPDATE_INTERVAL;

Expand Down Expand Up @@ -1746,7 +1833,7 @@ void Draw_Title(TitleClass* title) {
void Draw_Menu(MenuClass* menu) {
DWINUI::SetColors(HMI_data.Text_Color, HMI_data.Background_Color);
DWIN_Draw_Rectangle(1, DWINUI::backcolor, 0, TITLE_HEIGHT, DWIN_WIDTH - 1, STATUS_Y - 1);
ui.set_status("");
DWIN_ResetStatusLine();
}

// Startup routines
Expand All @@ -1759,23 +1846,6 @@ void DWIN_Startup() {
HMI_SetLanguage();
}

void DWIN_DrawStatusLine(const uint16_t color, const uint16_t bgcolor, const char * const text/*=nullptr*/) {
DWIN_Draw_Rectangle(1, bgcolor, 0, STATUS_Y, DWIN_WIDTH, STATUS_Y + 20);
if (text) DWINUI::Draw_CenteredString(color, STATUS_Y + 2, text);
DWIN_UpdateLCD();
}

// Update Status line
void DWIN_StatusChanged(const char * const cstr/*=nullptr*/) {
DWIN_DrawStatusLine(HMI_data.StatusTxt_Color, HMI_data.StatusBg_Color, cstr);
}

void DWIN_StatusChanged(FSTR_P const fstr) {
char str[strlen_P(FTOP(fstr)) + 1];
strcpy_P(str, FTOP(fstr));
DWIN_StatusChanged(str);
}

// Started a Print Job
void DWIN_Print_Started(const bool sd) {
sdprint = card.isPrinting() || sd;
Expand Down Expand Up @@ -1867,7 +1937,6 @@ void DWIN_RebootScreen() {

void DWIN_Redraw_screen() {
Draw_Main_Area();
DWIN_StatusChanged(ui.status_message);
Draw_Status_Area(false);
}

Expand Down
4 changes: 1 addition & 3 deletions Marlin/src/lcd/e3v2/enhanced/dwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,7 @@ void EachMomentUpdate();
void update_variable();
void DWIN_HandleScreen();
void DWIN_Update();
void DWIN_DrawStatusLine(const uint16_t color, const uint16_t bgcolor, const char *text=nullptr);
void DWIN_StatusChanged(const char * const cstr=nullptr);
void DWIN_StatusChanged(FSTR_P const fstr);
void DWIN_CheckStatusMessage();
void DWIN_StartHoming();
void DWIN_CompletedHoming();
#if HAS_MESH
Expand Down
19 changes: 10 additions & 9 deletions Marlin/src/lcd/marlinui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ MarlinUI ui;
#if ENABLED(DWIN_CREALITY_LCD)
#include "e3v2/creality/dwin.h"
#elif ENABLED(DWIN_CREALITY_LCD_ENHANCED)
#include "fontutils.h"
#include "e3v2/enhanced/dwin.h"
#elif ENABLED(DWIN_CREALITY_LCD_JYERSUI)
#include "e3v2/jyersui/dwin.h"
Expand All @@ -69,7 +70,7 @@ MarlinUI ui;
constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;

#if HAS_STATUS_MESSAGE
#if BOTH(HAS_WIRED_LCD, STATUS_MESSAGE_SCROLLING)
#if ENABLED(STATUS_MESSAGE_SCROLLING) && EITHER(HAS_WIRED_LCD, DWIN_CREALITY_LCD_ENHANCED)
uint8_t MarlinUI::status_scroll_offset; // = 0
#endif
char MarlinUI::status_message[MAX_MESSAGE_LENGTH + 1];
Expand Down Expand Up @@ -1481,11 +1482,9 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;

void MarlinUI::finish_status(const bool persist) {

#if HAS_WIRED_LCD
UNUSED(persist);

#if !(BASIC_PROGRESS_BAR && (PROGRESS_MSG_EXPIRE) > 0)
UNUSED(persist);
#endif
#if HAS_WIRED_LCD

#if BASIC_PROGRESS_BAR || BOTH(FILAMENT_LCD_DISPLAY, SDSUPPORT)
const millis_t ms = millis();
Expand All @@ -1502,13 +1501,15 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
next_filament_display = ms + 5000UL; // Show status message for 5s
#endif

TERN_(STATUS_MESSAGE_SCROLLING, status_scroll_offset = 0);
#else // HAS_WIRED_LCD
UNUSED(persist);
#endif

#if ENABLED(STATUS_MESSAGE_SCROLLING) && EITHER(HAS_WIRED_LCD, DWIN_CREALITY_LCD_ENHANCED)
status_scroll_offset = 0;
#endif

TERN_(EXTENSIBLE_UI, ExtUI::onStatusChanged(status_message));
TERN_(HAS_DWIN_E3V2_BASIC, DWIN_StatusChanged(status_message));
TERN_(DWIN_CREALITY_LCD, DWIN_StatusChanged(status_message));
TERN_(DWIN_CREALITY_LCD_ENHANCED, DWIN_CheckStatusMessage());
TERN_(DWIN_CREALITY_LCD_JYERSUI, CrealityDWIN.Update_Status(status_message));
}

Expand Down
7 changes: 3 additions & 4 deletions Marlin/src/lcd/marlinui.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ class MarlinUI {

#if EITHER(HAS_DISPLAY, DWIN_CREALITY_LCD_ENHANCED)
static void kill_screen(FSTR_P const lcd_error, FSTR_P const lcd_component);
#if DISABLED(LIGHTWEIGHT_UI)
static void draw_status_message(const bool blink);
#endif
#else
static inline void kill_screen(FSTR_P const, FSTR_P const) {}
#endif
Expand Down Expand Up @@ -444,10 +447,6 @@ class MarlinUI {
static inline void completion_feedback(const bool=true) { TERN_(HAS_TOUCH_SLEEP, wakeup_screen()); }
#endif

#if DISABLED(LIGHTWEIGHT_UI)
static void draw_status_message(const bool blink);
#endif

#if ENABLED(ADVANCED_PAUSE_FEATURE)
static void draw_hotend_status(const uint8_t row, const uint8_t extruder);
#endif
Expand Down

0 comments on commit 7269990

Please sign in to comment.