From d43cc2dd5f52c9b71b486e7778d7fb44ea67fad6 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 26 Apr 2015 20:08:45 -0700 Subject: [PATCH] M111 - Debug Level - Add `M111` as a standard option to set the debug level - Implement `DEBUG_ECHO` in `process_commands` - Other debug levels (e.g., `DEBUG_DRYRUN`) need more work --- Marlin/Marlin.h | 12 ++++++ Marlin/Marlin_main.cpp | 59 ++++++++++++++++++--------- Marlin/configurator/config/language.h | 3 +- Marlin/language.h | 3 +- 4 files changed, 55 insertions(+), 22 deletions(-) diff --git a/Marlin/Marlin.h b/Marlin/Marlin.h index 0158a1d714..97978c45f7 100644 --- a/Marlin/Marlin.h +++ b/Marlin/Marlin.h @@ -223,6 +223,18 @@ void Stop(); void filrunout(); #endif +/** + * Debug flags - not yet widely applied + */ +enum DebugFlags { + DEBUG_ECHO = BIT(0), + DEBUG_INFO = BIT(1), + DEBUG_ERRORS = BIT(2), + DEBUG_DRYRUN = BIT(3), + DEBUG_COMMUNICATION = BIT(4) +}; +extern uint8_t marlin_debug_flags; + extern bool Running; inline bool IsRunning() { return Running; } inline bool IsStopped() { return !Running; } diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 33432ac366..ac86cb05b7 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -138,6 +138,7 @@ * M109 - Sxxx Wait for extruder current temp to reach target temp. Waits only when heating * Rxxx Wait for extruder current temp to reach target temp. Waits when heating and cooling * IF AUTOTEMP is enabled, S B F. Exit autotemp by any M109 without F + * M111 - Set debug flags with S. See flag bits defined in Marlin.h. * M112 - Emergency stop * M114 - Output current position to serial port * M115 - Capabilities string @@ -218,6 +219,8 @@ bool Running = true; +uint8_t marlin_debug_flags = DEBUG_INFO|DEBUG_ERRORS; + static float feedrate = 1500.0, next_feedrate, saved_feedrate; float current_position[NUM_AXIS] = { 0.0 }; static float destination[NUM_AXIS] = { 0.0 }; @@ -749,9 +752,10 @@ void get_command() { gcode_N = (strtol(strchr_pointer + 1, NULL, 10)); if (gcode_N != gcode_LastN + 1 && strstr_P(command, PSTR("M110")) == NULL) { SERIAL_ERROR_START; - SERIAL_ERRORPGM(MSG_ERR_LINE_NO); - SERIAL_ERRORLN(gcode_LastN); - //Serial.println(gcode_N); + SERIAL_ERRORPGM(MSG_ERR_LINE_NO1); + SERIAL_ERROR(gcode_LastN + 1); + SERIAL_ERRORPGM(MSG_ERR_LINE_NO2); + SERIAL_ERRORLN(gcode_N); FlushSerialRequestResend(); serial_count = 0; return; @@ -3336,12 +3340,17 @@ inline void gcode_M109() { #endif // HAS_TEMP_BED +/** + * M111: Set the debug level + */ +inline void gcode_M111() { + marlin_debug_flags = code_seen('S') ? code_value_short() : DEBUG_INFO|DEBUG_ERRORS; +} + /** * M112: Emergency Stop */ -inline void gcode_M112() { - kill(); -} +inline void gcode_M112() { kill(); } #ifdef BARICUDA @@ -4781,6 +4790,12 @@ inline void gcode_T() { * This is called from the main loop() */ void process_commands() { + + if ((marlin_debug_flags & DEBUG_ECHO)) { + SERIAL_ECHO_START; + SERIAL_ECHOLN(command_queue[cmd_queue_index_r]); + } + if (code_seen('G')) { int gCode = code_value_short(); @@ -4919,34 +4934,38 @@ void process_commands() { gcode_M104(); break; - case 112: // M112 Emergency Stop + case 111: // M111: Set debug level + gcode_M111(); + break; + + case 112: // M112: Emergency Stop gcode_M112(); break; - case 140: // M140 Set bed temp + case 140: // M140: Set bed temp gcode_M140(); break; - case 105: // M105 Read current temperature + case 105: // M105: Read current temperature gcode_M105(); return; break; - case 109: // M109 Wait for temperature + case 109: // M109: Wait for temperature gcode_M109(); break; #if HAS_TEMP_BED - case 190: // M190 - Wait for bed heater to reach target. + case 190: // M190: Wait for bed heater to reach target gcode_M190(); break; #endif // HAS_TEMP_BED #if HAS_FAN - case 106: //M106 Fan On + case 106: // M106: Fan On gcode_M106(); break; - case 107: //M107 Fan Off + case 107: // M107: Fan Off gcode_M107(); break; #endif // HAS_FAN @@ -4954,20 +4973,20 @@ void process_commands() { #ifdef BARICUDA // PWM for HEATER_1_PIN #if HAS_HEATER_1 - case 126: // M126 valve open + case 126: // M126: valve open gcode_M126(); break; - case 127: // M127 valve closed + case 127: // M127: valve closed gcode_M127(); break; #endif // HAS_HEATER_1 // PWM for HEATER_2_PIN #if HAS_HEATER_2 - case 128: // M128 valve open + case 128: // M128: valve open gcode_M128(); break; - case 129: // M129 valve closed + case 129: // M129: valve closed gcode_M129(); break; #endif // HAS_HEATER_2 @@ -4975,13 +4994,13 @@ void process_commands() { #if HAS_POWER_SWITCH - case 80: // M80 - Turn on Power Supply + case 80: // M80: Turn on Power Supply gcode_M80(); break; #endif // HAS_POWER_SWITCH - case 81: // M81 - Turn off Power, including Power Supply, if possible + case 81: // M81: Turn off Power, including Power Supply, if possible gcode_M81(); break; @@ -4991,7 +5010,7 @@ void process_commands() { case 83: gcode_M83(); break; - case 18: //compatibility + case 18: // (for compatibility) case 84: // M84 gcode_M18_M84(); break; diff --git a/Marlin/configurator/config/language.h b/Marlin/configurator/config/language.h index 718fe9499c..2576bec42b 100644 --- a/Marlin/configurator/config/language.h +++ b/Marlin/configurator/config/language.h @@ -122,7 +122,8 @@ #define MSG_PLANNER_BUFFER_BYTES " PlannerBufferBytes: " #define MSG_OK "ok" #define MSG_FILE_SAVED "Done saving file." -#define MSG_ERR_LINE_NO "Line Number is not Last Line Number+1, Last Line: " +#define MSG_ERR_LINE_NO1 "Line Number out of sequence. Expected: " +#define MSG_ERR_LINE_NO2 " Got: " #define MSG_ERR_CHECKSUM_MISMATCH "checksum mismatch, Last Line: " #define MSG_ERR_NO_CHECKSUM "No Checksum with line number, Last Line: " #define MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM "No Line Number with checksum, Last Line: " diff --git a/Marlin/language.h b/Marlin/language.h index 3bc7ce0161..c9ddfeee41 100644 --- a/Marlin/language.h +++ b/Marlin/language.h @@ -122,7 +122,8 @@ #define MSG_PLANNER_BUFFER_BYTES " PlannerBufferBytes: " #define MSG_OK "ok" #define MSG_FILE_SAVED "Done saving file." -#define MSG_ERR_LINE_NO "Line Number is not Last Line Number+1, Last Line: " +#define MSG_ERR_LINE_NO1 "Line Number out of sequence. Expected: " +#define MSG_ERR_LINE_NO2 " Got: " #define MSG_ERR_CHECKSUM_MISMATCH "checksum mismatch, Last Line: " #define MSG_ERR_NO_CHECKSUM "No Checksum with line number, Last Line: " #define MSG_ERR_NO_LINENUMBER_WITH_CHECKSUM "No Line Number with checksum, Last Line: "