Skip to content

Commit 5561baf

Browse files
ellenspthinkyhead
andauthored
✨ M110 Get Command Line Number (#27090)
Co-authored-by: Scott Lahteine <[email protected]>
1 parent 75eee04 commit 5561baf

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

Marlin/src/core/language.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
#define STR_BUSY_PAUSED_FOR_USER "busy: paused for user"
136136
#define STR_BUSY_PAUSED_FOR_INPUT "busy: paused for input"
137137
#define STR_Z_MOVE_COMP "Z_move_comp"
138+
#define STR_LINE_NO "Line: "
138139
#define STR_RESEND "Resend: "
139140
#define STR_UNKNOWN_COMMAND "Unknown command: \""
140141
#define STR_ACTIVE_EXTRUDER "Active Extruder: "

Marlin/src/gcode/gcode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
* R<temp> Wait for extruder current temp to reach target temp. ** Wait for heating or cooling. **
144144
* If AUTOTEMP is enabled, S<mintemp> B<maxtemp> F<factor>. Exit autotemp by any M109 without F
145145
*
146-
* M110 - Set the current line number. (Used by host printing)
146+
* M110 - Get or set the current line number. (Used by host printing)
147147
* M111 - Set debug flags: "M111 S<flagbits>". See flag bits defined in enum.h.
148148
* M112 - Full Shutdown.
149149
*

Marlin/src/gcode/host/M110.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,19 @@
2424
#include "../queue.h" // for last_N
2525

2626
/**
27-
* M110: Set Current Line Number
27+
* M110: Get or set Current Line Number
28+
*
29+
* Parameters:
30+
* N<int> Number to set as last-processed command
31+
*
32+
* Without parameters:
33+
* Report the last-processed (not last-received or last-enqueued) command
34+
* (To purge the queue and resume from this line, the host should use 'M999' instead.)
2835
*/
2936
void GcodeSuite::M110() {
3037

3138
if (parser.seenval('N'))
3239
queue.set_current_line_number(parser.value_long());
33-
40+
else
41+
SERIAL_ECHOLNPGM(STR_LINE_NO, queue.get_current_line_number());
3442
}

Marlin/src/gcode/queue.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ class GCodeQueue {
212212
*/
213213
static void set_current_line_number(long n) { serial_state[ring_buffer.command_port().index].last_N = n; }
214214

215+
/**
216+
* Get the current line number for the last received command
217+
*/
218+
static long get_current_line_number() { return serial_state[ring_buffer.command_port().index].last_N; }
219+
215220
#if ENABLED(BUFFER_MONITORING)
216221

217222
private:

0 commit comments

Comments
 (0)