Browse Source

Return from Autoload filament and Load filament menu item to parent menu.

Exception is Load filament, when temperature is sufficient to load filament, in such case, load filament is started and GUI returns to status screen.
Marek Bel 6 years ago
parent
commit
f207145752
2 changed files with 66 additions and 23 deletions
  1. 6 0
      Firmware/Timer.cpp
  2. 60 23
      Firmware/ultralcd.cpp

+ 6 - 0
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()
 {
 }

+ 60 - 23
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() {
 
 }
 
+#ifdef PAT9125
+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
 
-
-void lcd_LoadFilament()
+static void lcd_LoadFilament()
 {
-  if (degHotend0() > EXTRUDE_MINTEMP) 
+  if (degHotend0() > EXTRUDE_MINTEMP)
   {
-#ifdef PAT9125
-	  if (filament_autoload_enabled && fsensor_enabled)
-	  {
-		  lcd_show_fullscreen_message_and_wait_P(MSG_AUTOLOADING_ENABLED);
-		  return;
-	  }
-#endif //PAT9125
-	  custom_message = true;
-	  loading_flag = true;
-	  enquecommand_P(PSTR("M701")); //load filament
-	  SERIAL_ECHOLN("Loading filament");	    
+      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);