Skip to content

Commit

Permalink
M111 - Debug Level
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
thinkyhead committed Apr 27, 2015
1 parent 1f530be commit d43cc2d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 22 deletions.
12 changes: 12 additions & 0 deletions Marlin/Marlin.h
Expand Up @@ -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; }
Expand Down
59 changes: 39 additions & 20 deletions Marlin/Marlin_main.cpp
Expand Up @@ -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<mintemp> B<maxtemp> F<factor>. Exit autotemp by any M109 without F
* M111 - Set debug flags with S<mask>. See flag bits defined in Marlin.h.
* M112 - Emergency stop
* M114 - Output current position to serial port
* M115 - Capabilities string
Expand Down Expand Up @@ -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 };
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -3337,12 +3341,17 @@ inline void gcode_M109() {
#endif // HAS_TEMP_BED

/**
* M112: Emergency Stop
* M111: Set the debug level
*/
inline void gcode_M112() {
kill();
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(); }

#ifdef BARICUDA

#if HAS_HEATER_1
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -4919,69 +4934,73 @@ 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

#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
#endif // BARICUDA

#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;

Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion Marlin/configurator/config/language.h
Expand Up @@ -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: "
Expand Down
3 changes: 2 additions & 1 deletion Marlin/language.h
Expand Up @@ -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: "
Expand Down

0 comments on commit d43cc2d

Please sign in to comment.