From 98d362c2da07f2179d5f7af801f513b6f5a5f8e8 Mon Sep 17 00:00:00 2001
From: Ben Lye <ben@lye.co.nz>
Date: Tue, 27 Jun 2017 20:49:21 +0100
Subject: [PATCH] Adding M118 command to send text to serial

Allows the user to send text to the serial console in order to
communicate with a host - sending debuging information or action
commands, for example.  Text must begin with '//' and this is added if
it is not already present at the beginning of the string.
---
 Marlin/Marlin_main.cpp | 12 ++++++++++++
 Marlin/gcode.cpp       |  2 +-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp
index b6dd4c2c8c..d695b273ef 100644
--- a/Marlin/Marlin_main.cpp
+++ b/Marlin/Marlin_main.cpp
@@ -130,6 +130,7 @@
  * M114 - Report current position.
  * M115 - Report capabilities. (Extended capabilities requires EXTENDED_CAPABILITIES_REPORT)
  * M117 - Display a message on the controller screen. (Requires an LCD)
+ * M118 - Display a message in the host console.
  * M119 - Report endstops status.
  * M120 - Enable endstops detection.
  * M121 - Disable endstops detection.
@@ -7991,6 +7992,14 @@ inline void gcode_M115() {
  */
 inline void gcode_M117() { lcd_setstatus(parser.string_arg); }
 
+/**
+ * M118: Display a message in the host console.
+ */
+inline void gcode_M118() {
+  SERIAL_ECHO_START();
+  SERIAL_ECHOLN(parser.string_arg);
+}
+
 /**
  * M119: Output endstop states to serial output
  */
@@ -10758,6 +10767,9 @@ void process_next_command() {
       case 117: // M117: Set LCD message text, if possible
         gcode_M117();
         break;
+      case 118: // M118: Display a message in the host console
+        gcode_M118();
+        break;
       case 119: // M119: Report endstop states
         gcode_M119();
         break;
diff --git a/Marlin/gcode.cpp b/Marlin/gcode.cpp
index a2f5dcfb10..85b3a194ca 100644
--- a/Marlin/gcode.cpp
+++ b/Marlin/gcode.cpp
@@ -150,7 +150,7 @@ void GCodeParser::parse(char *p) {
   #endif
 
   // Only use string_arg for these M codes
-  if (letter == 'M') switch (codenum) { case 23: case 28: case 30: case 117: case 928: string_arg = p; return; default: break; }
+  if (letter == 'M') switch (codenum) { case 23: case 28: case 30: case 117: case 118: case 928: string_arg = p; return; default: break; }
 
   #if ENABLED(DEBUG_GCODE_PARSER)
     const bool debug = codenum == 800;