From fb9de6e7877bb2e04640fa731f8b30c0967ec215 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 7 Mar 2018 00:06:03 -0600 Subject: [PATCH] Add AUTO_REPORT_SD_STATUS feature For parity with 2.0.x ahead of 1.1.9 release. --- Marlin/Configuration_adv.h | 5 +++++ Marlin/Marlin_main.cpp | 25 ++++++++++++++++++++++--- Marlin/cardreader.cpp | 13 +++++++++++++ Marlin/cardreader.h | 16 +++++++++++++++- 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 3220c2f15..506009c21 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -1410,6 +1410,11 @@ */ #define AUTO_REPORT_TEMPERATURES +/** + * Auto-report SdCard status with M27 S + */ +//#define AUTO_REPORT_SD_STATUS + /** * Include capabilities in M115 output */ diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index ff35b97ec..7595cf4ef 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -89,7 +89,7 @@ * M24 - Start/resume SD print. (Requires SDSUPPORT) * M25 - Pause SD print. (Requires SDSUPPORT) * M26 - Set SD position in bytes: "M26 S12345". (Requires SDSUPPORT) - * M27 - Report SD print status. (Requires SDSUPPORT) + * M27 - Report SD print status. (Requires SDSUPPORT) Or, with 'S' sets the SD status auto-report interval. (Requires AUTO_REPORT_SD_STATUS) * M28 - Start SD write: "M28 /path/file.gco". (Requires SDSUPPORT) * M29 - Stop SD write. (Requires SDSUPPORT) * M30 - Delete file from SD: "M30 /path/file.gco" @@ -6886,9 +6886,17 @@ inline void gcode_M17() { } /** - * M27: Get SD Card status + * M27: Get SD Card status or set the SD status auto-report interval. + */ - inline void gcode_M27() { card.getStatus(); } + inline void gcode_M27() { + #if ENABLED(AUTO_REPORT_SD_STATUS) + if (parser.seenval('S')) + card.set_auto_report_interval(parser.value_byte()); + else + #endif + card.getStatus(); + } /** * M28: Start SD Write @@ -8636,6 +8644,13 @@ inline void gcode_M115() { #endif ); + // AUTOREPORT_SD_STATUS (M27 extension) + cap_line(PSTR("AUTOREPORT_SD_STATUS") + #if ENABLED(AUTO_REPORT_SD_STATUS) + , true + #endif + ); + #endif // EXTENDED_CAPABILITIES_REPORT } @@ -13467,6 +13482,10 @@ void idle( i2cpem_next_update_ms = millis() + I2CPE_MIN_UPD_TIME_MS; } #endif + + #if ENABLED(AUTO_REPORT_SD_STATUS) + card.auto_report_sd_status(); + #endif } /** diff --git a/Marlin/cardreader.cpp b/Marlin/cardreader.cpp index 644bbe7fe..860ea17a9 100644 --- a/Marlin/cardreader.cpp +++ b/Marlin/cardreader.cpp @@ -911,4 +911,17 @@ void CardReader::printingHasFinished() { } } +#if ENABLED(AUTO_REPORT_SD_STATUS) + uint8_t CardReader::auto_report_sd_interval = 0; + millis_t CardReader::next_sd_report_ms; + + void CardReader::auto_report_sd_status() { + millis_t current_ms = millis(); + if (auto_report_sd_interval && ELAPSED(current_ms, next_sd_report_ms)) { + next_sd_report_ms = current_ms + 1000UL * auto_report_sd_interval; + getStatus(); + } + } +#endif // AUTO_REPORT_SD_STATUS + #endif // SDSUPPORT diff --git a/Marlin/cardreader.h b/Marlin/cardreader.h index 5bcdd2b6b..7b5ccdb9f 100644 --- a/Marlin/cardreader.h +++ b/Marlin/cardreader.h @@ -90,10 +90,19 @@ public: FORCE_INLINE uint8_t percentDone() { return (isFileOpen() && filesize) ? sdpos / ((filesize + 99) / 100) : 0; } FORCE_INLINE char* getWorkDirName() { workDir.getFilename(filename); return filename; } -public: + #if ENABLED(AUTO_REPORT_SD_STATUS) + void auto_report_sd_status(void); + FORCE_INLINE void set_auto_report_interval(uint8_t v) { + NOMORE(v, 60); + auto_report_sd_interval = v; + next_sd_report_ms = millis() + 1000UL * v; + } + #endif + bool saving, logging, sdprinting, cardOK, filenameIsDir; char filename[FILENAME_LENGTH], longFilename[LONG_FILENAME_LENGTH]; int autostart_index; + private: SdFile root, *curDir, workDir, workDirParents[MAX_DIR_DEPTH]; uint8_t workDirDepth; @@ -170,6 +179,11 @@ private: #if ENABLED(SDCARD_SORT_ALPHA) void flush_presort(); #endif + + #if ENABLED(AUTO_REPORT_SD_STATUS) + static uint8_t auto_report_sd_interval; + static millis_t next_sd_report_ms; + #endif }; #if PIN_EXISTS(SD_DETECT)