From 1f9fc665ec21f95666801aa4fccc4f4f71932018 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 26 Jun 2024 18:27:05 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8=20MarlinUI::=20clear=5Ffor=5Fdrawi?= =?UTF-8?q?ng?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/inc/Conditionals_LCD.h | 3 +++ Marlin/src/inc/Conditionals_post.h | 4 ++-- Marlin/src/lcd/HD44780/marlinui_HD44780.cpp | 3 ++- Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp | 2 ++ Marlin/src/lcd/dogm/marlinui_DOGM.cpp | 14 +++++++++++++- Marlin/src/lcd/e3v2/creality/dwin.cpp | 2 ++ Marlin/src/lcd/e3v2/jyersui/dwin.cpp | 2 ++ Marlin/src/lcd/e3v2/marlinui/ui_common.cpp | 6 ++++-- Marlin/src/lcd/e3v2/proui/dwin.cpp | 2 ++ Marlin/src/lcd/e3v2/proui/proui_extui.cpp | 1 + Marlin/src/lcd/extui/ui_api.cpp | 3 +++ Marlin/src/lcd/marlinui.cpp | 3 ++- Marlin/src/lcd/marlinui.h | 12 ++++++++---- Marlin/src/lcd/menu/menu.cpp | 2 +- Marlin/src/lcd/menu/menu_ubl.cpp | 2 +- Marlin/src/lcd/tft/touch.cpp | 8 ++++---- Marlin/src/lcd/tft/ui_color_ui.cpp | 2 +- Marlin/src/lcd/tft/ui_common.cpp | 8 +++++--- Marlin/src/lcd/tft/ui_move_axis_screen_1024.cpp | 2 +- Marlin/src/lcd/tft/ui_move_axis_screen_320.cpp | 2 +- Marlin/src/lcd/tft/ui_move_axis_screen_480.cpp | 2 +- 21 files changed, 61 insertions(+), 24 deletions(-) diff --git a/Marlin/src/inc/Conditionals_LCD.h b/Marlin/src/inc/Conditionals_LCD.h index 6b9ac4efe6..7de6146f29 100644 --- a/Marlin/src/inc/Conditionals_LCD.h +++ b/Marlin/src/inc/Conditionals_LCD.h @@ -1099,6 +1099,9 @@ * - poweroff (for PSU_CONTROL and HAS_MARLINUI_MENU) * * ...and implements these MarlinUI methods: + * - init_lcd + * - clear_lcd + * - clear_for_drawing * - zoffset_overlay (if BABYSTEP_GFX_OVERLAY or MESH_EDIT_GFX_OVERLAY are supported) * - draw_kill_screen * - kill_screen diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index 41c22e4835..d43132e13c 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -557,8 +557,8 @@ #endif #endif - #if HAS_SD_DETECT && NONE(HAS_GRAPHICAL_TFT, LCD_USE_DMA_FSMC, HAS_FSMC_GRAPHICAL_TFT, HAS_SPI_GRAPHICAL_TFT, IS_DWIN_MARLINUI, EXTENSIBLE_UI, HAS_DWIN_E3V2, HAS_U8GLIB_I2C_OLED) - #define REINIT_NOISY_SPI_LCD 1 // Have LCDs with shared SPI re-init on SD insertion + #if HAS_SD_DETECT && NONE(HAS_GRAPHICAL_TFT, LCD_USE_DMA_FSMC, HAS_FSMC_GRAPHICAL_TFT, HAS_SPI_GRAPHICAL_TFT, IS_DWIN_MARLINUI, EXTENSIBLE_UI, HAS_DWIN_E3V2) + #define REINIT_NOISY_LCD 1 // Have the LCD re-init on SD insertion #endif #endif // HAS_MEDIA diff --git a/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp b/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp index ea73243250..ae92d0a5f8 100644 --- a/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp +++ b/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp @@ -467,6 +467,7 @@ bool MarlinUI::detected() { #endif void MarlinUI::clear_lcd() { lcd.clear(); } +void MarlinUI::clear_for_drawing() { clear_lcd(); } #if ENABLED(SHOW_BOOTSCREEN) @@ -1515,7 +1516,7 @@ void MarlinUI::draw_status_screen() { lower_right.column = 0; lower_right.row = 0; - clear_lcd(); + clear_for_drawing(); x_map_pixels = (HD44780_CHAR_WIDTH) * (MESH_MAP_COLS) - 2; // Minus 2 because we are drawing a box around the map y_map_pixels = (HD44780_CHAR_HEIGHT) * (MESH_MAP_ROWS) - 2; diff --git a/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp b/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp index b29653f7b0..6dc5a41fdd 100644 --- a/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp +++ b/Marlin/src/lcd/TFTGLCD/marlinui_TFTGLCD.cpp @@ -376,6 +376,8 @@ void MarlinUI::clear_lcd() { lcd.clear_buffer(); } +void MarlinUI::clear_for_drawing() { clear_lcd(); } + #if HAS_LCD_CONTRAST void MarlinUI::_set_contrast() { lcd.setContrast(contrast); } #endif diff --git a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp index 1bc55630af..b99a31341a 100644 --- a/Marlin/src/lcd/dogm/marlinui_DOGM.cpp +++ b/Marlin/src/lcd/dogm/marlinui_DOGM.cpp @@ -374,7 +374,19 @@ void MarlinUI::draw_kill_screen() { } while (u8g.nextPage()); } -void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop +// Erase the LCD contents by drawing an empty box. +void MarlinUI::clear_lcd() { + u8g.setColorIndex(0); + u8g.firstPage(); + do { + u8g.drawBox(0, 0, u8g.getWidth(), u8g.getHeight()); + } while (u8g.nextPage()); +} + +// U8G displays are drawn over multiple loops so must do their own clearing. +void MarlinUI::clear_for_drawing() { + // Automatically cleared by Picture Loop +} #if HAS_DISPLAY_SLEEP void MarlinUI::sleep_display(const bool sleep/*=true*/) { diff --git a/Marlin/src/lcd/e3v2/creality/dwin.cpp b/Marlin/src/lcd/e3v2/creality/dwin.cpp index 7f057137d8..34bdd29694 100644 --- a/Marlin/src/lcd/e3v2/creality/dwin.cpp +++ b/Marlin/src/lcd/e3v2/creality/dwin.cpp @@ -1816,6 +1816,8 @@ void hmiSDCardInit() { card.cdroot(); } // Initialize or re-initialize the LCD void MarlinUI::init_lcd() { dwinStartup(); } +void MarlinUI::clear_lcd() {} + void MarlinUI::update() { eachMomentUpdate(); // Status update hmiSDCardUpdate(); // SD card update diff --git a/Marlin/src/lcd/e3v2/jyersui/dwin.cpp b/Marlin/src/lcd/e3v2/jyersui/dwin.cpp index 1c641817b8..2edc03dfd6 100644 --- a/Marlin/src/lcd/e3v2/jyersui/dwin.cpp +++ b/Marlin/src/lcd/e3v2/jyersui/dwin.cpp @@ -5155,6 +5155,8 @@ void MarlinUI::init_lcd() { jyersDWIN.redrawScreen(); } +void MarlinUI::clear_lcd() {} + #if ENABLED(ADVANCED_PAUSE_FEATURE) void MarlinUI::pause_show_message(const PauseMessage message, const PauseMode mode/*=PAUSE_MODE_SAME*/, const uint8_t extruder/*=active_extruder*/) { if (mode != PAUSE_MODE_SAME) pause_mode = mode; diff --git a/Marlin/src/lcd/e3v2/marlinui/ui_common.cpp b/Marlin/src/lcd/e3v2/marlinui/ui_common.cpp index 4a60f77c9d..31cf269227 100644 --- a/Marlin/src/lcd/e3v2/marlinui/ui_common.cpp +++ b/Marlin/src/lcd/e3v2/marlinui/ui_common.cpp @@ -90,6 +90,8 @@ void MarlinUI::clear_lcd() { did_first_redraw = false; } +void MarlinUI::clear_for_drawing() { clear_lcd(); } + #if ENABLED(SHOW_BOOTSCREEN) void MarlinUI::show_bootscreen() { @@ -111,7 +113,7 @@ void MarlinUI::clear_lcd() { dwinDrawString(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(); + clear_for_drawing(); dwinIconShow(BOOT_ICON, ICON_MarlinBoot, LOGO_CENTER - 266 / 2, 15); #if ENABLED(DWIN_MARLINUI_PORTRAIT) @@ -132,7 +134,7 @@ void MarlinUI::clear_lcd() { void MarlinUI::bootscreen_completion(const millis_t sofar) { if ((BOOTSCREEN_TIMEOUT) > sofar) safe_delay((BOOTSCREEN_TIMEOUT) - sofar); - clear_lcd(); + clear_for_drawing(); } #endif diff --git a/Marlin/src/lcd/e3v2/proui/dwin.cpp b/Marlin/src/lcd/e3v2/proui/dwin.cpp index 56c7fec517..2b691326c0 100644 --- a/Marlin/src/lcd/e3v2/proui/dwin.cpp +++ b/Marlin/src/lcd/e3v2/proui/dwin.cpp @@ -1913,6 +1913,8 @@ void MarlinUI::init_lcd() { dwinJPGCacheTo1(Language_English); } +void MarlinUI::clear_lcd() {} + void dwinInitScreen() { dwinSetColorDefaults(); hmiInit(); // Draws boot screen diff --git a/Marlin/src/lcd/e3v2/proui/proui_extui.cpp b/Marlin/src/lcd/e3v2/proui/proui_extui.cpp index ae85a5a60c..2adca7cbe6 100644 --- a/Marlin/src/lcd/e3v2/proui/proui_extui.cpp +++ b/Marlin/src/lcd/e3v2/proui/proui_extui.cpp @@ -195,6 +195,7 @@ namespace ExtUI { void onPIDTuning(const pidresult_t rst) { // Called for temperature PID tuning result switch (rst) { + default: break; #if ENABLED(PIDTEMP) case PID_STARTED: dwinPIDTuning(PIDTEMP_START); break; #endif diff --git a/Marlin/src/lcd/extui/ui_api.cpp b/Marlin/src/lcd/extui/ui_api.cpp index 29f9b34fe4..1fcfabdd72 100644 --- a/Marlin/src/lcd/extui/ui_api.cpp +++ b/Marlin/src/lcd/extui/ui_api.cpp @@ -1279,6 +1279,9 @@ namespace ExtUI { #if DISABLED(HAS_DWIN_E3V2) void MarlinUI::init_lcd() { ExtUI::onStartup(); } + void MarlinUI::clear_lcd() {} + void MarlinUI::clear_for_drawing() {} + void MarlinUI::update() { ExtUI::onIdle(); } void MarlinUI::kill_screen(FSTR_P const error, FSTR_P const component) { diff --git a/Marlin/src/lcd/marlinui.cpp b/Marlin/src/lcd/marlinui.cpp index 5b83f0c6bf..a967d92135 100644 --- a/Marlin/src/lcd/marlinui.cpp +++ b/Marlin/src/lcd/marlinui.cpp @@ -226,6 +226,7 @@ void MarlinUI::init() { #endif init_lcd(); + clear_lcd(); #if BUTTON_EXISTS(EN1) SET_INPUT_PULLUP(BTN_EN1); @@ -1204,7 +1205,7 @@ void MarlinUI::init() { // Change state of drawing flag between screen updates if (!drawing_screen) switch (lcdDrawUpdate) { case LCDVIEW_CLEAR_CALL_REDRAW: - clear_lcd(); break; + clear_for_drawing(); break; case LCDVIEW_REDRAW_NOW: refresh(LCDVIEW_NONE); case LCDVIEW_NONE: diff --git a/Marlin/src/lcd/marlinui.h b/Marlin/src/lcd/marlinui.h index 6a29110be8..cc130327a9 100644 --- a/Marlin/src/lcd/marlinui.h +++ b/Marlin/src/lcd/marlinui.h @@ -207,11 +207,14 @@ public: #if HAS_DISPLAY || HAS_DWIN_E3V2 static void init_lcd(); + // Erase the LCD contents. Do the lowest-level thing required to clear the LCD. + static void clear_lcd(); #else static void init_lcd() {} + static void clear_lcd() {} #endif - static void reinit_lcd() { TERN_(REINIT_NOISY_SPI_LCD, init_lcd()); } + static void reinit_lcd() { TERN_(REINIT_NOISY_LCD, init_lcd()); } #if HAS_WIRED_LCD static bool detected(); @@ -246,9 +249,6 @@ public: static void update_indicators(); #endif - // LCD implementations - static void clear_lcd(); - #if ALL(HAS_MARLINUI_MENU, TOUCH_SCREEN_CALIBRATION) static void check_touch_calibration() { if (touch_calibration.need_calibration()) currentScreen = touch_calibration_screen; @@ -520,6 +520,9 @@ public: #if HAS_DISPLAY + // Clear the LCD before new drawing. Some LCDs do nothing because they redraw frequently. + static void clear_for_drawing(); + static void abort_print(); static void pause_print(); static void resume_print(); @@ -630,6 +633,7 @@ public: #else // No LCD + static void clear_for_drawing() {} static void kill_screen(FSTR_P const, FSTR_P const) {} #endif diff --git a/Marlin/src/lcd/menu/menu.cpp b/Marlin/src/lcd/menu/menu.cpp index 892af5dbab..f939452143 100644 --- a/Marlin/src/lcd/menu/menu.cpp +++ b/Marlin/src/lcd/menu/menu.cpp @@ -209,7 +209,7 @@ void MarlinUI::goto_screen(screenFunc_t screen, const uint16_t encoder/*=0*/, co TERN_(AUTO_BED_LEVELING_UBL, bedlevel.lcd_map_control = false); } - clear_lcd(); + clear_for_drawing(); // Re-initialize custom characters that may be re-used #if HAS_MARLINUI_HD44780 diff --git a/Marlin/src/lcd/menu/menu_ubl.cpp b/Marlin/src/lcd/menu/menu_ubl.cpp index 2d28d44991..ff7225a166 100644 --- a/Marlin/src/lcd/menu/menu_ubl.cpp +++ b/Marlin/src/lcd/menu/menu_ubl.cpp @@ -96,7 +96,7 @@ void _lcd_mesh_fine_tune(FSTR_P const fmsg) { // To capture encoder events UBL will also call ui.capture and ui.release. // void MarlinUI::ubl_mesh_edit_start(const_float_t initial) { - TERN_(HAS_GRAPHICAL_TFT, clear_lcd()); + TERN_(HAS_GRAPHICAL_TFT, clear_for_drawing()); mesh_edit_accumulator = initial; goto_screen([]{ _lcd_mesh_fine_tune(GET_TEXT_F(MSG_MESH_EDIT_Z)); }); } diff --git a/Marlin/src/lcd/tft/touch.cpp b/Marlin/src/lcd/tft/touch.cpp index 7fc5f2fa21..e48f974536 100644 --- a/Marlin/src/lcd/tft/touch.cpp +++ b/Marlin/src/lcd/tft/touch.cpp @@ -184,7 +184,7 @@ void Touch::touch(touch_control_t *control) { case HEATER: int8_t heater; heater = control->data; - ui.clear_lcd(); + ui.clear_for_drawing(); #if HAS_HOTEND if (heater >= 0) { // HotEnd #if HOTENDS == 1 @@ -213,20 +213,20 @@ void Touch::touch(touch_control_t *control) { break; case FAN: - ui.clear_lcd(); + ui.clear_for_drawing(); static uint8_t fan, fan_speed; fan = 0; fan_speed = thermalManager.fan_speed[fan]; MenuItem_percent::action(GET_TEXT_F(MSG_FIRST_FAN_SPEED), &fan_speed, 0, 255, []{ thermalManager.set_fan_speed(fan, fan_speed); TERN_(LASER_SYNCHRONOUS_M106_M107, planner.buffer_sync_block(BLOCK_BIT_SYNC_FANS));}); break; case FEEDRATE: - ui.clear_lcd(); + ui.clear_for_drawing(); MenuItem_int3::action(GET_TEXT_F(MSG_SPEED), &feedrate_percentage, SPEED_EDIT_MIN, SPEED_EDIT_MAX); break; #if HAS_EXTRUDERS case FLOWRATE: - ui.clear_lcd(); + ui.clear_for_drawing(); MenuItemBase::itemIndex = control->data; #if EXTRUDERS == 1 MenuItem_int3::action(GET_TEXT_F(MSG_FLOW), &planner.flow_percentage[MenuItemBase::itemIndex], FLOW_EDIT_MIN, FLOW_EDIT_MAX, []{ planner.refresh_e_factor(MenuItemBase::itemIndex); }); diff --git a/Marlin/src/lcd/tft/ui_color_ui.cpp b/Marlin/src/lcd/tft/ui_color_ui.cpp index 279ea9715a..9861cbc1f6 100644 --- a/Marlin/src/lcd/tft/ui_color_ui.cpp +++ b/Marlin/src/lcd/tft/ui_color_ui.cpp @@ -79,7 +79,7 @@ void MarlinUI::tft_idle() { void MarlinUI::bootscreen_completion(const millis_t sofar) { if ((BOOTSCREEN_TIMEOUT) > sofar) safe_delay((BOOTSCREEN_TIMEOUT) - sofar); - clear_lcd(); + clear_for_drawing(); } #endif diff --git a/Marlin/src/lcd/tft/ui_common.cpp b/Marlin/src/lcd/tft/ui_common.cpp index 23f276349b..e42ca7e689 100644 --- a/Marlin/src/lcd/tft/ui_common.cpp +++ b/Marlin/src/lcd/tft/ui_common.cpp @@ -199,7 +199,7 @@ void moveAxis(const AxisEnum axis, const int8_t direction) { tft.queue.reset(); if (!sleepCleared) { sleepCleared = true; - ui.clear_lcd(); + ui.clear_for_drawing(); tft.queue.async(); } touch.idle(); @@ -407,7 +407,7 @@ void MarlinUI::init_lcd() { tft.add_glyphs(EXTRA_FONT_NAME); #endif TERN_(TOUCH_SCREEN, touch.init()); - clear_lcd(); + clear_for_drawing(); } void MarlinUI::clear_lcd() { @@ -421,6 +421,8 @@ void MarlinUI::clear_lcd() { cursor.set(0, 0); } +void MarlinUI::clear_for_drawing() { clear_lcd(); } + #if HAS_LCD_BRIGHTNESS void MarlinUI::_set_brightness() { @@ -441,7 +443,7 @@ void MarlinUI::clear_lcd() { if (stage == CALIBRATION_NONE) { defer_status_screen(true); - clear_lcd(); + clear_for_drawing(); stage = touch_calibration.calibration_start(); } else { diff --git a/Marlin/src/lcd/tft/ui_move_axis_screen_1024.cpp b/Marlin/src/lcd/tft/ui_move_axis_screen_1024.cpp index a68752c9dd..a15c05d25e 100644 --- a/Marlin/src/lcd/tft/ui_move_axis_screen_1024.cpp +++ b/Marlin/src/lcd/tft/ui_move_axis_screen_1024.cpp @@ -133,7 +133,7 @@ void MarlinUI::move_axis_screen() { motionAxisState.blocked = false; TERN_(TOUCH_SCREEN, touch.enable()); - ui.clear_lcd(); + ui.clear_for_drawing(); TERN_(TOUCH_SCREEN, touch.clear()); diff --git a/Marlin/src/lcd/tft/ui_move_axis_screen_320.cpp b/Marlin/src/lcd/tft/ui_move_axis_screen_320.cpp index 54a65c17bf..5b1fbaf958 100644 --- a/Marlin/src/lcd/tft/ui_move_axis_screen_320.cpp +++ b/Marlin/src/lcd/tft/ui_move_axis_screen_320.cpp @@ -146,7 +146,7 @@ void MarlinUI::move_axis_screen() { motionAxisState.blocked = false; TERN_(TOUCH_SCREEN, touch.enable()); - ui.clear_lcd(); + ui.clear_for_drawing(); TERN_(TOUCH_SCREEN, touch.clear()); diff --git a/Marlin/src/lcd/tft/ui_move_axis_screen_480.cpp b/Marlin/src/lcd/tft/ui_move_axis_screen_480.cpp index e311c7e8ec..9e42411580 100644 --- a/Marlin/src/lcd/tft/ui_move_axis_screen_480.cpp +++ b/Marlin/src/lcd/tft/ui_move_axis_screen_480.cpp @@ -146,7 +146,7 @@ void MarlinUI::move_axis_screen() { motionAxisState.blocked = false; TERN_(TOUCH_SCREEN, touch.enable()); - ui.clear_lcd(); + ui.clear_for_drawing(); TERN_(TOUCH_SCREEN, touch.clear());