GCODE_MACROS_IN_EEPROM (#28114)

This commit is contained in:
ellensp
2025-11-12 14:51:22 +13:00
committed by GitHub
parent 10009b018d
commit 579545177d
7 changed files with 61 additions and 14 deletions
+6 -2
View File
@@ -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
/**
+7 -5
View File
@@ -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 <command>|... 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
+4 -5
View File
@@ -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);
+4
View File
@@ -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;
+7 -1
View File
@@ -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
+32
View File
@@ -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
//
+1 -1
View File
@@ -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 \