From 61932b859efb472f7075c390b12a7b41c6e17230 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 12 Aug 2016 03:21:10 -0700 Subject: [PATCH] Fix bug in CardReader::stopSDPrint If the SD print is paused, it cannot be stopped --- Marlin/cardreader.cpp | 20 ++++++-------------- Marlin/cardreader.h | 2 +- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/Marlin/cardreader.cpp b/Marlin/cardreader.cpp index a0cdadc97..1eeab4643 100644 --- a/Marlin/cardreader.cpp +++ b/Marlin/cardreader.cpp @@ -276,19 +276,12 @@ void CardReader::openAndPrintFile(const char *name) { } void CardReader::startFileprint() { - if (cardOK) - sdprinting = true; -} - -void CardReader::pauseSDPrint() { - if (sdprinting) sdprinting = false; + if (cardOK) sdprinting = true; } void CardReader::stopSDPrint() { - if (sdprinting) { - sdprinting = false; - file.close(); - } + sdprinting = false; + if (isFileOpen()) file.close(); } void CardReader::openLogFile(char* name) { @@ -340,7 +333,6 @@ void CardReader::openFile(char* name, bool read, bool push_current/*=false*/) { SERIAL_ECHOPGM("Now doing file: "); SERIAL_ECHOLN(name); } - file.close(); } else { //opening fresh file file_subcall_ctr = 0; //resetting procedure depth in case user cancels print while in procedure @@ -348,7 +340,8 @@ void CardReader::openFile(char* name, bool read, bool push_current/*=false*/) { SERIAL_ECHOPGM("Now fresh file: "); SERIAL_ECHOLN(name); } - sdprinting = false; + + stopSDPrint(); SdFile myDir; curDir = &root; @@ -425,8 +418,7 @@ void CardReader::openFile(char* name, bool read, bool push_current/*=false*/) { void CardReader::removeFile(char* name) { if (!cardOK) return; - file.close(); - sdprinting = false; + stopSDPrint(); SdFile myDir; curDir = &root; diff --git a/Marlin/cardreader.h b/Marlin/cardreader.h index 8c22e581c..b0ed92b89 100644 --- a/Marlin/cardreader.h +++ b/Marlin/cardreader.h @@ -51,7 +51,6 @@ public: void release(); void openAndPrintFile(const char *name); void startFileprint(); - void pauseSDPrint(); void stopSDPrint(); void getStatus(); void printingHasFinished(); @@ -70,6 +69,7 @@ public: void updir(); void setroot(); + FORCE_INLINE void pauseSDPrint() { sdprinting = false; } FORCE_INLINE bool isFileOpen() { return file.isOpen(); } FORCE_INLINE bool eof() { return sdpos >= filesize; } FORCE_INLINE int16_t get() { sdpos = file.curPosition(); return (int16_t)file.read(); }