diff --git a/g2core/canonical_machine.h b/g2core/canonical_machine.h index a557d608..742b21f0 100644 --- a/g2core/canonical_machine.h +++ b/g2core/canonical_machine.h @@ -192,6 +192,7 @@ typedef enum { // these are in order to optimized CASE NEXT_ACTION_MARLIN_RESET_LINE_NUMBERS, // M110 NEXT_ACTION_MARLIN_REPORT_VERSION, // M115 NEXT_ACTION_MARLIN_DISPLAY_ON_SCREEN, // M117 + NEXT_ACTION_MARLIN_SET_MT, // M84 (with S), M85 #endif } cmNextAction; diff --git a/g2core/gcode_parser.cpp b/g2core/gcode_parser.cpp index cccb9d45..cfeac90a 100644 --- a/g2core/gcode_parser.cpp +++ b/g2core/gcode_parser.cpp @@ -743,7 +743,9 @@ stat_t _parse_gcode_block(char *buf, char *active_comment) case 117: return STAT_OK; //SET_NON_MODAL (next_action, NEXT_ACTION_MARLIN_DISPLAY_ON_SCREEN); + case 18: // compatibility alias for M84 case 84: SET_NON_MODAL (next_action, NEXT_ACTION_MARLIN_DISABLE_MOTORS); + case 85: SET_NON_MODAL (next_action, NEXT_ACTION_MARLIN_SET_MT); case 110: SET_NON_MODAL (next_action, NEXT_ACTION_MARLIN_RESET_LINE_NUMBERS); case 111: return STAT_OK; // ignore M111, and don't process contents of the line further @@ -941,11 +943,26 @@ stat_t _execute_gcode_block(char *active_comment) } break; } - case NEXT_ACTION_MARLIN_DISABLE_MOTORS: { // M84 - ritorno(marlin_disable_motors()); + case NEXT_ACTION_MARLIN_DISABLE_MOTORS: { // M84 and M18 + if (gf.S_word) { + ritorno(marlin_set_motor_timeout(gv.S_word)); + gf.S_word = false; + } else { + ritorno(marlin_disable_motors()); + } + break; } - case NEXT_ACTION_MARLIN_DISPLAY_ON_SCREEN: { // M184 + case NEXT_ACTION_MARLIN_SET_MT: { // M85 + if (gf.S_word) { + ritorno(marlin_set_motor_timeout(gv.S_word)); + gf.S_word = false; + } else { + // this means nothing, but it's not an error + return status; + } + } + case NEXT_ACTION_MARLIN_DISPLAY_ON_SCREEN: { // M117 // ignore for now return status; } diff --git a/g2core/marlin_compatibility.cpp b/g2core/marlin_compatibility.cpp index e80ce843..e1625f19 100644 --- a/g2core/marlin_compatibility.cpp +++ b/g2core/marlin_compatibility.cpp @@ -31,6 +31,7 @@ #include "temperature.h" // for temperature controls #include "json_parser.h" #include "planner.h" +#include "stepper.h" // for MOTOR_TIMEOUT_SECONDS_MIN/MOTOR_TIMEOUT_SECONDS_MAX #include "MotateTimers.h" // for char definitions #include "MotateUniqueID.h" // for Motate::UUID @@ -484,7 +485,7 @@ stat_t marlin_set_fan_speed(const uint8_t fan, float speed) /* - * marlin_disable_motors() - M84 + * marlin_disable_motors() - M84 (without S) * */ @@ -500,6 +501,33 @@ stat_t marlin_disable_motors() return (STAT_OK); } +/* + * marlin_set_motor_timeout() - M84 (with S), M85 Sxxx + * + */ + +stat_t marlin_set_motor_timeout(float s) // M18 Sxxx, M84 Sxxx, M85 Sxxx +{ + if (s < MOTOR_TIMEOUT_SECONDS_MIN) { + return (STAT_INPUT_LESS_THAN_MIN_VALUE); + } + if (s > MOTOR_TIMEOUT_SECONDS_MAX) { + return (STAT_INPUT_EXCEEDS_MAX_VALUE); + } + + char buffer[128]; + char *str = buffer; + + // TODO: support other fans, or remapping output + str_concat(str, "{mt:"); + str += floattoa(str, s, 1); + str_concat(str, "}"); + + cm_json_command(buffer); + + return (STAT_OK); +} + /* * marlin_report_version() - M115 diff --git a/g2core/marlin_compatibility.h b/g2core/marlin_compatibility.h index d1673ff0..1f6d50c6 100644 --- a/g2core/marlin_compatibility.h +++ b/g2core/marlin_compatibility.h @@ -48,6 +48,7 @@ stat_t cm_marlin_set_extruder_mode(const uint8_t mode); // M82, M82 stat_t marlin_set_fan_speed(const uint8_t fan, float speed); // M106, M107 stat_t marlin_disable_motors(); // M84 +stat_t marlin_set_motor_timeout(float s); // M18 Sxxx, M84 Sxxx, M85 Sxxx stat_t marlin_report_version(); // M115 #endif // End of include guard: MARLIN_COMPAT_H_ONCE