Skip to content

Commit 7ff91bc

Browse files
committed
✨ M550 CONFIGURABLE_MACHINE_NAME
1 parent 07b9790 commit 7ff91bc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+298
-157
lines changed

Marlin/Configuration.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129

130130
// Name displayed in the LCD "Ready" message and Info menu
131131
//#define CUSTOM_MACHINE_NAME "3D Printer"
132+
//#define CONFIGURABLE_MACHINE_NAME // Add G-code M550 to set/report the machine name
132133

133134
// Printer's unique ID, used by some programs to differentiate between machines.
134135
// Choose your own or use a service like https://www.uuidgenerator.net/version4

Marlin/Configuration_adv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2227,7 +2227,7 @@
22272227

22282228
// Developer menu (accessed by touching "About Printer" copyright text)
22292229
//#define TOUCH_UI_DEVELOPER_MENU
2230-
#endif
2230+
#endif // TOUCH_UI_FTDI_EVE
22312231

22322232
//
22332233
// Classic UI Options

Marlin/src/MarlinCore.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@
271271

272272
PGMSTR(M112_KILL_STR, "M112 Shutdown");
273273

274+
#if ENABLED(CONFIGURABLE_MACHINE_NAME)
275+
MString<64> machine_name;
276+
#endif
277+
274278
MarlinState marlin_state = MarlinState::MF_INITIALIZING;
275279

276280
// For M109 and M190, this flag may be cleared (by M108) to exit the wait loop
@@ -1363,6 +1367,10 @@ void setup() {
13631367
SETUP_RUN(settings.first_load()); // Load data from EEPROM if available (or use defaults)
13641368
// This also updates variables in the planner, elsewhere
13651369

1370+
#if ENABLED(CONFIGURABLE_MACHINE_NAME)
1371+
SETUP_RUN(ui.reset_status(false)); // machine_name Initialized by settings.load()
1372+
#endif
1373+
13661374
#if ENABLED(PROBE_TARE)
13671375
SETUP_RUN(probe.tare_init());
13681376
#endif

Marlin/src/MarlinCore.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ inline void idle_no_sleep() { idle(true); }
4141
void kill(FSTR_P const lcd_error=nullptr, FSTR_P const lcd_component=nullptr, const bool steppers_off=false);
4242
void minkill(const bool steppers_off=false);
4343

44+
#if ENABLED(CONFIGURABLE_MACHINE_NAME)
45+
extern MString<64> machine_name;
46+
#endif
47+
4448
// Global State of the firmware
4549
enum class MarlinState : uint8_t {
4650
MF_INITIALIZING = 0,

Marlin/src/core/language.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
#undef MACHINE_NAME
8989
#define MACHINE_NAME DEFAULT_MACHINE_NAME
9090
#endif
91+
#define MACHINE_NAME_SUBST TERN(CONFIGURABLE_MACHINE_NAME, "$", MACHINE_NAME)
9192

9293
#define MARLIN_WEBSITE_URL "marlinfw.org"
9394

Marlin/src/core/mstring.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ class MString {
298298
MString& clear() { return set(); }
299299
MString& eol() { return append('\n'); }
300300
MString& trunc(const int &i) { if (i <= SIZE) str[i] = '\0'; debug(F("trunc")); return *this; }
301+
MString& ltrim() { char *s = str; while (*s == ' ') ++s; if (s != str) strcpy(str, s); return *this; }
302+
MString& rtrim() { int s = length(); while (s && str[s - 1] == ' ') --s; str[s] = '\0'; return *this; }
303+
MString& trim() { return rtrim().ltrim(); }
301304

302305
// Truncate on a Unicode boundary
303306
MString& utrunc(const int &n=SIZE) {

Marlin/src/gcode/config/M550.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* Marlin 3D Printer Firmware
3+
* Copyright (c) 2025 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4+
*
5+
* Based on Sprinter and grbl.
6+
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
23+
#include "../../inc/MarlinConfig.h"
24+
25+
#if ENABLED(CONFIGURABLE_MACHINE_NAME)
26+
27+
#include "../gcode.h"
28+
#include "../../MarlinCore.h"
29+
#include "../../lcd/marlinui.h"
30+
31+
/**
32+
* M550: Set machine name
33+
*
34+
* Parameters:
35+
* P "<name>" Set the name using the 'P' parameter (RepRapFirmware)
36+
* "<name>" Set the name using the "string" parameter
37+
*/
38+
void GcodeSuite::M550() {
39+
bool did_set = true;
40+
41+
if (parser.seenval('P'))
42+
machine_name = parser.value_string();
43+
else if (TERN(GCODE_QUOTED_STRINGS, false, parser.seen('P')))
44+
machine_name = parser.string_arg[0] == 'P' ? &parser.string_arg[1] : parser.string_arg;
45+
else if (parser.string_arg && parser.string_arg[0])
46+
machine_name = parser.string_arg;
47+
else
48+
did_set = false;
49+
50+
if (did_set) {
51+
machine_name.trim();
52+
ui.reset_status(false);
53+
}
54+
else
55+
SERIAL_ECHOLNPGM("RepRap name: ", &machine_name);
56+
57+
}
58+
59+
#endif // CONFIGURABLE_MACHINE_NAME

Marlin/src/gcode/control/M80_M81.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#include "../../feature/powerloss.h"
3939
#endif
4040

41-
#if HAS_SUICIDE
41+
#if ANY(HAS_SUICIDE, CONFIGURABLE_MACHINE_NAME)
4242
#include "../../MarlinCore.h"
4343
#endif
4444

@@ -92,7 +92,11 @@ void GcodeSuite::M81() {
9292

9393
safe_delay(1000); // Wait 1 second before switching off
9494

95-
LCD_MESSAGE_F(MACHINE_NAME " " STR_OFF ".");
95+
#if ENABLED(CONFIGURABLE_MACHINE_NAME)
96+
ui.set_status(&MString<30>(&machine_name, ' ', F(STR_OFF), '.'));
97+
#else
98+
LCD_MESSAGE_F(MACHINE_NAME " " STR_OFF ".");
99+
#endif
96100

97101
bool delayed_power_off = false;
98102

Marlin/src/gcode/gcode.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,10 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
947947
case 540: M540(); break; // M540: Set abort on endstop hit for SD printing
948948
#endif
949949

950+
#if ENABLED(CONFIGURABLE_MACHINE_NAME)
951+
case 550: M550(); break; // M550: Set machine name
952+
#endif
953+
950954
#if HAS_ETHERNET
951955
case 552: M552(); break; // M552: Set IP address
952956
case 553: M553(); break; // M553: Set gateway

Marlin/src/gcode/gcode.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@
261261
* M512 - Set/Change/Remove Password (Requires PASSWORD_CHANGE_GCODE)
262262
* M524 - Abort the current SD print job started with M24. (Requires SDSUPPORT)
263263
* M540 - Enable/disable SD card abort on endstop hit: "M540 S<state>". (Requires SD_ABORT_ON_ENDSTOP_HIT)
264+
* M550 - Set the machine name: "M550 P<name>". (Requires CONFIGURABLE_MACHINE_NAME)
264265
* M552 - Get or set IP address. Enable/disable network interface. (Requires enabled Ethernet port)
265266
* M553 - Get or set IP netmask. (Requires enabled Ethernet port)
266267
* M554 - Get or set IP gateway. (Requires enabled Ethernet port)
@@ -1128,6 +1129,10 @@ class GcodeSuite {
11281129
static void M540();
11291130
#endif
11301131

1132+
#if ENABLED(CONFIGURABLE_MACHINE_NAME)
1133+
static void M550();
1134+
#endif
1135+
11311136
#if HAS_ETHERNET
11321137
static void M552();
11331138
static void M552_report();

0 commit comments

Comments
 (0)