From 4402760739d2435bc58affecd70b0440dbeabf31 Mon Sep 17 00:00:00 2001
From: Scott Lahteine <sourcetree@thinkyhead.com>
Date: Tue, 29 Mar 2016 19:18:45 -0700
Subject: [PATCH] Echo all debug levels in M111, default to DEBUG_NONE

Redo of #3268 by @jbrazio
---
 Marlin/Marlin.h        |  1 +
 Marlin/Marlin_main.cpp | 50 ++++++++++++++++++++++++++----------------
 Marlin/language.h      | 13 ++++++-----
 3 files changed, 40 insertions(+), 24 deletions(-)

diff --git a/Marlin/Marlin.h b/Marlin/Marlin.h
index 1294b5ebec..58a6ff7112 100644
--- a/Marlin/Marlin.h
+++ b/Marlin/Marlin.h
@@ -229,6 +229,7 @@ void Stop();
  * Debug flags - not yet widely applied
  */
 enum DebugFlags {
+  DEBUG_NONE          = 0,
   DEBUG_ECHO          = _BV(0),
   DEBUG_INFO          = _BV(1),
   DEBUG_ERRORS        = _BV(2),
diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp
index f3fb8876d0..8bc93d4482 100644
--- a/Marlin/Marlin_main.cpp
+++ b/Marlin/Marlin_main.cpp
@@ -250,7 +250,7 @@
 
 bool Running = true;
 
-uint8_t marlin_debug_flags = DEBUG_INFO | DEBUG_ERRORS;
+uint8_t marlin_debug_flags = DEBUG_NONE;
 
 static float feedrate = 1500.0, saved_feedrate;
 float current_position[NUM_AXIS] = { 0.0 };
@@ -4346,27 +4346,39 @@ inline void gcode_M110() {
  * M111: Set the debug level
  */
 inline void gcode_M111() {
-  marlin_debug_flags = code_seen('S') ? code_value_short() : DEBUG_INFO | DEBUG_COMMUNICATION;
-
-  if (marlin_debug_flags & DEBUG_ECHO) {
-    SERIAL_ECHO_START;
-    SERIAL_ECHOLNPGM(MSG_DEBUG_ECHO);
-  }
-  // FOR MOMENT NOT ACTIVE
-  //if (marlin_debug_flags & DEBUG_INFO) SERIAL_ECHOLNPGM(MSG_DEBUG_INFO);
-  //if (marlin_debug_flags & DEBUG_ERRORS) SERIAL_ECHOLNPGM(MSG_DEBUG_ERRORS);
-  if (marlin_debug_flags & DEBUG_DRYRUN) {
-    SERIAL_ECHO_START;
-    SERIAL_ECHOLNPGM(MSG_DEBUG_DRYRUN);
-    disable_all_heaters();
-  }
+  marlin_debug_flags = code_seen('S') ? code_value_short() : DEBUG_NONE;
 
+  const char str_debug_1[] PROGMEM = MSG_DEBUG_ECHO;
+  const char str_debug_2[] PROGMEM = MSG_DEBUG_INFO;
+  const char str_debug_4[] PROGMEM = MSG_DEBUG_ERRORS;
+  const char str_debug_8[] PROGMEM = MSG_DEBUG_DRYRUN;
+  const char str_debug_16[] PROGMEM = MSG_DEBUG_COMMUNICATION;
   #if ENABLED(DEBUG_LEVELING_FEATURE)
-    if (marlin_debug_flags & DEBUG_LEVELING) {
-      SERIAL_ECHO_START;
-      SERIAL_ECHOLNPGM(MSG_DEBUG_LEVELING);
-    }
+    const char str_debug_32[] PROGMEM = MSG_DEBUG_LEVELING;
   #endif
+
+  const char* const debug_strings[] PROGMEM = {
+    str_debug_1, str_debug_2, str_debug_4, str_debug_8, str_debug_16,
+    #if ENABLED(DEBUG_LEVELING_FEATURE)
+      str_debug_32
+    #endif
+  };
+
+  SERIAL_ECHO_START;
+  SERIAL_ECHOPGM(MSG_DEBUG_PREFIX);
+  if (marlin_debug_flags) {
+    uint8_t comma = 0;
+    for (uint8_t i = 0; i < COUNT(debug_strings); i++) {
+      if (TEST(marlin_debug_flags, i)) {
+        if (comma++) SERIAL_CHAR('|');
+        serialprintPGM(debug_strings[i]);
+      }
+    }
+  }
+  else {
+    SERIAL_ECHOPGM(MSG_DEBUG_OFF);
+  }
+  SERIAL_EOL;
 }
 
 /**
diff --git a/Marlin/language.h b/Marlin/language.h
index 1b82ec314c..2c8d3cc722 100644
--- a/Marlin/language.h
+++ b/Marlin/language.h
@@ -238,11 +238,14 @@
 #define MSG_T_MINTEMP                       "MINTEMP triggered"
 
 // Debug
-#define MSG_DEBUG_ECHO                      "DEBUG ECHO ENABLED"
-#define MSG_DEBUG_INFO                      "DEBUG INFO ENABLED"
-#define MSG_DEBUG_ERRORS                    "DEBUG ERRORS ENABLED"
-#define MSG_DEBUG_DRYRUN                    "DEBUG DRYRUN ENABLED"
-#define MSG_DEBUG_LEVELING                  "DEBUG LEVELING ENABLED"
+#define MSG_DEBUG_PREFIX                    "DEBUG: "
+#define MSG_DEBUG_OFF                       "off"
+#define MSG_DEBUG_ECHO                      "ECHO"
+#define MSG_DEBUG_INFO                      "INFO"
+#define MSG_DEBUG_ERRORS                    "ERRORS"
+#define MSG_DEBUG_DRYRUN                    "DRYRUN"
+#define MSG_DEBUG_COMMUNICATION             "COMMUNICATION"
+#define MSG_DEBUG_LEVELING                  "LEVELING"
 
 // LCD Menu Messages
 
-- 
GitLab