From 77b82d300a2afdc9b96d23ab0abb929ca0df36b4 Mon Sep 17 00:00:00 2001
From: Scott Lahteine <github@thinkyhead.com>
Date: Thu, 27 Feb 2020 06:34:48 -0600
Subject: [PATCH] Add idle_no_sleep

---
 Marlin/src/MarlinCore.h                 | 10 ++++++++-
 Marlin/src/feature/pause.cpp            |  9 ++++----
 Marlin/src/gcode/calibrate/G76_M871.cpp | 30 +++++--------------------
 3 files changed, 18 insertions(+), 31 deletions(-)

diff --git a/Marlin/src/MarlinCore.h b/Marlin/src/MarlinCore.h
index 5a8157bde1..fd2cbeaba9 100644
--- a/Marlin/src/MarlinCore.h
+++ b/Marlin/src/MarlinCore.h
@@ -40,10 +40,18 @@ void stop();
 
 void idle(
   #if ENABLED(ADVANCED_PAUSE_FEATURE)
-    bool no_stepper_sleep = false  // pass true to keep steppers from disabling on timeout
+    bool no_stepper_sleep=false    // Pass true to keep steppers from timing out
   #endif
 );
 
+inline void idle_no_sleep() {
+  idle(
+    #if ENABLED(ADVANCED_PAUSE_FEATURE)
+      true
+    #endif
+  );
+}
+
 #if ENABLED(EXPERIMENTAL_I2CBUS)
   #include "feature/twibus.h"
   extern TWIBus i2c;
diff --git a/Marlin/src/feature/pause.cpp b/Marlin/src/feature/pause.cpp
index 95b5cc953f..175a2d21cd 100644
--- a/Marlin/src/feature/pause.cpp
+++ b/Marlin/src/feature/pause.cpp
@@ -202,7 +202,7 @@ bool load_filament(const float &slow_load_length/*=0*/, const float &fast_load_l
       #if HAS_BUZZER
         filament_change_beep(max_beep_count);
       #endif
-      idle(true);
+      idle_no_sleep();
     }
   }
 
@@ -280,7 +280,7 @@ bool load_filament(const float &slow_load_length/*=0*/, const float &fast_load_l
           KEEPALIVE_STATE(PAUSED_FOR_USER);
           wait_for_user = false;
           lcd_pause_show_message(PAUSE_MESSAGE_OPTION);
-          while (pause_menu_response == PAUSE_RESPONSE_WAIT_FOR) idle(true);
+          while (pause_menu_response == PAUSE_RESPONSE_WAIT_FOR) idle_no_sleep();
         }
       #endif
 
@@ -541,7 +541,7 @@ void wait_for_confirmation(const bool is_reload/*=false*/, const int8_t max_beep
       #endif
 
       // Wait for LCD click or M108
-      while (wait_for_user) idle(true);
+      while (wait_for_user) idle_no_sleep();
 
       #if ENABLED(HOST_PROMPT_SUPPORT)
         host_prompt_do(PROMPT_INFO, PSTR("Reheating"));
@@ -576,8 +576,7 @@ void wait_for_confirmation(const bool is_reload/*=false*/, const int8_t max_beep
         filament_change_beep(max_beep_count, true);
       #endif
     }
-
-    idle(true);
+    idle_no_sleep();
   }
   #if ENABLED(DUAL_X_CARRIAGE)
     active_extruder = saved_ext;
diff --git a/Marlin/src/gcode/calibrate/G76_M871.cpp b/Marlin/src/gcode/calibrate/G76_M871.cpp
index 029e58bdd4..ef1a18e112 100644
--- a/Marlin/src/gcode/calibrate/G76_M871.cpp
+++ b/Marlin/src/gcode/calibrate/G76_M871.cpp
@@ -137,11 +137,7 @@ void GcodeSuite::G76() {
     while (thermalManager.degBed() > target_bed
       || thermalManager.degProbe() > target_probe
     ) {
-      idle(
-        #if ENABLED(ADVANCED_PAUSE_FEATURE)
-          true
-        #endif
-      );
+      idle_no_sleep();
       const millis_t ms = millis();
       if (ELAPSED(ms, next_temp_report)) {
         thermalManager.print_heater_states(active_extruder);
@@ -167,11 +163,7 @@ void GcodeSuite::G76() {
       SERIAL_ECHOLNPGM("Waiting for bed and probe to reach target temp.");
       const millis_t probe_timeout_ms = millis() + 900UL * 1000UL;
       while (fabs(thermalManager.degBed() - float(target_bed)) > 0.1 || thermalManager.degProbe() > target_probe) {
-        idle(
-          #if ENABLED(ADVANCED_PAUSE_FEATURE)
-            true
-          #endif
-        );
+        idle_no_sleep();
         const millis_t ms = millis();
         if (ELAPSED(ms, next_temp_report)) {
           thermalManager.print_heater_states(active_extruder);
@@ -191,11 +183,7 @@ void GcodeSuite::G76() {
       do_blocking_move_to(destination);
       SERIAL_ECHOLNPGM("Waiting for probe heating.");
       while (thermalManager.degProbe() < target_probe) {
-        idle(
-          #if ENABLED(ADVANCED_PAUSE_FEATURE)
-            true
-          #endif
-        );
+        idle_no_sleep();
         const millis_t ms = millis();
         if (ELAPSED(ms, next_temp_report)) {
           thermalManager.print_heater_states(active_extruder);
@@ -262,11 +250,7 @@ void GcodeSuite::G76() {
     while (fabs(thermalManager.degBed() - float(target_bed)) > 0.1f
            || thermalManager.degProbe() > target_probe
     ) {
-      idle(
-        #if ENABLED(ADVANCED_PAUSE_FEATURE)
-          true
-        #endif
-      );
+      idle_no_sleep();
       const millis_t ms = millis();
       if (ELAPSED(ms, next_temp_report)) {
         thermalManager.print_heater_states(active_extruder);
@@ -293,11 +277,7 @@ void GcodeSuite::G76() {
 
       const millis_t probe_timeout_ms = millis() + 900UL * 1000UL;
       while (thermalManager.degProbe() < target_probe) {
-        idle(
-          #if ENABLED(ADVANCED_PAUSE_FEATURE)
-            true
-          #endif
-        );
+        idle_no_sleep();
         const millis_t ms = millis();
         if (ELAPSED(ms, next_temp_report)) {
           thermalManager.print_heater_states(active_extruder);