From a442c34a1ad1a181238fddfd0a52a922de9a643c Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 16 Sep 2017 03:24:47 -0500 Subject: [PATCH] Move SD commands to cpp --- Marlin/src/Marlin.cpp | 25 -------- Marlin/src/gcode/gcode.cpp | 62 +++++--------------- Marlin/src/gcode/sdcard/{M20.h => M20.cpp} | 11 +++- Marlin/src/gcode/sdcard/{M21.h => M21.cpp} | 11 +++- Marlin/src/gcode/sdcard/{M22.h => M22.cpp} | 11 +++- Marlin/src/gcode/sdcard/{M23.h => M23.cpp} | 11 +++- Marlin/src/gcode/sdcard/{M25.h => M25.cpp} | 16 ++++- Marlin/src/gcode/sdcard/{M26.h => M26.cpp} | 11 +++- Marlin/src/gcode/sdcard/{M27.h => M27.cpp} | 11 +++- Marlin/src/gcode/sdcard/{M28.h => M28.cpp} | 11 +++- Marlin/src/gcode/sdcard/{M29.h => M29.cpp} | 11 +++- Marlin/src/gcode/sdcard/{M30.h => M30.cpp} | 11 +++- Marlin/src/gcode/sdcard/{M32.h => M32.cpp} | 13 +++- Marlin/src/gcode/sdcard/{M33.h => M33.cpp} | 11 +++- Marlin/src/gcode/sdcard/{M34.h => M34.cpp} | 11 +++- Marlin/src/gcode/sdcard/{M928.h => M928.cpp} | 11 +++- 16 files changed, 163 insertions(+), 85 deletions(-) rename Marlin/src/gcode/sdcard/{M20.h => M20.cpp} (86%) rename Marlin/src/gcode/sdcard/{M21.h => M21.cpp} (83%) rename Marlin/src/gcode/sdcard/{M22.h => M22.cpp} (83%) rename Marlin/src/gcode/sdcard/{M23.h => M23.cpp} (86%) rename Marlin/src/gcode/sdcard/{M25.h => M25.cpp} (80%) rename Marlin/src/gcode/sdcard/{M26.h => M26.cpp} (85%) rename Marlin/src/gcode/sdcard/{M27.h => M27.cpp} (83%) rename Marlin/src/gcode/sdcard/{M28.h => M28.cpp} (81%) rename Marlin/src/gcode/sdcard/{M29.h => M29.cpp} (85%) rename Marlin/src/gcode/sdcard/{M30.h => M30.cpp} (85%) rename Marlin/src/gcode/sdcard/{M32.h => M32.cpp} (84%) rename Marlin/src/gcode/sdcard/{M33.h => M33.cpp} (83%) rename Marlin/src/gcode/sdcard/{M34.h => M34.cpp} (82%) rename Marlin/src/gcode/sdcard/{M928.h => M928.cpp} (85%) diff --git a/Marlin/src/Marlin.cpp b/Marlin/src/Marlin.cpp index 493ca94153..65cafbcc30 100644 --- a/Marlin/src/Marlin.cpp +++ b/Marlin/src/Marlin.cpp @@ -360,33 +360,8 @@ void suicide() { ***************** GCode Handlers ***************** **************************************************/ -#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) - #include "gcode/sdcard/M22.h" // M22 - Release SD card. (Requires SDSUPPORT) - #include "gcode/sdcard/M23.h" // M23 - Select SD file: "M23 /path/file.gco". (Requires SDSUPPORT) - #include "gcode/sdcard/M24.h" // M24 - Start/resume SD print. (Requires SDSUPPORT) - #include "gcode/sdcard/M25.h" // M25 - Pause SD print. (Requires SDSUPPORT) - #include "gcode/sdcard/M26.h" // M26 - Set SD position in bytes: "M26 S12345". (Requires SDSUPPORT) - #include "gcode/sdcard/M27.h" // M27 - Report SD print status. (Requires SDSUPPORT) - #include "gcode/sdcard/M28.h" // M28 - Start SD write: "M28 /path/file.gco". (Requires SDSUPPORT) - #include "gcode/sdcard/M29.h" // M29 - Stop SD write. (Requires SDSUPPORT) - #include "gcode/sdcard/M30.h" // M30 - Delete file from SD: "M30 /path/file.gco" -#endif - #include "gcode/stats/M31.h" // M31: Get the time since the start of SD Print (or last M109) -#if ENABLED(SDSUPPORT) - #include "gcode/sdcard/M32.h" - #if ENABLED(LONG_FILENAME_HOST_SUPPORT) - #include "gcode/sdcard/M33.h" - #endif - #if ENABLED(SDCARD_SORT_ALPHA) && ENABLED(SDSORT_GCODE) - #include "gcode/sdcard/M34.h" - #endif - #include "gcode/sdcard/M928.h" -#endif - /** * Sensitive pin test for M42, M226 */ diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp index e41444f0f2..799a5df58a 100644 --- a/Marlin/src/gcode/gcode.cpp +++ b/Marlin/src/gcode/gcode.cpp @@ -117,20 +117,7 @@ void GcodeSuite::dwell(millis_t time) { // Placeholders for non-migrated codes // extern void gcode_M18_M84(); -extern void gcode_M20(); -extern void gcode_M21(); -extern void gcode_M22(); -extern void gcode_M23(); -extern void gcode_M25(); -extern void gcode_M26(); -extern void gcode_M27(); -extern void gcode_M28(); -extern void gcode_M29(); -extern void gcode_M30(); extern void gcode_M31(); -extern void gcode_M32(); -extern void gcode_M33(); -extern void gcode_M34(); extern void gcode_M42(); extern void gcode_M43(); extern void gcode_M48(); @@ -160,7 +147,6 @@ extern void gcode_M118(); extern void gcode_M119(); extern void gcode_M120(); extern void gcode_M121(); -extern void gcode_M125(); extern void gcode_M126(); extern void gcode_M127(); extern void gcode_M128(); @@ -225,7 +211,6 @@ extern void gcode_M907(); extern void gcode_M908(); extern void gcode_M909(); extern void gcode_M910(); -extern void gcode_M928(); extern void gcode_M999(); extern void gcode_T(uint8_t tmp_extruder); @@ -423,43 +408,28 @@ void GcodeSuite::process_next_command() { break; #if ENABLED(SDSUPPORT) - case 20: // M20: list SD card - gcode_M20(); break; - case 21: // M21: init SD card - gcode_M21(); break; - case 22: // M22: release SD card - gcode_M22(); break; - case 23: // M23: Select file - gcode_M23(); break; - case 24: // M24: Start SD print - M24(); break; - case 25: // M25: Pause SD print - gcode_M25(); break; - case 26: // M26: Set SD index - gcode_M26(); break; - case 27: // M27: Get SD status - gcode_M27(); break; - case 28: // M28: Start SD write - gcode_M28(); break; - case 29: // M29: Stop SD write - gcode_M29(); break; - case 30: // M30 Delete File - gcode_M30(); break; - case 32: // M32: Select file and start SD print - gcode_M32(); break; + case 20: M20(); break; // M20: list SD card + case 21: M21(); break; // M21: init SD card + case 22: M22(); break; // M22: release SD card + case 23: M23(); break; // M23: Select file + case 24: M24(); break; // M24: Start SD print + case 25: M25(); break; // M25: Pause SD print + case 26: M26(); break; // M26: Set SD index + case 27: M27(); break; // M27: Get SD status + case 28: M28(); break; // M28: Start SD write + case 29: M29(); break; // M29: Stop SD write + case 30: M30(); break; // M30 Delete File + case 32: M32(); break; // M32: Select file and start SD print #if ENABLED(LONG_FILENAME_HOST_SUPPORT) - case 33: // M33: Get the long full path to a file or folder - gcode_M33(); break; + case 33: M33(); break; // M33: Get the long full path to a file or folder #endif #if ENABLED(SDCARD_SORT_ALPHA) && ENABLED(SDSORT_GCODE) - case 34: // M34: Set SD card sorting options - gcode_M34(); break; - #endif // SDCARD_SORT_ALPHA && SDSORT_GCODE + case 34: M34(); break; // M34: Set SD card sorting options + #endif - case 928: // M928: Start SD write - gcode_M928(); break; + case 928: M928(); break; // M928: Start SD write #endif // SDSUPPORT case 31: // M31: Report time since the start of SD print or last M109 diff --git a/Marlin/src/gcode/sdcard/M20.h b/Marlin/src/gcode/sdcard/M20.cpp similarity index 86% rename from Marlin/src/gcode/sdcard/M20.h rename to Marlin/src/gcode/sdcard/M20.cpp index 89b2d6d448..a5916f5292 100644 --- a/Marlin/src/gcode/sdcard/M20.h +++ b/Marlin/src/gcode/sdcard/M20.cpp @@ -20,11 +20,20 @@ * */ +#include "../../inc/MarlinConfig.h" + +#if ENABLED(SDSUPPORT) + +#include "../gcode.h" +#include "../../sd/cardreader.h" + /** * M20: List SD card to serial output */ -void gcode_M20() { +void GcodeSuite::M20() { SERIAL_PROTOCOLLNPGM(MSG_BEGIN_FILE_LIST); card.ls(); SERIAL_PROTOCOLLNPGM(MSG_END_FILE_LIST); } + +#endif // SDSUPPORT diff --git a/Marlin/src/gcode/sdcard/M21.h b/Marlin/src/gcode/sdcard/M21.cpp similarity index 83% rename from Marlin/src/gcode/sdcard/M21.h rename to Marlin/src/gcode/sdcard/M21.cpp index 3812bca034..90bf3372a0 100644 --- a/Marlin/src/gcode/sdcard/M21.h +++ b/Marlin/src/gcode/sdcard/M21.cpp @@ -20,7 +20,16 @@ * */ +#include "../../inc/MarlinConfig.h" + +#if ENABLED(SDSUPPORT) + +#include "../gcode.h" +#include "../../sd/cardreader.h" + /** * M21: Init SD Card */ -void gcode_M21() { card.initsd(); } +void GcodeSuite::M21() { card.initsd(); } + +#endif // SDSUPPORT diff --git a/Marlin/src/gcode/sdcard/M22.h b/Marlin/src/gcode/sdcard/M22.cpp similarity index 83% rename from Marlin/src/gcode/sdcard/M22.h rename to Marlin/src/gcode/sdcard/M22.cpp index 3a8848829b..afb665ae64 100644 --- a/Marlin/src/gcode/sdcard/M22.h +++ b/Marlin/src/gcode/sdcard/M22.cpp @@ -20,7 +20,16 @@ * */ +#include "../../inc/MarlinConfig.h" + +#if ENABLED(SDSUPPORT) + +#include "../gcode.h" +#include "../../sd/cardreader.h" + /** * M22: Release SD Card */ -void gcode_M22() { card.release(); } +void GcodeSuite::M22() { card.release(); } + +#endif // SDSUPPORT diff --git a/Marlin/src/gcode/sdcard/M23.h b/Marlin/src/gcode/sdcard/M23.cpp similarity index 86% rename from Marlin/src/gcode/sdcard/M23.h rename to Marlin/src/gcode/sdcard/M23.cpp index 46059e2d4f..41211e988a 100644 --- a/Marlin/src/gcode/sdcard/M23.h +++ b/Marlin/src/gcode/sdcard/M23.cpp @@ -20,11 +20,20 @@ * */ +#include "../../inc/MarlinConfig.h" + +#if ENABLED(SDSUPPORT) + +#include "../gcode.h" +#include "../../sd/cardreader.h" + /** * M23: Open a file */ -void gcode_M23() { +void GcodeSuite::M23() { // Simplify3D includes the size, so zero out all spaces (#7227) for (char *fn = parser.string_arg; *fn; ++fn) if (*fn == ' ') *fn = '\0'; card.openFile(parser.string_arg, true); } + +#endif // SDSUPPORT diff --git a/Marlin/src/gcode/sdcard/M25.h b/Marlin/src/gcode/sdcard/M25.cpp similarity index 80% rename from Marlin/src/gcode/sdcard/M25.h rename to Marlin/src/gcode/sdcard/M25.cpp index 7f466ad92f..8de3364215 100644 --- a/Marlin/src/gcode/sdcard/M25.h +++ b/Marlin/src/gcode/sdcard/M25.cpp @@ -20,10 +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 "../queue.h" +#endif + /** * M25: Pause SD Print */ -void gcode_M25() { +void GcodeSuite::M25() { card.pauseSDPrint(); print_job_timer.pause(); @@ -31,3 +43,5 @@ void gcode_M25() { enqueue_and_echo_commands_P(PSTR("M125")); // Must be enqueued with pauseSDPrint set to be last in the buffer #endif } + +#endif // SDSUPPORT diff --git a/Marlin/src/gcode/sdcard/M26.h b/Marlin/src/gcode/sdcard/M26.cpp similarity index 85% rename from Marlin/src/gcode/sdcard/M26.h rename to Marlin/src/gcode/sdcard/M26.cpp index a3eaf6121b..5efbeb393c 100644 --- a/Marlin/src/gcode/sdcard/M26.h +++ b/Marlin/src/gcode/sdcard/M26.cpp @@ -20,10 +20,19 @@ * */ +#include "../../inc/MarlinConfig.h" + +#if ENABLED(SDSUPPORT) + +#include "../gcode.h" +#include "../../sd/cardreader.h" + /** * M26: Set SD Card file index */ -void gcode_M26() { +void GcodeSuite::M26() { if (card.cardOK && parser.seenval('S')) card.setIndex(parser.value_long()); } + +#endif // SDSUPPORT diff --git a/Marlin/src/gcode/sdcard/M27.h b/Marlin/src/gcode/sdcard/M27.cpp similarity index 83% rename from Marlin/src/gcode/sdcard/M27.h rename to Marlin/src/gcode/sdcard/M27.cpp index 6825e8466b..439b976000 100644 --- a/Marlin/src/gcode/sdcard/M27.h +++ b/Marlin/src/gcode/sdcard/M27.cpp @@ -20,7 +20,16 @@ * */ +#include "../../inc/MarlinConfig.h" + +#if ENABLED(SDSUPPORT) + +#include "../gcode.h" +#include "../../sd/cardreader.h" + /** * M27: Get SD Card status */ -void gcode_M27() { card.getStatus(); } +void GcodeSuite::M27() { card.getStatus(); } + +#endif // SDSUPPORT diff --git a/Marlin/src/gcode/sdcard/M28.h b/Marlin/src/gcode/sdcard/M28.cpp similarity index 81% rename from Marlin/src/gcode/sdcard/M28.h rename to Marlin/src/gcode/sdcard/M28.cpp index 5e8689f438..82200e83ab 100644 --- a/Marlin/src/gcode/sdcard/M28.h +++ b/Marlin/src/gcode/sdcard/M28.cpp @@ -20,7 +20,16 @@ * */ +#include "../../inc/MarlinConfig.h" + +#if ENABLED(SDSUPPORT) + +#include "../gcode.h" +#include "../../sd/cardreader.h" + /** * M28: Start SD Write */ -void gcode_M28() { card.openFile(parser.string_arg, false); } +void GcodeSuite::M28() { card.openFile(parser.string_arg, false); } + +#endif // SDSUPPORT diff --git a/Marlin/src/gcode/sdcard/M29.h b/Marlin/src/gcode/sdcard/M29.cpp similarity index 85% rename from Marlin/src/gcode/sdcard/M29.h rename to Marlin/src/gcode/sdcard/M29.cpp index 341640981c..c5e2081cd3 100644 --- a/Marlin/src/gcode/sdcard/M29.h +++ b/Marlin/src/gcode/sdcard/M29.cpp @@ -20,10 +20,19 @@ * */ +#include "../../inc/MarlinConfig.h" + +#if ENABLED(SDSUPPORT) + +#include "../gcode.h" +#include "../../sd/cardreader.h" + /** * M29: Stop SD Write * Processed in write to file routine above */ -void gcode_M29() { +void GcodeSuite::M29() { // card.saving = false; } + +#endif // SDSUPPORT diff --git a/Marlin/src/gcode/sdcard/M30.h b/Marlin/src/gcode/sdcard/M30.cpp similarity index 85% rename from Marlin/src/gcode/sdcard/M30.h rename to Marlin/src/gcode/sdcard/M30.cpp index 5d584a39b4..94335fe0f5 100644 --- a/Marlin/src/gcode/sdcard/M30.h +++ b/Marlin/src/gcode/sdcard/M30.cpp @@ -20,12 +20,21 @@ * */ +#include "../../inc/MarlinConfig.h" + +#if ENABLED(SDSUPPORT) + +#include "../gcode.h" +#include "../../sd/cardreader.h" + /** * M30 : Delete SD Card file */ -void gcode_M30() { +void GcodeSuite::M30() { if (card.cardOK) { card.closefile(); card.removeFile(parser.string_arg); } } + +#endif // SDSUPPORT diff --git a/Marlin/src/gcode/sdcard/M32.h b/Marlin/src/gcode/sdcard/M32.cpp similarity index 84% rename from Marlin/src/gcode/sdcard/M32.h rename to Marlin/src/gcode/sdcard/M32.cpp index 5938d8c5d7..de864f9cb3 100644 --- a/Marlin/src/gcode/sdcard/M32.h +++ b/Marlin/src/gcode/sdcard/M32.cpp @@ -20,10 +20,19 @@ * */ +#include "../../inc/MarlinConfig.h" + +#if ENABLED(SDSUPPORT) + +#include "../gcode.h" +#include "../../sd/cardreader.h" +#include "../../module/stepper.h" +#include "../../module/printcounter.h" + /** * M32: Select file and start SD Print */ -void gcode_M32() { +void GcodeSuite::M32() { if (IS_SD_PRINTING) stepper.synchronize(); @@ -42,3 +51,5 @@ void gcode_M32() { if (!call_procedure) print_job_timer.start(); } } + +#endif // SDSUPPORT diff --git a/Marlin/src/gcode/sdcard/M33.h b/Marlin/src/gcode/sdcard/M33.cpp similarity index 83% rename from Marlin/src/gcode/sdcard/M33.h rename to Marlin/src/gcode/sdcard/M33.cpp index 2380c9f532..69933df999 100644 --- a/Marlin/src/gcode/sdcard/M33.h +++ b/Marlin/src/gcode/sdcard/M33.cpp @@ -20,6 +20,13 @@ * */ +#include "../../inc/MarlinConfig.h" + +#if ENABLED(SDSUPPORT) && ENABLED(LONG_FILENAME_HOST_SUPPORT) + +#include "../gcode.h" +#include "../../sd/cardreader.h" + /** * M33: Get the long full path of a file or folder * @@ -32,6 +39,8 @@ * Output: * /Miscellaneous/Armchair/Armchair.gcode */ -void gcode_M33() { +void GcodeSuite::M33() { card.printLongPath(parser.string_arg); } + +#endif // SDSUPPORT && LONG_FILENAME_HOST_SUPPORT diff --git a/Marlin/src/gcode/sdcard/M34.h b/Marlin/src/gcode/sdcard/M34.cpp similarity index 82% rename from Marlin/src/gcode/sdcard/M34.h rename to Marlin/src/gcode/sdcard/M34.cpp index 189eaa2da9..911539d408 100644 --- a/Marlin/src/gcode/sdcard/M34.h +++ b/Marlin/src/gcode/sdcard/M34.cpp @@ -20,10 +20,17 @@ * */ +#include "../../inc/MarlinConfig.h" + +#if ENABLED(SDSUPPORT) && ENABLED(SDCARD_SORT_ALPHA) && ENABLED(SDSORT_GCODE) + +#include "../gcode.h" +#include "../../sd/cardreader.h" + /** * M34: Set SD Card Sorting Options */ -void gcode_M34() { +void GcodeSuite::M34() { if (parser.seen('S')) card.setSortOn(parser.value_bool()); if (parser.seenval('F')) { const int v = parser.value_long(); @@ -31,3 +38,5 @@ void gcode_M34() { } //if (parser.seen('R')) card.setSortReverse(parser.value_bool()); } + +#endif // SDSUPPORT && SDCARD_SORT_ALPHA && SDSORT_GCODE diff --git a/Marlin/src/gcode/sdcard/M928.h b/Marlin/src/gcode/sdcard/M928.cpp similarity index 85% rename from Marlin/src/gcode/sdcard/M928.h rename to Marlin/src/gcode/sdcard/M928.cpp index 41c83fe9f1..069448f0b9 100644 --- a/Marlin/src/gcode/sdcard/M928.h +++ b/Marlin/src/gcode/sdcard/M928.cpp @@ -20,9 +20,18 @@ * */ +#include "../../inc/MarlinConfig.h" + +#if ENABLED(SDSUPPORT) + +#include "../gcode.h" +#include "../../sd/cardreader.h" + /** * M928: Start SD Write */ -void gcode_M928() { +void GcodeSuite::M928() { card.openLogFile(parser.string_arg); } + +#endif // SDSUPPORT