diff --git a/Marlin/src/Marlin.cpp b/Marlin/src/Marlin.cpp index 38801990f6..10c223849a 100644 --- a/Marlin/src/Marlin.cpp +++ b/Marlin/src/Marlin.cpp @@ -353,14 +353,6 @@ float cartes[XYZ] = { 0 }; int lpq_len = 20; #endif -#if ENABLED(HOST_KEEPALIVE_FEATURE) - MarlinBusyState busy_state = NOT_BUSY; - static millis_t next_busy_signal_ms = 0; - uint8_t host_keepalive_interval = DEFAULT_KEEPALIVE_INTERVAL; -#else - #define host_keepalive() NOOP -#endif - #if ENABLED(I2C_POSITION_ENCODERS) I2CPositionEncodersMgr I2CPEM; uint8_t blockBufferIndexRef = 0; @@ -2245,46 +2237,6 @@ static void homeaxis(const AxisEnum axis) { #endif -/** - * *************************************************************************** - * ***************************** G-CODE HANDLING ***************************** - * *************************************************************************** - */ - -#if ENABLED(HOST_KEEPALIVE_FEATURE) - - /** - * Output a "busy" message at regular intervals - * while the machine is not accepting commands. - */ - void host_keepalive() { - const millis_t ms = millis(); - if (host_keepalive_interval && busy_state != NOT_BUSY) { - if (PENDING(ms, next_busy_signal_ms)) return; - switch (busy_state) { - case IN_HANDLER: - case IN_PROCESS: - SERIAL_ECHO_START(); - SERIAL_ECHOLNPGM(MSG_BUSY_PROCESSING); - break; - case PAUSED_FOR_USER: - SERIAL_ECHO_START(); - SERIAL_ECHOLNPGM(MSG_BUSY_PAUSED_FOR_USER); - break; - case PAUSED_FOR_INPUT: - SERIAL_ECHO_START(); - SERIAL_ECHOLNPGM(MSG_BUSY_PAUSED_FOR_INPUT); - break; - default: - break; - } - } - next_busy_signal_ms = ms + host_keepalive_interval * 1000UL; - } - -#endif // HOST_KEEPALIVE_FEATURE - - /************************************************** ***************** GCode Handlers ***************** **************************************************/ @@ -3574,7 +3526,9 @@ void idle( lcd_update(); - host_keepalive(); + #if ENABLED(HOST_KEEPALIVE_FEATURE) + gcode.host_keepalive(); + #endif #if ENABLED(AUTO_REPORT_TEMPERATURES) && (HAS_TEMP_HOTEND || HAS_TEMP_BED) auto_report_temperatures(); diff --git a/Marlin/src/Marlin.h b/Marlin/src/Marlin.h index f56dd4e1d7..527a030e12 100644 --- a/Marlin/src/Marlin.h +++ b/Marlin/src/Marlin.h @@ -266,13 +266,6 @@ extern float soft_endstop_min[XYZ], soft_endstop_max[XYZ]; #define STOW_PROBE() #endif -#if ENABLED(HOST_KEEPALIVE_FEATURE) - extern MarlinBusyState busy_state; - #define KEEPALIVE_STATE(n) do{ busy_state = n; }while(0) -#else - #define KEEPALIVE_STATE(n) NOOP -#endif - #if FAN_COUNT > 0 extern int16_t fanSpeeds[FAN_COUNT]; #if ENABLED(PROBING_FANS_OFF) diff --git a/Marlin/src/core/enum.h b/Marlin/src/core/enum.h index 9bee5db459..9bf3ba856a 100644 --- a/Marlin/src/core/enum.h +++ b/Marlin/src/core/enum.h @@ -121,20 +121,6 @@ enum EndstopEnum { #endif #endif -/** - * States for managing Marlin and host communication - * Marlin sends messages if blocked or busy - */ -#if ENABLED(HOST_KEEPALIVE_FEATURE) - enum MarlinBusyState { - NOT_BUSY, // Not in a handler - IN_HANDLER, // Processing a GCode - IN_PROCESS, // Known to be blocking command input (as in G29) - PAUSED_FOR_USER, // Blocking pending any input - PAUSED_FOR_INPUT // Blocking pending text input (concept) - }; -#endif - /** * SD Card */ diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp index 7fd4f0df3d..1b1525de84 100644 --- a/Marlin/src/gcode/gcode.cpp +++ b/Marlin/src/gcode/gcode.cpp @@ -41,6 +41,11 @@ millis_t GcodeSuite::previous_cmd_ms; bool GcodeSuite::axis_relative_modes[] = AXIS_RELATIVE_MODES; +#if ENABLED(HOST_KEEPALIVE_FEATURE) + GcodeSuite::MarlinBusyState GcodeSuite::busy_state = NOT_BUSY; + uint8_t GcodeSuite::host_keepalive_interval = DEFAULT_KEEPALIVE_INTERVAL; +#endif + /** * Set target_extruder from the T parameter or the active_extruder * @@ -1068,3 +1073,37 @@ void GcodeSuite::process_next_command() { ok_to_send(); } + +#if ENABLED(HOST_KEEPALIVE_FEATURE) + + /** + * Output a "busy" message at regular intervals + * while the machine is not accepting commands. + */ + void GcodeSuite::host_keepalive() { + const millis_t ms = millis(); + static millis_t next_busy_signal_ms = 0; + if (host_keepalive_interval && busy_state != NOT_BUSY) { + if (PENDING(ms, next_busy_signal_ms)) return; + switch (busy_state) { + case IN_HANDLER: + case IN_PROCESS: + SERIAL_ECHO_START(); + SERIAL_ECHOLNPGM(MSG_BUSY_PROCESSING); + break; + case PAUSED_FOR_USER: + SERIAL_ECHO_START(); + SERIAL_ECHOLNPGM(MSG_BUSY_PAUSED_FOR_USER); + break; + case PAUSED_FOR_INPUT: + SERIAL_ECHO_START(); + SERIAL_ECHOLNPGM(MSG_BUSY_PAUSED_FOR_INPUT); + break; + default: + break; + } + } + next_busy_signal_ms = ms + host_keepalive_interval * 1000UL; + } + +#endif // HOST_KEEPALIVE_FEATURE diff --git a/Marlin/src/gcode/gcode.h b/Marlin/src/gcode/gcode.h index 2f40b775b9..1fdd440d8c 100644 --- a/Marlin/src/gcode/gcode.h +++ b/Marlin/src/gcode/gcode.h @@ -263,6 +263,8 @@ public: static void get_destination_from_command(); static void process_next_command(); + static FORCE_INLINE void home_all_axes() { G28(true); } + /** * Multi-stepper support for M92, M201, M203 */ @@ -274,7 +276,28 @@ public: #define TARGET_EXTRUDER 0 #endif - static FORCE_INLINE void home_all_axes() { G28(true); } + #if ENABLED(HOST_KEEPALIVE_FEATURE) + /** + * States for managing Marlin and host communication + * Marlin sends messages if blocked or busy + */ + enum MarlinBusyState { + NOT_BUSY, // Not in a handler + IN_HANDLER, // Processing a GCode + IN_PROCESS, // Known to be blocking command input (as in G29) + PAUSED_FOR_USER, // Blocking pending any input + PAUSED_FOR_INPUT // Blocking pending text input (concept) + }; + + static MarlinBusyState busy_state; + static uint8_t host_keepalive_interval; + + static void host_keepalive(); + + #define KEEPALIVE_STATE(n) gcode.busy_state = gcode.n + #else + #define KEEPALIVE_STATE(n) NOOP + #endif private: diff --git a/Marlin/src/gcode/host/M113.h b/Marlin/src/gcode/host/M113.h index e7310dfa4e..59b26c7daf 100644 --- a/Marlin/src/gcode/host/M113.h +++ b/Marlin/src/gcode/host/M113.h @@ -27,11 +27,11 @@ */ void gcode_M113() { if (parser.seenval('S')) { - host_keepalive_interval = parser.value_byte(); - NOMORE(host_keepalive_interval, 60); + gcode.host_keepalive_interval = parser.value_byte(); + NOMORE(gcode.host_keepalive_interval, 60); } else { SERIAL_ECHO_START(); - SERIAL_ECHOLNPAIR("M113 S", (unsigned long)host_keepalive_interval); + SERIAL_ECHOLNPAIR("M113 S", (unsigned long)gcode.host_keepalive_interval); } }