From 51f195e698e2cbdbb8f1a97213f0c9553e8fc470 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 15 Sep 2017 20:44:40 -0500 Subject: [PATCH] Move dwell to gcode --- Marlin/src/Marlin.cpp | 17 +++-------------- Marlin/src/gcode/control/M3-M5.h | 4 ++-- Marlin/src/gcode/gcode.cpp | 12 +++++++++++- Marlin/src/gcode/gcode.h | 2 ++ Marlin/src/gcode/lcd/M0_M1.h | 2 +- Marlin/src/gcode/motion/G4.h | 2 +- Marlin/src/module/tool_change.cpp | 6 +++++- 7 files changed, 25 insertions(+), 20 deletions(-) diff --git a/Marlin/src/Marlin.cpp b/Marlin/src/Marlin.cpp index 3cb9136314..1bd50e8bea 100644 --- a/Marlin/src/Marlin.cpp +++ b/Marlin/src/Marlin.cpp @@ -163,7 +163,6 @@ volatile bool wait_for_heatup = true; #endif // Inactivity shutdown -millis_t previous_cmd_ms = 0; static millis_t max_inactive_time = 0; static millis_t stepper_inactive_time = (DEFAULT_STEPPER_DEACTIVE_TIME) * 1000UL; @@ -366,16 +365,6 @@ void suicide() { ***************** GCode Handlers ***************** **************************************************/ -#if ENABLED(ARC_SUPPORT) - #include "gcode/motion/G2_G3.h" -#endif - -void dwell(millis_t time) { - gcode.refresh_cmd_timeout(); - time += previous_cmd_ms; - while (PENDING(millis(), time)) idle(); -} - #include "gcode/motion/G4.h" #if ENABLED(BEZIER_CURVE_SUPPORT) @@ -882,7 +871,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) { const millis_t ms = millis(); - if (max_inactive_time && ELAPSED(ms, previous_cmd_ms + max_inactive_time)) { + if (max_inactive_time && ELAPSED(ms, gcode.previous_cmd_ms + max_inactive_time)) { SERIAL_ERROR_START(); SERIAL_ECHOLNPAIR(MSG_KILL_INACTIVE_TIME, parser.command_ptr); kill(PSTR(MSG_KILLED)); @@ -895,7 +884,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) { #define MOVE_AWAY_TEST true #endif - if (MOVE_AWAY_TEST && stepper_inactive_time && ELAPSED(ms, previous_cmd_ms + stepper_inactive_time) + if (MOVE_AWAY_TEST && stepper_inactive_time && ELAPSED(ms, gcode.previous_cmd_ms + stepper_inactive_time) && !ignore_stepper_queue && !planner.blocks_queued()) { #if ENABLED(DISABLE_INACTIVE_X) disable_X(); @@ -965,7 +954,7 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) { #endif #if ENABLED(EXTRUDER_RUNOUT_PREVENT) - if (ELAPSED(ms, previous_cmd_ms + (EXTRUDER_RUNOUT_SECONDS) * 1000UL) + if (ELAPSED(ms, gcode.previous_cmd_ms + (EXTRUDER_RUNOUT_SECONDS) * 1000UL) && thermalManager.degHotend(active_extruder) > EXTRUDER_RUNOUT_MINTEMP) { #if ENABLED(SWITCHING_EXTRUDER) const bool oldstatus = E0_ENABLE_READ; diff --git a/Marlin/src/gcode/control/M3-M5.h b/Marlin/src/gcode/control/M3-M5.h index c45cf9f720..c7d1ef502e 100644 --- a/Marlin/src/gcode/control/M3-M5.h +++ b/Marlin/src/gcode/control/M3-M5.h @@ -52,10 +52,10 @@ */ // Wait for spindle to come up to speed -inline void delay_for_power_up() { dwell(SPINDLE_LASER_POWERUP_DELAY); } +inline void delay_for_power_up() { gcode.dwell(SPINDLE_LASER_POWERUP_DELAY); } // Wait for spindle to stop turning -inline void delay_for_power_down() { dwell(SPINDLE_LASER_POWERDOWN_DELAY); } +inline void delay_for_power_down() { gcode.dwell(SPINDLE_LASER_POWERDOWN_DELAY); } /** * ocr_val_mode() is used for debugging and to get the points needed to compute the RPM vs ocr_val line diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp index 530a689468..89bc70946a 100644 --- a/Marlin/src/gcode/gcode.cpp +++ b/Marlin/src/gcode/gcode.cpp @@ -31,12 +31,13 @@ GcodeSuite gcode; #include "parser.h" #include "queue.h" #include "../module/motion.h" -#include "../module/printcounter.h" #if ENABLED(PRINTCOUNTER) #include "../module/printcounter.h" #endif +#include "../Marlin.h" // for idle() + uint8_t GcodeSuite::target_extruder; millis_t GcodeSuite::previous_cmd_ms; @@ -99,6 +100,15 @@ void GcodeSuite::get_destination_from_command() { #endif } +/** + * Dwell waits immediately. It does not synchronize. Use M400 instead of G4 + */ +void GcodeSuite::dwell(millis_t time) { + refresh_cmd_timeout(); + time += previous_cmd_ms; + while (PENDING(millis(), time)) idle(); +} + // // Placeholders for non-migrated codes // diff --git a/Marlin/src/gcode/gcode.h b/Marlin/src/gcode/gcode.h index 1fdd440d8c..dd44e42a85 100644 --- a/Marlin/src/gcode/gcode.h +++ b/Marlin/src/gcode/gcode.h @@ -299,6 +299,8 @@ public: #define KEEPALIVE_STATE(n) NOOP #endif + void dwell(millis_t time); + private: static void G0_G1( diff --git a/Marlin/src/gcode/lcd/M0_M1.h b/Marlin/src/gcode/lcd/M0_M1.h index a47101fbe0..c535be15e3 100644 --- a/Marlin/src/gcode/lcd/M0_M1.h +++ b/Marlin/src/gcode/lcd/M0_M1.h @@ -67,7 +67,7 @@ void gcode_M0_M1() { gcode.refresh_cmd_timeout(); if (ms > 0) { - ms += previous_cmd_ms; // wait until this time for a click + ms += gcode.previous_cmd_ms; // wait until this time for a click while (PENDING(millis(), ms) && wait_for_user) idle(); } else { diff --git a/Marlin/src/gcode/motion/G4.h b/Marlin/src/gcode/motion/G4.h index a10b974afa..8eb3f198dd 100644 --- a/Marlin/src/gcode/motion/G4.h +++ b/Marlin/src/gcode/motion/G4.h @@ -33,5 +33,5 @@ void gcode_G4() { if (!lcd_hasstatus()) LCD_MESSAGEPGM(MSG_DWELL); - dwell(dwell_ms); + gcode.dwell(dwell_ms); } diff --git a/Marlin/src/module/tool_change.cpp b/Marlin/src/module/tool_change.cpp index 17a986e10e..665b2bb7f3 100644 --- a/Marlin/src/module/tool_change.cpp +++ b/Marlin/src/module/tool_change.cpp @@ -30,6 +30,10 @@ #include "../inc/MarlinConfig.h" +#if ENABLED(PARKING_EXTRUDER) && PARKING_EXTRUDER_SOLENOIDS_DELAY > 0 + #include "../gcode/gcode.h" // for dwell() +#endif + #if ENABLED(SWITCHING_EXTRUDER) #if EXTRUDERS > 3 @@ -74,7 +78,7 @@ default: OUT_WRITE(SOL0_PIN, state); break; } #if PARKING_EXTRUDER_SOLENOIDS_DELAY > 0 - dwell(PARKING_EXTRUDER_SOLENOIDS_DELAY); + gcode.dwell(PARKING_EXTRUDER_SOLENOIDS_DELAY); #endif }