From af08e164266d37b778c00668dff96a35d754e140 Mon Sep 17 00:00:00 2001
From: Marek Bel <marek.bel@posta.cz>
Date: Tue, 4 Sep 2018 08:06:03 +0200
Subject: [PATCH] Use stop_and_save_print_to_ram() and
 restore_print_from_ram_and_continue() pair to pause print from menu. Move
 declaration of those functions to marlin.h. Move declaration of
 FSensorStateMenu to ultralcd.h.

Known limitations: Filament is not retracted, extruder is not lifted in Z and moved to rear left corner in XY. Nozzle heating is not turned off nor restored. Unused code is not removed.
---
 Firmware/Marlin.h        |  3 +++
 Firmware/Marlin_main.cpp |  3 ---
 Firmware/fsensor.cpp     |  5 +----
 Firmware/ultralcd.cpp    | 13 +++++++++++--
 Firmware/ultralcd.h      |  1 +
 5 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h
index dbb611f4..5367a41e 100644
--- a/Firmware/Marlin.h
+++ b/Firmware/Marlin.h
@@ -419,6 +419,9 @@ extern void print_world_coordinates();
 extern void print_physical_coordinates();
 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);
+
 
 //estimated time to end of the print
 extern uint16_t print_time_remaining();
diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp
index 6ac5298e..f30abc71 100644
--- a/Firmware/Marlin_main.cpp
+++ b/Firmware/Marlin_main.cpp
@@ -649,9 +649,6 @@ void servo_init()
 }
 
 
-void stop_and_save_print_to_ram(float z_move, float e_move);
-void restore_print_from_ram_and_continue(float e_move);
-
 bool fans_check_enabled = true;
 
 
diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp
index 8800dbb0..a035683c 100644
--- a/Firmware/fsensor.cpp
+++ b/Firmware/fsensor.cpp
@@ -7,6 +7,7 @@
 #include "planner.h"
 #include "fastio.h"
 #include "cmdqueue.h"
+#include "ultralcd.h"
 
 //Basic params
 #define FSENSOR_CHUNK_LEN    0.64F  //filament sensor chunk length 0.64mm
@@ -27,10 +28,6 @@ const char ERRMSG_PAT9125_NOT_RESP[] PROGMEM = "PAT9125 not responding (%d)!\n";
 #define FSENSOR_INT_PIN         63  //filament sensor interrupt pin PK1
 #define FSENSOR_INT_PIN_MSK   0x02  //filament sensor interrupt pin mask (bit1)
 
-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 int8_t FSensorStateMenu;
-
 void fsensor_stop_and_save_print(void)
 {
 	printf_P(PSTR("fsensor_stop_and_save_print\n"));
diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp
index f10aa6eb..95cc170a 100644
--- a/Firmware/ultralcd.cpp
+++ b/Firmware/ultralcd.cpp
@@ -5520,6 +5520,15 @@ static void lcd_test_menu()
 }
 #endif //LCD_TEST
 
+static void pause_print()
+{
+    stop_and_save_print_to_ram(0.0,0.0);
+}
+static void resume_print()
+{
+    restore_print_from_ram_and_continue(0.0);
+}
+
 static void lcd_main_menu()
 {
 
@@ -5613,11 +5622,11 @@ static void lcd_main_menu()
 		if (mesh_bed_leveling_flag == false && homing_flag == false) {
 			if (card.sdprinting)
 			{
-				MENU_ITEM_FUNCTION_P(_i("Pause print"), lcd_sdcard_pause);////MSG_PAUSE_PRINT c=0 r=0
+				MENU_ITEM_FUNCTION_P(_i("Pause print"), pause_print);////MSG_PAUSE_PRINT c=0 r=0
 			}
 			else
 			{
-				MENU_ITEM_FUNCTION_P(_i("Resume print"), lcd_sdcard_resume);////MSG_RESUME_PRINT c=0 r=0
+				MENU_ITEM_FUNCTION_P(_i("Resume print"), resume_print);////MSG_RESUME_PRINT c=0 r=0
 			}
 			MENU_ITEM_SUBMENU_P(_T(MSG_STOP_PRINT), lcd_sdcard_stop);
 		}
diff --git a/Firmware/ultralcd.h b/Firmware/ultralcd.h
index c6bbb900..d7f8d00d 100644
--- a/Firmware/ultralcd.h
+++ b/Firmware/ultralcd.h
@@ -82,6 +82,7 @@ extern void lcd_diag_show_end_stops();
 #define LCD_COMMAND_V2_CAL 8
 
 extern int lcd_commands_type;
+extern int8_t FSensorStateMenu;
 
 #define CUSTOM_MSG_TYPE_STATUS 0 // status message from lcd_status_message variable
 #define CUSTOM_MSG_TYPE_MESHBL 1 // Mesh bed leveling in progress