From ecc09e0b5455ccc4131c6efebf194c2dac4906dc Mon Sep 17 00:00:00 2001 From: Rob Giseburt Date: Mon, 6 Feb 2017 16:53:11 -0600 Subject: [PATCH] Marlin: *fake* support for SD M-codes (M20, M21, M22, M23) --- g2core/gcode_parser.cpp | 10 ++++++++++ g2core/marlin_compatibility.cpp | 35 +++++++++++++++++++++++++++++++++ g2core/marlin_compatibility.h | 3 +++ 3 files changed, 48 insertions(+) diff --git a/g2core/gcode_parser.cpp b/g2core/gcode_parser.cpp index e840d283..469e8264 100644 --- a/g2core/gcode_parser.cpp +++ b/g2core/gcode_parser.cpp @@ -751,6 +751,16 @@ stat_t _parse_gcode_block(char *buf, char *active_comment) case 111: return STAT_OK; // ignore M111, and don't process contents of the line further case 115: SET_NON_MODAL (next_action, NEXT_ACTION_MARLIN_REPORT_VERSION); + + case 20: // List SD card + return marlin_list_sd_response(); + case 21: // Initialize SD card + case 22: // Release SD card + return STAT_OK; + + case 23: // Select SD file + return marlin_select_sd_response(pstr); + #endif // MARLIN_COMPAT_ENABLED default: status = STAT_MCODE_COMMAND_UNSUPPORTED; diff --git a/g2core/marlin_compatibility.cpp b/g2core/marlin_compatibility.cpp index e1625f19..6a189972 100644 --- a/g2core/marlin_compatibility.cpp +++ b/g2core/marlin_compatibility.cpp @@ -588,4 +588,39 @@ stat_t marlin_report_version() return (STAT_OK); } +/* + * marlin_list_sd_response() - M20 + * + */ +stat_t marlin_list_sd_response() +{ + char buffer[128]; + char *str = buffer; + + str_concat(str, "Begin file list\nEnd file list\n"); + *str = 0; + xio_writeline(buffer); + + return (STAT_OK); +} + +/* + * marlin_select_sd_response() - M23 + * + */ +stat_t marlin_select_sd_response(const char *file) +{ + char buffer[128]; + char *str = buffer; + + str_concat(str, "open failed, File: "); + strncpy(str, file, Motate::strlen(file)); + str += Motate::strlen(file); + str_concat(str, "\n"); + *str = 0; + xio_writeline(buffer); + + return (STAT_OK); +} + #endif // MARLIN_COMPAT_ENABLED == true diff --git a/g2core/marlin_compatibility.h b/g2core/marlin_compatibility.h index 1f6d50c6..41ef0a3b 100644 --- a/g2core/marlin_compatibility.h +++ b/g2core/marlin_compatibility.h @@ -51,4 +51,7 @@ 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 + +stat_t marlin_list_sd_response(); // M20 +stat_t marlin_select_sd_response(const char *file); // M23 #endif // End of include guard: MARLIN_COMPAT_H_ONCE