diff --git a/Firmware/Timer.cpp b/Firmware/Timer.cpp index 78f47a45..29866a67 100644 --- a/Firmware/Timer.cpp +++ b/Firmware/Timer.cpp @@ -6,6 +6,12 @@ #include "Timer.h" #include "Arduino.h" +/** + * @brief construct Timer + * + * It is guaranteed, that construction is equivalent with zeroing all members. + * This property can be exploited in MenuData union. + */ Timer::Timer() : m_isRunning(false), m_started() { } diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 25d65d74..19522eca 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -108,6 +108,11 @@ union MenuData // editMenuParentState is used when an edit menu is entered, so it knows // the return menu and encoder state. struct EditMenuParentState editMenuParentState; + + struct AutoLoadFilamentMenu + { + Timer timer; + } autoLoadFilamentMenu; }; // State of the currently active menu. @@ -188,6 +193,7 @@ unsigned char firstrun = 1; /** forward declarations **/ +static const char* lcd_display_message_fullscreen_nonBlocking_P(const char *msg, uint8_t &nlines); // void copy_and_scalePID_i(); // void copy_and_scalePID_d(); @@ -2069,39 +2075,50 @@ void lcd_alright() { } - - -void lcd_LoadFilament() -{ - if (degHotend0() > EXTRUDE_MINTEMP) - { #ifdef PAT9125 - if (filament_autoload_enabled && fsensor_enabled) - { - lcd_show_fullscreen_message_and_wait_P(MSG_AUTOLOADING_ENABLED); - return; - } +static void lcd_menu_AutoLoadFilament() +{ + if (degHotend0() > EXTRUDE_MINTEMP) + { + uint8_t nlines; + lcd_display_message_fullscreen_nonBlocking_P(MSG_AUTOLOADING_ENABLED,nlines); + } + else + { + if (!menuData.autoLoadFilamentMenu.timer.running()) menuData.autoLoadFilamentMenu.timer.start(); + lcd.setCursor(0, 0); + lcd_printPGM(MSG_ERROR); + lcd.setCursor(0, 2); + lcd_printPGM(MSG_PREHEAT_NOZZLE); + if (menuData.autoLoadFilamentMenu.timer.expired(2000ul)) menu_action_back(); + } + if (lcd_clicked()) menu_action_back(); +} #endif //PAT9125 - custom_message = true; - loading_flag = true; - enquecommand_P(PSTR("M701")); //load filament - SERIAL_ECHOLN("Loading filament"); + +static void lcd_LoadFilament() +{ + if (degHotend0() > EXTRUDE_MINTEMP) + { + custom_message = true; + loading_flag = true; + enquecommand_P(PSTR("M701")); //load filament + SERIAL_ECHOLN("Loading filament"); + lcd_return_to_status(); } - else + else { lcd_implementation_clear(); lcd.setCursor(0, 0); lcd_printPGM(MSG_ERROR); lcd.setCursor(0, 2); - lcd_printPGM(MSG_PREHEAT_NOZZLE); + lcd_printPGM(MSG_PREHEAT_NOZZLE); delay(2000); lcd_implementation_clear(); } - lcd_return_to_status(); } - void lcd_menu_statistics() { @@ -2777,11 +2794,16 @@ static inline bool pgm_is_interpunction(const char *c_addr) return c == '.' || c == ',' || c == ':'|| c == ';' || c == '?' || c == '!' || c == '/'; } -const char* lcd_display_message_fullscreen_P(const char *msg, uint8_t &nlines) +/** + * @brief show full screen message + * + * This function is non-blocking + * @param msg message to be displayed from PROGMEM + * @param nlines + * @return rest of the text (to be displayed on next page) + */ +static const char* lcd_display_message_fullscreen_nonBlocking_P(const char *msg, uint8_t &nlines) { - // Disable update of the screen by the usual lcd_update() routine. - lcd_update_enable(false); - lcd_implementation_clear(); lcd.setCursor(0, 0); const char *msgend = msg; uint8_t row = 0; @@ -2834,6 +2856,21 @@ const char* lcd_display_message_fullscreen_P(const char *msg, uint8_t &nlines) return multi_screen ? msgend : NULL; } +const char* lcd_display_message_fullscreen_P(const char *msg, uint8_t &nlines) +{ + // Disable update of the screen by the usual lcd_update() routine. + lcd_update_enable(false); + lcd_implementation_clear(); + return lcd_display_message_fullscreen_nonBlocking_P(msg, nlines); +} + + +/** + * @brief show full screen message and wait + * + * This function is blocking. + * @param msg message to be displayed from PROGMEM + */ void lcd_show_fullscreen_message_and_wait_P(const char *msg) { const char *msg_next = lcd_display_message_fullscreen_P(msg); @@ -5689,7 +5726,7 @@ static void lcd_main_menu() #ifndef SNMM #ifdef PAT9125 if ( ((filament_autoload_enabled == true) && (fsensor_enabled == true))) - MENU_ITEM(function, MSG_AUTOLOAD_FILAMENT, lcd_LoadFilament); + MENU_ITEM(submenu, MSG_AUTOLOAD_FILAMENT, lcd_menu_AutoLoadFilament); else #endif //PAT9125 MENU_ITEM(function, MSG_LOAD_FILAMENT, lcd_LoadFilament);