From a1f026f57ad7dbf4c50b135cf1dc0f9eacc06025 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 20 Feb 2020 20:09:37 -0600 Subject: [PATCH] Inline manage_inactivity, tweak autoreport_paused --- Marlin/src/MarlinCore.cpp | 8 ++------ Marlin/src/MarlinCore.h | 6 ------ Marlin/src/core/utility.cpp | 12 ++++++++++++ Marlin/src/core/utility.h | 13 +++++-------- Marlin/src/feature/bedlevel/ubl/ubl.cpp | 10 ++++------ Marlin/src/gcode/gcode.cpp | 8 ++++++-- Marlin/src/gcode/gcode.h | 12 ++++++++++++ 7 files changed, 41 insertions(+), 28 deletions(-) diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index b1e895d97..19fe1c062 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -204,10 +204,6 @@ bool wait_for_heatup = true; bool wait_for_user; // = false; #endif -#if HAS_AUTO_REPORTING || ENABLED(HOST_KEEPALIVE_FEATURE) - bool suspend_auto_report; // = false -#endif - // Inactivity shutdown millis_t max_inactive_time, // = 0 stepper_inactive_time = (DEFAULT_STEPPER_DEACTIVE_TIME) * 1000UL; @@ -432,7 +428,7 @@ void startOrResumeJob() { * - Pulse FET_SAFETY_PIN if it exists */ -void manage_inactivity(const bool ignore_stepper_queue/*=false*/) { +inline void manage_inactivity(const bool ignore_stepper_queue=false) { #if HAS_FILAMENT_SENSOR runout.run(); @@ -697,7 +693,7 @@ void idle( #endif #if HAS_AUTO_REPORTING - if (!suspend_auto_report) { + if (!gcode.autoreport_paused) { #if ENABLED(AUTO_REPORT_TEMPERATURES) thermalManager.auto_report_temperatures(); #endif diff --git a/Marlin/src/MarlinCore.h b/Marlin/src/MarlinCore.h index fb5746225..5a8157bde 100644 --- a/Marlin/src/MarlinCore.h +++ b/Marlin/src/MarlinCore.h @@ -44,8 +44,6 @@ void idle( #endif ); -void manage_inactivity(const bool ignore_stepper_queue=false); - #if ENABLED(EXPERIMENTAL_I2CBUS) #include "feature/twibus.h" extern TWIBus i2c; @@ -84,10 +82,6 @@ extern bool wait_for_heatup; extern bool wait_for_user; #endif -#if HAS_AUTO_REPORTING || ENABLED(HOST_KEEPALIVE_FEATURE) - extern bool suspend_auto_report; -#endif - // Inactivity shutdown timer extern millis_t max_inactive_time, stepper_inactive_time; diff --git a/Marlin/src/core/utility.cpp b/Marlin/src/core/utility.cpp index 768bc5e9d..64783d070 100644 --- a/Marlin/src/core/utility.cpp +++ b/Marlin/src/core/utility.cpp @@ -35,6 +35,18 @@ void safe_delay(millis_t ms) { thermalManager.manage_heater(); // This keeps us safe if too many small safe_delay() calls are made } +// A delay to provide brittle hosts time to receive bytes +#if ENABLED(SERIAL_OVERRUN_PROTECTION) + + #include "../gcode/gcode.h" // for set_autoreport_paused + + void serial_delay(const millis_t ms) { + const bool was = gcode.set_autoreport_paused(true); + safe_delay(ms); + gcode.set_autoreport_paused(was); + } +#endif + #if ENABLED(DEBUG_LEVELING_FEATURE) #include "../module/probe.h" diff --git a/Marlin/src/core/utility.h b/Marlin/src/core/utility.h index d0a5274ce..e34f9dd58 100644 --- a/Marlin/src/core/utility.h +++ b/Marlin/src/core/utility.h @@ -27,14 +27,11 @@ // Delay that ensures heaters and watchdog are kept alive void safe_delay(millis_t ms); -// A delay to provide brittle hosts time to receive bytes -inline void serial_delay(const millis_t ms) { - #if ENABLED(SERIAL_OVERRUN_PROTECTION) - safe_delay(ms); - #else - UNUSED(ms); - #endif -} +#if ENABLED(SERIAL_OVERRUN_PROTECTION) + void serial_delay(const millis_t ms); +#else + inline void serial_delay(const millis_t) {} +#endif #if GRID_MAX_POINTS_X && GRID_MAX_POINTS_Y diff --git a/Marlin/src/feature/bedlevel/ubl/ubl.cpp b/Marlin/src/feature/bedlevel/ubl/ubl.cpp index 6583e679c..72fe9d974 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl.cpp +++ b/Marlin/src/feature/bedlevel/ubl/ubl.cpp @@ -28,6 +28,8 @@ unified_bed_leveling ubl; + #include "../../../MarlinCore.h" + #include "../../../module/configuration_store.h" #include "../../../module/planner.h" #include "../../../module/motion.h" @@ -151,9 +153,7 @@ * 4: Compact Human-Readable */ void unified_bed_leveling::display_map(const int map_type) { - #if HAS_AUTO_REPORTING || ENABLED(HOST_KEEPALIVE_FEATURE) - suspend_auto_report = true; - #endif + const bool was = gcode.set_autoreport_paused(true); constexpr uint8_t eachsp = 1 + 6 + 1, // [-3.567] twixt = eachsp * (GRID_MAX_POINTS_X) - 9 * 2; // Leading 4sp, Coordinates 9sp each @@ -229,9 +229,7 @@ SERIAL_EOL(); } - #if HAS_AUTO_REPORTING || ENABLED(HOST_KEEPALIVE_FEATURE) - suspend_auto_report = false; - #endif + set_gcode.set_autoreport_paused(was); } bool unified_bed_leveling::sanity_check() { diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp index 06ab3af52..4c9832dba 100644 --- a/Marlin/src/gcode/gcode.cpp +++ b/Marlin/src/gcode/gcode.cpp @@ -53,7 +53,7 @@ GcodeSuite gcode; #include "../feature/cancel_object.h" #endif -#include "../MarlinCore.h" // for idle() and suspend_auto_report +#include "../MarlinCore.h" // for idle() millis_t GcodeSuite::previous_move_ms; @@ -66,6 +66,10 @@ uint8_t GcodeSuite::axis_relative = ( | (ar_init.e ? _BV(REL_E) : 0) ); +#if HAS_AUTO_REPORTING || ENABLED(HOST_KEEPALIVE_FEATURE) + bool GcodeSuite::autoreport_paused; // = false +#endif + #if ENABLED(HOST_KEEPALIVE_FEATURE) GcodeSuite::MarlinBusyState GcodeSuite::busy_state = NOT_BUSY; uint8_t GcodeSuite::host_keepalive_interval = DEFAULT_KEEPALIVE_INTERVAL; @@ -942,7 +946,7 @@ void GcodeSuite::process_subcommands_now(char * gcode) { void GcodeSuite::host_keepalive() { const millis_t ms = millis(); static millis_t next_busy_signal_ms = 0; - if (!suspend_auto_report && host_keepalive_interval && busy_state != NOT_BUSY) { + if (!autoreport_paused && host_keepalive_interval && busy_state != NOT_BUSY) { if (PENDING(ms, next_busy_signal_ms)) return; switch (busy_state) { case IN_HANDLER: diff --git a/Marlin/src/gcode/gcode.h b/Marlin/src/gcode/gcode.h index 7670a8163..c44c17081 100644 --- a/Marlin/src/gcode/gcode.h +++ b/Marlin/src/gcode/gcode.h @@ -351,6 +351,18 @@ public: process_subcommands_now_P(G28_STR); } + #if HAS_AUTO_REPORTING || ENABLED(HOST_KEEPALIVE_FEATURE) + static bool autoreport_paused; + static inline bool set_autoreport_paused(const bool p) { + const bool was = autoreport_paused; + autoreport_paused = p; + return was; + } + #else + static constexpr bool autoreport_paused = false; + static inline bool set_autoreport_paused(const bool) { return false; } + #endif + #if ENABLED(HOST_KEEPALIVE_FEATURE) /** * States for managing Marlin and host communication