Skip to content

Commit

Permalink
Add MACHINE_COMMAND_MACROS
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Dec 19, 2020
1 parent 45b1155 commit 67d1caf
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,10 @@
*/
//#define SDCARD_CONNECTION LCD

// Emulate RepRapFirmware with macro files stored in /sys and /macros
// Provide the M98 command to run a macro file as a sub-program
//#define MACHINE_COMMAND_MACROS

#endif // SDSUPPORT

/**
Expand Down
49 changes: 49 additions & 0 deletions Marlin/src/gcode/sdcard/M98.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2019 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 <http://www.gnu.org/licenses/>.
*
*/

#include "../../inc/MarlinConfig.h"

#if ENABLED(MACHINE_COMMAND_MACROS)

#include "../gcode.h"
#include "../../sd/cardreader.h"

/**
* M98: Select file and run as sub-procedure
*
* P<path> - The plain (DOS 8.3) filepath
*
* Example:
* M98 P/macros/home.g ; Run home.g (as a procedure)
*
*/
void GcodeSuite::M98() {
if (card.isMounted() && parser.seen('P')) {
char *path = parser.value_string();
char *lb = strchr(p, ' ');
if (!lb) lb = strchr(p, ';');
if (lb) *lb = '\0';
card.runMacro(path);
}
}

#endif // MACHINE_COMMAND_MACROS
9 changes: 9 additions & 0 deletions Marlin/src/sd/cardreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,15 @@ bool CardReader::fileExists(const char * const path) {
return success;
}

#if ENABLED(MACHINE_COMMAND_MACROS)

void CardReader::runMacro(const char * const path) {
openFileRead(path, 2);
startFileprint();
}

#endif

//
// Delete a file by name in the working directory
//
Expand Down
4 changes: 4 additions & 0 deletions Marlin/src/sd/cardreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ class CardReader {
static bool fileExists(const char * const name);
static void removeFile(const char * const name);

#if ENABLED(MACHINE_COMMAND_MACROS)
static void runMacro(const char * const path);
#endif

static inline char* longest_filename() { return longFilename[0] ? longFilename : filename; }
#if ENABLED(LONG_FILENAME_HOST_SUPPORT)
static void printLongPath(char * const path); // Used by M33
Expand Down

0 comments on commit 67d1caf

Please sign in to comment.