From 735c1b6183739152eeddade4c06c17e3b0de38bc Mon Sep 17 00:00:00 2001
From: Katelyn Schiesser <katelyn.schiesser@gmail.com>
Date: Thu, 25 Feb 2021 06:28:27 -0800
Subject: [PATCH] PROBING_HEATERS_OFF sub-option WAIT_FOR_HOTEND (#20835)

---
 Marlin/Configuration.h            |  1 +
 Marlin/src/module/motion.cpp      |  7 ++++++-
 Marlin/src/module/probe.cpp       |  4 ++++
 Marlin/src/module/temperature.cpp | 11 +++++++++++
 Marlin/src/module/temperature.h   |  4 ++++
 5 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h
index 1c98168236b..ea3385356a1 100644
--- a/Marlin/Configuration.h
+++ b/Marlin/Configuration.h
@@ -1139,6 +1139,7 @@
 //#define PROBING_HEATERS_OFF       // Turn heaters off when probing
 #if ENABLED(PROBING_HEATERS_OFF)
   //#define WAIT_FOR_BED_HEATER     // Wait for bed to heat back up between probes (to improve accuracy)
+  //#define WAIT_FOR_HOTEND         // Wait for hotend to heat back up between probes (to improve accuracy & prevent cold extrude)
 #endif
 //#define PROBING_FANS_OFF          // Turn fans off when probing
 //#define PROBING_STEPPERS_OFF      // Turn steppers off (unless needed to hold position) when probing
diff --git a/Marlin/src/module/motion.cpp b/Marlin/src/module/motion.cpp
index 10d3585a732..55973185eee 100644
--- a/Marlin/src/module/motion.cpp
+++ b/Marlin/src/module/motion.cpp
@@ -1318,11 +1318,16 @@ void prepare_line_to_destination() {
     if (is_home_dir) {
 
       if (TERN0(HOMING_Z_WITH_PROBE, axis == Z_AXIS)) {
-        #if ALL(HAS_HEATED_BED, WAIT_FOR_BED_HEATER)
+        #if BOTH(HAS_HEATED_BED, WAIT_FOR_BED_HEATER)
           // Wait for bed to heat back up between probing points
           thermalManager.wait_for_bed_heating();
         #endif
 
+        #if BOTH(HAS_HOTEND, WAIT_FOR_HOTEND)
+          // Wait for the hotend to heat back up between probing points
+          thermalManager.wait_for_hotend_heating(active_extruder);
+        #endif
+
         TERN_(HAS_QUIET_PROBING, if (final_approach) probe.set_probing_paused(true));
       }
 
diff --git a/Marlin/src/module/probe.cpp b/Marlin/src/module/probe.cpp
index 6df115225e4..e59e514a067 100644
--- a/Marlin/src/module/probe.cpp
+++ b/Marlin/src/module/probe.cpp
@@ -478,6 +478,10 @@ bool Probe::probe_down_to_z(const float z, const feedRate_t fr_mm_s) {
     thermalManager.wait_for_bed_heating();
   #endif
 
+  #if BOTH(HAS_TEMP_HOTEND, WAIT_FOR_HOTEND)
+    thermalManager.wait_for_hotend_heating(active_extruder);
+  #endif
+
   if (TERN0(BLTOUCH_SLOW_MODE, bltouch.deploy())) return true; // Deploy in LOW SPEED MODE on every probe action
 
   // Disable stealthChop if used. Enable diag1 pin on driver.
diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp
index a220386b9e4..e85e48c2d45 100644
--- a/Marlin/src/module/temperature.cpp
+++ b/Marlin/src/module/temperature.cpp
@@ -3447,6 +3447,17 @@ void Temperature::tick() {
       return false;
     }
 
+    #if ENABLED(WAIT_FOR_HOTEND)
+      void Temperature::wait_for_hotend_heating(const uint8_t target_extruder) {
+        if (isHeatingHotend(target_extruder)) {
+          SERIAL_ECHOLNPGM("Wait for hotend heating...");
+          LCD_MESSAGEPGM(MSG_HEATING);
+          wait_for_hotend(target_extruder);
+          ui.reset_status();
+        }
+      }
+    #endif
+
   #endif // HAS_TEMP_HOTEND
 
   #if HAS_HEATED_BED
diff --git a/Marlin/src/module/temperature.h b/Marlin/src/module/temperature.h
index 1019c10fad5..5f5a076911f 100644
--- a/Marlin/src/module/temperature.h
+++ b/Marlin/src/module/temperature.h
@@ -630,6 +630,10 @@ class Temperature {
             , const bool click_to_cancel=false
           #endif
         );
+
+        #if ENABLED(WAIT_FOR_HOTEND)
+          static void wait_for_hotend_heating(const uint8_t target_extruder);
+        #endif
       #endif
 
       FORCE_INLINE static bool still_heating(const uint8_t e) {