Skip to content

Commit

Permalink
✨ M110 Get Command Line Number (MarlinFirmware#27090)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
  • Loading branch information
ellensp and thinkyhead authored May 20, 2024
1 parent 75eee04 commit 5561baf
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions Marlin/src/core/language.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
#define STR_BUSY_PAUSED_FOR_USER "busy: paused for user"
#define STR_BUSY_PAUSED_FOR_INPUT "busy: paused for input"
#define STR_Z_MOVE_COMP "Z_move_comp"
#define STR_LINE_NO "Line: "
#define STR_RESEND "Resend: "
#define STR_UNKNOWN_COMMAND "Unknown command: \""
#define STR_ACTIVE_EXTRUDER "Active Extruder: "
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/gcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
* R<temp> Wait for extruder current temp to reach target temp. ** Wait for heating or cooling. **
* If AUTOTEMP is enabled, S<mintemp> B<maxtemp> F<factor>. Exit autotemp by any M109 without F
*
* M110 - Set the current line number. (Used by host printing)
* M110 - Get or set the current line number. (Used by host printing)
* M111 - Set debug flags: "M111 S<flagbits>". See flag bits defined in enum.h.
* M112 - Full Shutdown.
*
Expand Down
12 changes: 10 additions & 2 deletions Marlin/src/gcode/host/M110.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,19 @@
#include "../queue.h" // for last_N

/**
* M110: Set Current Line Number
* M110: Get or set Current Line Number
*
* Parameters:
* N<int> Number to set as last-processed command
*
* Without parameters:
* Report the last-processed (not last-received or last-enqueued) command
* (To purge the queue and resume from this line, the host should use 'M999' instead.)
*/
void GcodeSuite::M110() {

if (parser.seenval('N'))
queue.set_current_line_number(parser.value_long());

else
SERIAL_ECHOLNPGM(STR_LINE_NO, queue.get_current_line_number());
}
5 changes: 5 additions & 0 deletions Marlin/src/gcode/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ class GCodeQueue {
*/
static void set_current_line_number(long n) { serial_state[ring_buffer.command_port().index].last_N = n; }

/**
* Get the current line number for the last received command
*/
static long get_current_line_number() { return serial_state[ring_buffer.command_port().index].last_N; }

#if ENABLED(BUFFER_MONITORING)

private:
Expand Down

0 comments on commit 5561baf

Please sign in to comment.