diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index ffcecc3533..2e0f7f14fb 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -4091,13 +4091,17 @@ /** * G-code Macros * - * Add G-codes M810-M819 to define and run G-code macros. - * Macros are not saved to EEPROM. + * Add G-codes M810-M819 to define and run G-code macros + * and M820 to report the current set of macros. + * Macros are not saved to EEPROM unless enabled below. */ //#define GCODE_MACROS #if ENABLED(GCODE_MACROS) #define GCODE_MACROS_SLOTS 5 // Up to 10 may be used #define GCODE_MACROS_SLOT_SIZE 50 // Maximum length of a single macro + #if ENABLED(EEPROM_SETTINGS) + //#define GCODE_MACROS_IN_EEPROM // Include macros in EEPROM + #endif #endif /** diff --git a/Marlin/src/gcode/feature/macro/M810-M819.cpp b/Marlin/src/gcode/feature/macro/M810-M819.cpp index 7b9e1a13f1..29f6a11d14 100644 --- a/Marlin/src/gcode/feature/macro/M810-M819.cpp +++ b/Marlin/src/gcode/feature/macro/M810-M819.cpp @@ -28,10 +28,8 @@ #include "../../queue.h" #include "../../parser.h" -char gcode_macros[GCODE_MACROS_SLOTS][GCODE_MACROS_SLOT_SIZE + 1] = {{ 0 }}; - /** - * M810_819: Set/execute a G-code macro. + * M810 - M819: Set/execute a G-code macro. * * Usage: * M810 |... Set Macro 0 to the given commands, separated by the pipe character @@ -48,7 +46,7 @@ void GcodeSuite::M810_819() { if (len > GCODE_MACROS_SLOT_SIZE) SERIAL_ERROR_MSG("Macro too long."); else { - char c, *s = parser.string_arg, *d = gcode_macros[index]; + char c, *s = parser.string_arg, *d = gcode.macros[index]; do { c = *s++; *d++ = c == '|' ? '\n' : c; @@ -57,9 +55,13 @@ void GcodeSuite::M810_819() { } else { // Execute a macro - char * const cmd = gcode_macros[index]; + char * const cmd = gcode.macros[index]; if (strlen(cmd)) process_subcommands_now(cmd); } } +void GcodeSuite::M810_819_report(const bool forReplay/*=true*/) { + M820(forReplay); +} + #endif // GCODE_MACROS diff --git a/Marlin/src/gcode/feature/macro/M820.cpp b/Marlin/src/gcode/feature/macro/M820.cpp index 9759f482ec..5c6176d2aa 100644 --- a/Marlin/src/gcode/feature/macro/M820.cpp +++ b/Marlin/src/gcode/feature/macro/M820.cpp @@ -28,17 +28,16 @@ #include "../../queue.h" #include "../../parser.h" -extern char gcode_macros[GCODE_MACROS_SLOTS][GCODE_MACROS_SLOT_SIZE + 1]; - /** * M820: List defined M810 - M819 macros */ -void GcodeSuite::M820() { - SERIAL_ECHOLNPGM(STR_STORED_MACROS); +void GcodeSuite::M820(const bool withoutEcho/*=true*/) { + report_heading(withoutEcho, F(STR_STORED_MACROS)); bool some = false; for (uint8_t i = 0; i < GCODE_MACROS_SLOTS; ++i) { - const char *cmd = gcode_macros[i]; + const char *cmd = gcode.macros[i]; if (*cmd) { + report_echo_start(withoutEcho); SERIAL_ECHO(F("M81"), i, C(' ')); char c; while ((c = *cmd++)) SERIAL_CHAR(c == '\n' ? '|' : c); diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp index 373cc16a53..aa629f4a71 100644 --- a/Marlin/src/gcode/gcode.cpp +++ b/Marlin/src/gcode/gcode.cpp @@ -104,6 +104,10 @@ relative_t GcodeSuite::axis_relative; // Init in constructor xyz_pos_t GcodeSuite::coordinate_system[MAX_COORDINATE_SYSTEMS]; #endif +#if ENABLED(GCODE_MACROS) + char GcodeSuite::macros[GCODE_MACROS_SLOTS][GCODE_MACROS_SLOT_SIZE + 1] = {{ 0 }}; +#endif + void GcodeSuite::report_echo_start(const bool forReplay) { if (!forReplay) SERIAL_ECHO_START(); } void GcodeSuite::report_heading(const bool forReplay, FSTR_P const fstr, const bool eol/*=true*/) { if (forReplay) return; diff --git a/Marlin/src/gcode/gcode.h b/Marlin/src/gcode/gcode.h index a0f3f68f6f..9b48813732 100644 --- a/Marlin/src/gcode/gcode.h +++ b/Marlin/src/gcode/gcode.h @@ -510,6 +510,11 @@ public: static void dwell(const millis_t time); + #if ENABLED(GCODE_MACROS) + static char macros[GCODE_MACROS_SLOTS][GCODE_MACROS_SLOT_SIZE + 1]; + static void reset_macros() { for (uint8_t i = 0; i < GCODE_MACROS_SLOTS; ++i) macros[i][0] = '\0'; } + #endif + private: friend class MarlinSettings; @@ -1229,7 +1234,8 @@ private: #if ENABLED(GCODE_MACROS) static void M810_819(); - static void M820(); + static void M810_819_report(const bool forReplay=true); + static void M820(const bool withoutEcho=true); #endif #if HAS_BED_PROBE diff --git a/Marlin/src/module/settings.cpp b/Marlin/src/module/settings.cpp index 7ebcb63eb1..caddd8129c 100644 --- a/Marlin/src/module/settings.cpp +++ b/Marlin/src/module/settings.cpp @@ -705,6 +705,13 @@ typedef struct SettingsDataStruct { // uint32_t material_changes #endif + // + // GCODE_MACROS + // + #if ENABLED(GCODE_MACROS_EEPROM) + char gcode_macros[GCODE_MACROS_SLOTS][GCODE_MACROS_SLOT_SIZE + 1]; + #endif + } SettingsData; //static_assert(sizeof(SettingsData) <= MARLIN_EEPROM_SIZE, "EEPROM too small to contain SettingsData!"); @@ -1823,6 +1830,14 @@ void MarlinSettings::postprocess() { EEPROM_WRITE(mmu3.mmu_hw_enabled); // EEPROM_MMU_ENABLED #endif + // + // GCODE_MACROS + // + #if ENABLED(GCODE_MACROS_EEPROM) + _FIELD_TEST(gcode_macros); + EEPROM_WRITE(gcode.macros); + #endif + // // Report final CRC and Data Size // @@ -2981,6 +2996,13 @@ void MarlinSettings::postprocess() { EEPROM_READ(mmu3.mmu_hw_enabled); // EEPROM_MMU_ENABLED #endif + // + // GCODE_MACROS + // + #if ENABLED(GCODE_MACROS_EEPROM) + EEPROM_READ(gcode.macros); + #endif + // // Validate Final Size and CRC // @@ -3800,6 +3822,11 @@ void MarlinSettings::reset() { mmu3.mmu_hw_enabled = true; #endif + // + // G-code Macros + // + TERN_(GCODE_MACROS_EEPROM, gcode.reset_macros()); + // // Hotend Idle Timeout // @@ -4035,6 +4062,11 @@ void MarlinSettings::reset() { // TERN_(EDITABLE_HOMING_FEEDRATE, gcode.M210_report(forReplay)); + // + // G-Code Macros + // + TERN_(GCODE_MACROS, gcode.M810_819_report(forReplay)); + // // Probe Offset // diff --git a/buildroot/tests/DUE b/buildroot/tests/DUE index 448da6f9d4..d5fcf2e4cb 100755 --- a/buildroot/tests/DUE +++ b/buildroot/tests/DUE @@ -15,7 +15,7 @@ opt_set MOTHERBOARD BOARD_RAMPS4DUE_EFB \ TEMP_SENSOR_CHAMBER 3 TEMP_CHAMBER_PIN 6 HEATER_CHAMBER_PIN 45 \ BACKLASH_MEASUREMENT_FEEDRATE 600 \ TRAMMING_POINT_XY '{{20,20},{20,20},{20,20},{20,20},{20,20}}' TRAMMING_POINT_NAME_5 '"Point 5"' -opt_enable S_CURVE_ACCELERATION EEPROM_SETTINGS GCODE_MACROS \ +opt_enable S_CURVE_ACCELERATION EEPROM_SETTINGS GCODE_MACROS GCODE_MACROS_IN_EEPROM \ FIX_MOUNTED_PROBE Z_SAFE_HOMING CODEPENDENT_XY_HOMING \ ASSISTED_TRAMMING REPORT_TRAMMING_MM ASSISTED_TRAMMING_WAIT_POSITION \ EEPROM_SETTINGS SDSUPPORT BINARY_FILE_TRANSFER \