From a687b8e64ae3245d0df99893e38720797c786db4 Mon Sep 17 00:00:00 2001 From: Marek Bel <marek.bel@posta.cz> Date: Mon, 17 Sep 2018 17:05:11 +0200 Subject: [PATCH] Don't enable lcd update inside mmu_eject_filament(). --- Firmware/lcd.h | 23 +++++++++++++++++++++++ Firmware/mmu.cpp | 15 ++++++++------- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/Firmware/lcd.h b/Firmware/lcd.h index 251344de..1a7a8193 100644 --- a/Firmware/lcd.h +++ b/Firmware/lcd.h @@ -150,6 +150,29 @@ extern void lcd_update_enable(uint8_t enabled); extern void lcd_buttons_update(void); +//! @brief Helper class to temporarily disable LCD updates +//! +//! When constructed (on stack), original state state of lcd_update_enabled is stored +//! and LCD updates are disabled. +//! When destroyed (gone out of scope), original state of LCD update is restored. +//! It has zero overhead compared to storing bool saved = lcd_update_enabled +//! and calling lcd_update_enable(false) and lcd_update_enable(saved). +class LcdUpdateDisabler +{ +public: + LcdUpdateDisabler(): m_updateEnabled(lcd_update_enabled) + { + lcd_update_enable(false); + } + ~LcdUpdateDisabler() + { + lcd_update_enable(m_updateEnabled); + } + +private: + bool m_updateEnabled; +}; + diff --git a/Firmware/mmu.cpp b/Firmware/mmu.cpp index a8502e04..cb59b7e9 100644 --- a/Firmware/mmu.cpp +++ b/Firmware/mmu.cpp @@ -1012,14 +1012,15 @@ void mmu_eject_filament(uint8_t filament, bool recover) if (degHotend0() > EXTRUDE_MINTEMP) { st_synchronize(); - lcd_update_enable(false); - lcd_clear(); - lcd_set_cursor(0, 1); lcd_puts_P(_i("Ejecting filament")); - current_position[E_AXIS] -= 80; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2500 / 60, active_extruder); - st_synchronize(); - lcd_update_enable(true); + { + LcdUpdateDisabler disableLcdUpdate; + lcd_clear(); + lcd_set_cursor(0, 1); lcd_puts_P(_i("Ejecting filament")); + current_position[E_AXIS] -= 80; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2500 / 60, active_extruder); + st_synchronize(); + } mmu_command(MMU_CMD_E0 + filament); manage_response(false, false);