From be0e4a4ad066d20ffb4ede4eb468b43f4a784c62 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 16 Sep 2017 02:13:07 -0500 Subject: [PATCH] Consolidate pause, apply to M125, M600, M24 --- Marlin/src/Marlin.cpp | 16 ++---- .../pause/common.h => feature/pause.cpp} | 49 ++++++++++++++----- Marlin/src/feature/pause.h | 41 ++++++++++++++++ .../gcode/feature/pause/{M125.h => M125.cpp} | 12 ++++- .../gcode/feature/pause/{M600.h => M600.cpp} | 15 +++++- Marlin/src/gcode/gcode.cpp | 8 ++- Marlin/src/gcode/sdcard/{M24.h => M24.cpp} | 14 +++++- 7 files changed, 118 insertions(+), 37 deletions(-) rename Marlin/src/{gcode/feature/pause/common.h => feature/pause.cpp} (89%) create mode 100644 Marlin/src/feature/pause.h rename Marlin/src/gcode/feature/pause/{M125.h => M125.cpp} (92%) rename Marlin/src/gcode/feature/pause/{M600.h => M600.cpp} (92%) rename Marlin/src/gcode/sdcard/{M24.h => M24.cpp} (81%) diff --git a/Marlin/src/Marlin.cpp b/Marlin/src/Marlin.cpp index 3beaecf89..493ca9415 100644 --- a/Marlin/src/Marlin.cpp +++ b/Marlin/src/Marlin.cpp @@ -125,6 +125,9 @@ #include "feature/tmc2130.h" #endif +#if ENABLED(ADVANCED_PAUSE_FEATURE) && ENABLED(PAUSE_PARK_NO_STEPPER_TIMEOUT) + #include "feature/pause.h" +#endif bool Running = true; @@ -357,11 +360,6 @@ void suicide() { ***************** GCode Handlers ***************** **************************************************/ -#if ENABLED(ADVANCED_PAUSE_FEATURE) - // For M125, M600, M24 - #include "gcode/feature/pause/common.h" -#endif - #if ENABLED(SDSUPPORT) #include "gcode/sdcard/M20.h" // M20 - List SD card. (Requires SDSUPPORT) #include "gcode/sdcard/M21.h" // M21 - Init SD card. (Requires SDSUPPORT) @@ -508,10 +506,6 @@ static bool pin_is_protected(const int8_t pin) { #include "gcode/control/M120_M121.h" -#if ENABLED(PARK_HEAD_ON_PAUSE) - #include "gcode/feature/pause/M125.h" -#endif - #if HAS_COLOR_LEDS #include "gcode/feature/leds/M150.h" #endif @@ -612,10 +606,6 @@ void quickstop_stepper() { #include "gcode/config/M540.h" #endif -#if ENABLED(ADVANCED_PAUSE_FEATURE) - #include "gcode/feature/pause/M600.h" -#endif - #if ENABLED(MK2_MULTIPLEXER) #include "gcode/feature/snmm/M702.h" #endif diff --git a/Marlin/src/gcode/feature/pause/common.h b/Marlin/src/feature/pause.cpp similarity index 89% rename from Marlin/src/gcode/feature/pause/common.h rename to Marlin/src/feature/pause.cpp index b28213d44..ae538c65d 100644 --- a/Marlin/src/gcode/feature/pause/common.h +++ b/Marlin/src/feature/pause.cpp @@ -21,21 +21,34 @@ */ /** - * feature/pause/common.h - Merge this with its G-codes in the refactor + * feature/pause.cpp - Pause feature support functions + * This may be combined with related G-codes if features are consolidated. */ -#ifndef PAUSE_COMMON_H -#define PAUSE_COMMON_H +#include "../inc/MarlinConfig.h" -#if IS_KINEMATIC - #define RUNPLAN(RATE_MM_S) planner.buffer_line_kinematic(destination, RATE_MM_S, active_extruder) -#else - #define RUNPLAN(RATE_MM_S) line_to_destination(RATE_MM_S) +#if ENABLED(ADVANCED_PAUSE_FEATURE) || ENABLED(PARK_HEAD_ON_PAUSE) + +#include "../Marlin.h" +#include "../gcode/gcode.h" +#include "../module/motion.h" +#include "../module/planner.h" +#include "../module/stepper.h" +#include "../module/printcounter.h" +#include "../module/temperature.h" + +#if ENABLED(ULTIPANEL) + #include "../lcd/ultralcd.h" #endif +#include "../libs/buzzer.h" + +// private: + static float resume_position[XYZE]; -static bool move_away_flag = false; + #if ENABLED(SDSUPPORT) + #include "../sd/cardreader.h" static bool sd_print_paused = false; #endif @@ -74,8 +87,18 @@ static void ensure_safe_temperature() { } } -static bool pause_print(const float &retract, const float &z_lift, const float &x_pos, const float &y_pos, - const float &unload_length = 0 , const int8_t max_beep_count = 0, const bool show_lcd = false +// public: + +bool move_away_flag = false; + +#if IS_KINEMATIC + #define RUNPLAN(RATE_MM_S) planner.buffer_line_kinematic(destination, RATE_MM_S, active_extruder) +#else + #define RUNPLAN(RATE_MM_S) line_to_destination(RATE_MM_S) +#endif + +bool pause_print(const float &retract, const float &z_lift, const float &x_pos, const float &y_pos, + const float &unload_length/*=0*/ , const int8_t max_beep_count/*=0*/, const bool show_lcd/*=false*/ ) { if (move_away_flag) return false; // already paused @@ -172,7 +195,7 @@ static bool pause_print(const float &retract, const float &z_lift, const float & return true; } -static void wait_for_filament_reload(const int8_t max_beep_count = 0) { +void wait_for_filament_reload(const int8_t max_beep_count/*=0*/) { bool nozzle_timed_out = false; // Wait for filament insert by user and press button @@ -226,7 +249,7 @@ static void wait_for_filament_reload(const int8_t max_beep_count = 0) { KEEPALIVE_STATE(IN_HANDLER); } -static void resume_print(const float &load_length = 0, const float &initial_extrude_length = 0, const int8_t max_beep_count = 0) { +void resume_print(const float &load_length/*=0*/, const float &initial_extrude_length/*=0*/, const int8_t max_beep_count/*=0*/) { bool nozzle_timed_out = false; if (!move_away_flag) return; @@ -332,4 +355,4 @@ static void resume_print(const float &load_length = 0, const float &initial_extr move_away_flag = false; } -#endif // PAUSE_COMMON_H +#endif // ADVANCED_PAUSE_FEATURE || PARK_HEAD_ON_PAUSE diff --git a/Marlin/src/feature/pause.h b/Marlin/src/feature/pause.h new file mode 100644 index 000000000..80d994129 --- /dev/null +++ b/Marlin/src/feature/pause.h @@ -0,0 +1,41 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +/** + * feature/pause.h - Pause feature support functions + * This may be combined with related G-codes if features are consolidated. + */ + +#ifndef _PAUSE_H_ +#define _PAUSE_H_ + +extern bool move_away_flag; + +bool pause_print(const float &retract, const float &z_lift, const float &x_pos, const float &y_pos, + const float &unload_length=0 , const int8_t max_beep_count=0, const bool show_lcd=false +); + +void wait_for_filament_reload(const int8_t max_beep_count=0); + +void resume_print(const float &load_length=0, const float &initial_extrude_length=0, const int8_t max_beep_count=0); + +#endif // _PAUSE_H_ diff --git a/Marlin/src/gcode/feature/pause/M125.h b/Marlin/src/gcode/feature/pause/M125.cpp similarity index 92% rename from Marlin/src/gcode/feature/pause/M125.h rename to Marlin/src/gcode/feature/pause/M125.cpp index e9ed31c3e..347afa937 100644 --- a/Marlin/src/gcode/feature/pause/M125.h +++ b/Marlin/src/gcode/feature/pause/M125.cpp @@ -20,7 +20,13 @@ * */ -#include "common.h" +#include "../../../inc/MarlinConfig.h" + +#if ENABLED(PARK_HEAD_ON_PAUSE) + +#include "../../gcode.h" +#include "../../parser.h" +#include "../../../feature/pause.h" /** * M125: Store current position and move to filament change position. @@ -37,7 +43,7 @@ * Y = override Y * Z = override Z raise */ -void gcode_M125() { +void GcodeSuite::M125() { // Initial retract before move to filament change position const float retract = parser.seen('L') ? parser.value_axis_units(E_AXIS) : 0 @@ -87,3 +93,5 @@ void gcode_M125() { #endif } } + +#endif // PARK_HEAD_ON_PAUSE diff --git a/Marlin/src/gcode/feature/pause/M600.h b/Marlin/src/gcode/feature/pause/M600.cpp similarity index 92% rename from Marlin/src/gcode/feature/pause/M600.h rename to Marlin/src/gcode/feature/pause/M600.cpp index 6e47fb59d..144e0af63 100644 --- a/Marlin/src/gcode/feature/pause/M600.h +++ b/Marlin/src/gcode/feature/pause/M600.cpp @@ -20,7 +20,16 @@ * */ -#include "common.h" +#include "../../../inc/MarlinConfig.h" + +#if ENABLED(ADVANCED_PAUSE_FEATURE) + +#include "../../../feature/pause.h" + +#include "../../gcode.h" +#include "../../parser.h" + +#include "../../../module/printcounter.h" /** * M600: Pause for filament change @@ -36,7 +45,7 @@ * Default values are used for omitted arguments. * */ -void gcode_M600() { +void GcodeSuite::M600() { #if ENABLED(HOME_BEFORE_FILAMENT_CHANGE) // Don't allow filament change without homing first @@ -101,3 +110,5 @@ void gcode_M600() { // Resume the print job timer if it was running if (job_running) print_job_timer.start(); } + +#endif // ADVANCED_PAUSE_FEATURE diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp index 99bac95ec..e41444f0f 100644 --- a/Marlin/src/gcode/gcode.cpp +++ b/Marlin/src/gcode/gcode.cpp @@ -121,7 +121,6 @@ extern void gcode_M20(); extern void gcode_M21(); extern void gcode_M22(); extern void gcode_M23(); -extern void gcode_M24(); extern void gcode_M25(); extern void gcode_M26(); extern void gcode_M27(); @@ -212,7 +211,6 @@ extern void gcode_M501(); extern void gcode_M502(); extern void gcode_M503(); extern void gcode_M540(); -extern void gcode_M600(); extern void gcode_M605(); extern void gcode_M665(); extern void gcode_M666(); @@ -434,7 +432,7 @@ void GcodeSuite::process_next_command() { case 23: // M23: Select file gcode_M23(); break; case 24: // M24: Start SD print - gcode_M24(); break; + M24(); break; case 25: // M25: Pause SD print gcode_M25(); break; case 26: // M26: Set SD index @@ -570,7 +568,7 @@ void GcodeSuite::process_next_command() { #if ENABLED(PARK_HEAD_ON_PAUSE) case 125: // M125: Store current position and move to filament change position - gcode_M125(); break; + M125(); break; #endif #if ENABLED(BARICUDA) @@ -911,7 +909,7 @@ void GcodeSuite::process_next_command() { #if ENABLED(ADVANCED_PAUSE_FEATURE) case 600: // M600: Pause for filament change - gcode_M600(); + M600(); break; #endif // ADVANCED_PAUSE_FEATURE diff --git a/Marlin/src/gcode/sdcard/M24.h b/Marlin/src/gcode/sdcard/M24.cpp similarity index 81% rename from Marlin/src/gcode/sdcard/M24.h rename to Marlin/src/gcode/sdcard/M24.cpp index 7e5caf30b..b85b8864d 100644 --- a/Marlin/src/gcode/sdcard/M24.h +++ b/Marlin/src/gcode/sdcard/M24.cpp @@ -20,14 +20,22 @@ * */ +#include "../../inc/MarlinConfig.h" + +#if ENABLED(SDSUPPORT) + +#include "../gcode.h" +#include "../../sd/cardreader.h" +#include "../../module/printcounter.h" + #if ENABLED(PARK_HEAD_ON_PAUSE) - #include "../feature/pause/common.h" + #include "../../feature/pause.h" #endif /** * M24: Start or Resume SD Print */ -void gcode_M24() { +void GcodeSuite::M24() { #if ENABLED(PARK_HEAD_ON_PAUSE) resume_print(); #endif @@ -35,3 +43,5 @@ void gcode_M24() { card.startFileprint(); print_job_timer.start(); } + +#endif // SDSUPPORT