From 1fb9b299d4d96276ff1fb6cd2ee5e73e753e2b23 Mon Sep 17 00:00:00 2001 From: TheSFReader Date: Fri, 19 Oct 2018 21:25:07 +0200 Subject: [PATCH] Add M524 to abort SD printing (#12155) --- Marlin/src/Marlin.cpp | 9 +++------ Marlin/src/gcode/gcode.cpp | 4 ++++ Marlin/src/gcode/gcode.h | 5 +++++ ...30_M32-M34_M928.cpp => M20-M30_M32-M34_M524_M928.cpp} | 7 +++++++ Marlin/src/lcd/extensible_ui/ui_api.cpp | 6 +----- Marlin/src/lcd/ultralcd.cpp | 4 +--- Marlin/src/lcd/ultralcd.h | 5 ----- Marlin/src/sd/cardreader.cpp | 2 +- Marlin/src/sd/cardreader.h | 2 +- 9 files changed, 23 insertions(+), 21 deletions(-) rename Marlin/src/gcode/sdcard/{M20-M30_M32-M34_M928.cpp => M20-M30_M32-M34_M524_M928.cpp} (97%) diff --git a/Marlin/src/Marlin.cpp b/Marlin/src/Marlin.cpp index cc755d4cf0..4abdf4f9a2 100644 --- a/Marlin/src/Marlin.cpp +++ b/Marlin/src/Marlin.cpp @@ -972,11 +972,8 @@ void loop() { #if ENABLED(SDSUPPORT) card.checkautostart(); - #endif - - #if ENABLED(SDSUPPORT) && (ENABLED(ULTIPANEL) || ENABLED(EXTENSIBLE_UI)) - if (abort_sd_printing) { - abort_sd_printing = false; + + if (card.abort_sd_printing) { card.stopSDPrint( #if SD_RESORT true @@ -992,7 +989,7 @@ void loop() { card.removeJobRecoveryFile(); #endif } - #endif // SDSUPPORT && (ENABLED(ULTIPANEL) || ENABLED(EXTENSIBLE_UI)) + #endif // SDSUPPORT if (commands_in_queue < BUFSIZE) get_available_commands(); advance_command_queue(); diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp index 4de056de7a..17d7d51dd3 100644 --- a/Marlin/src/gcode/gcode.cpp +++ b/Marlin/src/gcode/gcode.cpp @@ -584,6 +584,10 @@ void GcodeSuite::process_parsed_command( case 504: M504(); break; // M504: Validate EEPROM contents #endif + #if ENABLED(SDSUPPORT) + case 524: M524(); break; // M524: Abort the current SD print job + #endif + #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) case 540: M540(); break; // M540: Set abort on endstop hit for SD printing #endif diff --git a/Marlin/src/gcode/gcode.h b/Marlin/src/gcode/gcode.h index 8a8a9b0076..560cf2e122 100644 --- a/Marlin/src/gcode/gcode.h +++ b/Marlin/src/gcode/gcode.h @@ -202,6 +202,7 @@ * M501 - Restore parameters from EEPROM. (Requires EEPROM_SETTINGS) * M502 - Revert to the default "factory settings". ** Does not write them to EEPROM! ** * M503 - Print the current settings (in memory): "M503 S". S0 specifies compact output. + * M524 - Abort the current SD print job (started with M24) * M540 - Enable/disable SD card abort on endstop hit: "M540 S". (Requires ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) * M600 - Pause for filament change: "M600 X Y Z E L". (Requires ADVANCED_PAUSE_FEATURE) * M603 - Configure filament change: "M603 T U L". (Requires ADVANCED_PAUSE_FEATURE) @@ -719,6 +720,10 @@ private: static void M504(); #endif + #if ENABLED(SDSUPPORT) + static void M524(); + #endif + #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) static void M540(); #endif diff --git a/Marlin/src/gcode/sdcard/M20-M30_M32-M34_M928.cpp b/Marlin/src/gcode/sdcard/M20-M30_M32-M34_M524_M928.cpp similarity index 97% rename from Marlin/src/gcode/sdcard/M20-M30_M32-M34_M928.cpp rename to Marlin/src/gcode/sdcard/M20-M30_M32-M34_M524_M928.cpp index 6a982b74b0..81cca4c0d3 100644 --- a/Marlin/src/gcode/sdcard/M20-M30_M32-M34_M928.cpp +++ b/Marlin/src/gcode/sdcard/M20-M30_M32-M34_M524_M928.cpp @@ -244,6 +244,13 @@ void GcodeSuite::M32() { #endif // SDCARD_SORT_ALPHA && SDSORT_GCODE +/** + * M524: Abort the current SD print job (started with M24) + */ +void GcodeSuite::M524() { + if (IS_SD_PRINTING()) card.abort_sd_printing = true; +} + /** * M928: Start SD Write */ diff --git a/Marlin/src/lcd/extensible_ui/ui_api.cpp b/Marlin/src/lcd/extensible_ui/ui_api.cpp index e13ca08758..47b635f54f 100644 --- a/Marlin/src/lcd/extensible_ui/ui_api.cpp +++ b/Marlin/src/lcd/extensible_ui/ui_api.cpp @@ -37,10 +37,6 @@ #if ENABLED(SDSUPPORT) #include "../../sd/cardreader.h" #include "../../feature/emergency_parser.h" - - bool abort_sd_printing; // =false -#else - constexpr bool abort_sd_printing = false; #endif #if ENABLED(PRINTCOUNTER) @@ -476,7 +472,7 @@ namespace UI { void stopPrint() { #if ENABLED(SDSUPPORT) wait_for_heatup = wait_for_user = false; - abort_sd_printing = true; + card.abort_sd_printing = true; UI::onStatusChanged(PSTR(MSG_PRINT_ABORTED)); #endif } diff --git a/Marlin/src/lcd/ultralcd.cpp b/Marlin/src/lcd/ultralcd.cpp index 85a2180bb1..8da41adbb4 100644 --- a/Marlin/src/lcd/ultralcd.cpp +++ b/Marlin/src/lcd/ultralcd.cpp @@ -895,11 +895,9 @@ void lcd_quick_feedback(const bool clear_buttons) { lcd_reset_status(); } - bool abort_sd_printing; // =false - void lcd_sdcard_stop() { wait_for_heatup = wait_for_user = false; - abort_sd_printing = true; + card.abort_sd_printing = true; lcd_setstatusPGM(PSTR(MSG_PRINT_ABORTED), -1); lcd_return_to_status(); } diff --git a/Marlin/src/lcd/ultralcd.h b/Marlin/src/lcd/ultralcd.h index 2b262f6af1..b1d9490ecf 100644 --- a/Marlin/src/lcd/ultralcd.h +++ b/Marlin/src/lcd/ultralcd.h @@ -288,10 +288,5 @@ void lcd_reselect_last_file(); #endif -#if (ENABLED(EXTENSIBLE_UI) || ENABLED(ULTIPANEL)) && ENABLED(SDSUPPORT) - extern bool abort_sd_printing; -#else - constexpr bool abort_sd_printing = false; -#endif #endif // ULTRALCD_H diff --git a/Marlin/src/sd/cardreader.cpp b/Marlin/src/sd/cardreader.cpp index 68ebe99d4a..91a3a8d04c 100644 --- a/Marlin/src/sd/cardreader.cpp +++ b/Marlin/src/sd/cardreader.cpp @@ -351,7 +351,7 @@ void CardReader::stopSDPrint( #if ENABLED(ADVANCED_PAUSE_FEATURE) did_pause_print = 0; #endif - sdprinting = false; + sdprinting = abort_sd_printing = false; if (isFileOpen()) file.close(); #if SD_RESORT if (re_sort) presort(); diff --git a/Marlin/src/sd/cardreader.h b/Marlin/src/sd/cardreader.h index 42e35656fb..a92196f986 100644 --- a/Marlin/src/sd/cardreader.h +++ b/Marlin/src/sd/cardreader.h @@ -149,7 +149,7 @@ public: FORCE_INLINE char* longest_filename() { return longFilename[0] ? longFilename : filename; } public: - bool saving, logging, sdprinting, cardOK, filenameIsDir; + bool saving, logging, sdprinting, cardOK, filenameIsDir, abort_sd_printing; char filename[FILENAME_LENGTH], longFilename[LONG_FILENAME_LENGTH]; int8_t autostart_index; private: