Browse Source

Fix the "Stop print" behavior from the LCD

Correctly cleanup the printer state when stopping the current print:

- Disable interrupts while aborting the planner/queue to ensure
  new serial commands are not inserted while aborting
- _Always_ call planner_abort_hard() to interrupt any pending move!
- Clear the saved_target, which might be set when calling stop
  from within a paused state. Create a new function to clear the
  paused state for future use.
- Do not disable/reset the MBL: doing so will destroy the ability to
  restart correctly using M999.
Yuri D'Elia 4 years ago
parent
commit
faa76df2fe
3 changed files with 24 additions and 20 deletions
  1. 1 0
      Firmware/Marlin.h
  2. 8 0
      Firmware/Marlin_main.cpp
  3. 15 20
      Firmware/ultralcd.cpp

+ 1 - 0
Firmware/Marlin.h

@@ -455,6 +455,7 @@ extern void print_mesh_bed_leveling_table();
 
 extern void stop_and_save_print_to_ram(float z_move, float e_move);
 extern void restore_print_from_ram_and_continue(float e_move);
+extern void cancel_saved_printing();
 
 
 //estimated time to end of the print

+ 8 - 0
Firmware/Marlin_main.cpp

@@ -10343,6 +10343,14 @@ void restore_print_from_ram_and_continue(float e_move)
     waiting_inside_plan_buffer_line_print_aborted = true; //unroll the stack
 }
 
+// Cancel the state related to a currently saved print
+void cancel_saved_printing()
+{
+    saved_target[0] = SAVED_TARGET_UNSET;
+    saved_printing_type = PRINTING_TYPE_NONE;
+    saved_printing = false;
+}
+
 void print_world_coordinates()
 {
 	printf_P(_N("world coordinates: (%.3f, %.3f, %.3f)\n"), current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS]);

+ 15 - 20
Firmware/ultralcd.cpp

@@ -7258,30 +7258,25 @@ static void lcd_sd_updir()
 
 void lcd_print_stop()
 {
-//-//
-     if(!card.sdprinting)
-          {
-          SERIAL_ECHOLNRPGM(MSG_OCTOPRINT_CANCEL);   // for Octoprint
-          }
-	saved_printing = false;
-    saved_printing_type = PRINTING_TYPE_NONE;
+    if (!card.sdprinting) {
+        SERIAL_ECHOLNRPGM(MSG_OCTOPRINT_CANCEL);   // for Octoprint
+    }
+
+    cli();
+
+    // Clear any saved printing state
+    cancel_saved_printing();
 	cancel_heatup = true;
-#ifdef MESH_BED_LEVELING
-	mbl.active = false;
-#endif
-	// Stop the stoppers, update the position from the stoppers.
-	if (mesh_bed_leveling_flag == false && homing_flag == false)
-	{
-		planner_abort_hard();
-		// Because the planner_abort_hard() initialized current_position[Z] from the stepper,
-		// Z baystep is no more applied. Reset it.
-		babystep_reset();
-	}
-	// Clean the input command queue.
+
+    // Abort the planner/queue/sd
+    planner_abort_hard();
 	cmdqueue_reset();
-	lcd_setstatuspgm(_T(MSG_PRINT_ABORTED));
 	card.sdprinting = false;
 	card.closefile();
+    st_reset_timer();
+    sei();
+
+	lcd_setstatuspgm(_T(MSG_PRINT_ABORTED));
 	stoptime = _millis();
 	unsigned long t = (stoptime - starttime - pause_time) / 1000; //time in s
 	pause_time = 0;