From e95c2ad59297423c4c4ef051e7e3e17d9502e15e Mon Sep 17 00:00:00 2001
From: Marek Bel <marek.bel@posta.cz>
Date: Mon, 5 Nov 2018 17:43:07 +0100
Subject: [PATCH] Display auto deplete as not available if filament sensor is
 disabled.

---
 Firmware/mmu.cpp      |  2 +-
 Firmware/ultralcd.cpp | 32 +++++++++++++++++++++-----------
 Firmware/ultralcd.h   |  2 +-
 3 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/Firmware/mmu.cpp b/Firmware/mmu.cpp
index 92d13835..2db7d42f 100644
--- a/Firmware/mmu.cpp
+++ b/Firmware/mmu.cpp
@@ -269,7 +269,7 @@ void mmu_loop(void)
 			if (!mmu_finda && CHECK_FINDA && fsensor_enabled) {
 				fsensor_stop_and_save_print();
 				enquecommand_front_P(PSTR("FSENSOR_RECOVER")); //then recover
-				if (lcd_autoDeplete) enquecommand_front_P(PSTR("M600 AUTO")); //save print and run M600 command
+				if (lcd_autoDepleteEnabled()) enquecommand_front_P(PSTR("M600 AUTO")); //save print and run M600 command
 				else enquecommand_front_P(PSTR("M600")); //save print and run M600 command
 			}
 			mmu_state = 1;
diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp
index 98c9b8f3..4127ab40 100644
--- a/Firmware/ultralcd.cpp
+++ b/Firmware/ultralcd.cpp
@@ -90,7 +90,7 @@ unsigned long display_time; //just timer for showing pid finished message on lcd
 float pid_temp = DEFAULT_PID_TEMP;
 
 static bool forceMenuExpire = false;
-bool lcd_autoDeplete;
+static bool lcd_autoDeplete;
 
 
 static float manual_feedrate[] = MANUAL_FEEDRATE;
@@ -4423,6 +4423,11 @@ static void lcd_wizard_load()
 	gcode_M701();
 }
 
+bool lcd_autoDepleteEnabled()
+{
+    return (lcd_autoDeplete && fsensor_enabled);
+}
+
 //! @brief Printer first run wizard (Selftest and calibration)
 //!
 //!
@@ -4685,6 +4690,18 @@ while(0)
 #define SETTINGS_FILAMENT_SENSOR do{}while(0)
 #endif //FILAMENT_SENSOR
 
+#define SETTINGS_AUTO_DEPLETE \
+do\
+{\
+    if (mmu_enabled)\
+    {\
+        if (!fsensor_enabled)         MENU_ITEM_TEXT_P(_i("Auto deplete[N/A]"));\
+        else if (lcd_autoDeplete) MENU_ITEM_FUNCTION_P(_i("Auto deplete [on]"), auto_deplete_switch);\
+        else                      MENU_ITEM_FUNCTION_P(_i("Auto deplete[off]"), auto_deplete_switch);\
+    }\
+}\
+while(0)\
+
 #ifdef TMC2130
 #define SETTINGS_SILENT_MODE \
 do\
@@ -4812,11 +4829,7 @@ static void lcd_settings_menu()
 
 	SETTINGS_FILAMENT_SENSOR;
 
-	if (mmu_enabled)
-	{
-        if (lcd_autoDeplete) MENU_ITEM_FUNCTION_P(_i("Auto deplete [on]"), auto_deplete_switch);
-        else MENU_ITEM_FUNCTION_P(_i("Auto deplete[off]"), auto_deplete_switch);
-	}
+	SETTINGS_AUTO_DEPLETE;
 
 	if (fans_check_enabled == true)
 		MENU_ITEM_FUNCTION_P(_i("Fans check   [on]"), lcd_set_fan_check);////MSG_FANS_CHECK_ON c=17 r=1
@@ -5927,11 +5940,8 @@ static void lcd_tune_menu()
 		MENU_ITEM_FUNCTION_P(_T(MSG_FSENSOR_ON), lcd_fsensor_state_set);
 	}
 #endif //FILAMENT_SENSOR
-    if (mmu_enabled)
-    {
-        if (lcd_autoDeplete) MENU_ITEM_FUNCTION_P(_i("Auto deplete [on]"), auto_deplete_switch);
-        else MENU_ITEM_FUNCTION_P(_i("Auto deplete[off]"), auto_deplete_switch);
-    }
+
+	SETTINGS_AUTO_DEPLETE;
 
 #ifdef TMC2130
      if(!farm_mode)
diff --git a/Firmware/ultralcd.h b/Firmware/ultralcd.h
index 29c63596..44bbf390 100644
--- a/Firmware/ultralcd.h
+++ b/Firmware/ultralcd.h
@@ -118,7 +118,6 @@ extern int8_t SilentModeMenu;
 
 extern bool cancel_heatup;
 extern bool isPrintPaused;
-extern bool lcd_autoDeplete;
 
 
 void lcd_ignore_click(bool b=true);
@@ -174,6 +173,7 @@ void lcd_set_progress();
 void lcd_language();
 
 void lcd_wizard();
+bool lcd_autoDepleteEnabled();
 
 //! @brief Wizard state
 enum class WizState : uint8_t