Browse Source

Merge pull request #4610 from thinkyhead/rc_sd_pause_and_stop

Fix stopSDPrint so it works when paused
Scott Lahteine 9 years ago
parent
commit
fef0e8ba86
3 changed files with 53 additions and 63 deletions
  1. 25
    26
      Marlin/Marlin.h
  2. 27
    36
      Marlin/cardreader.cpp
  3. 1
    1
      Marlin/cardreader.h

+ 25
- 26
Marlin/Marlin.h View File

@@ -60,35 +60,34 @@
60 60
   #include "stopwatch.h"
61 61
 #endif
62 62
 
63
-#define SERIAL_CHAR(x) MYSERIAL.write(x)
64
-#define SERIAL_EOL SERIAL_CHAR('\n')
65
-
66
-#define SERIAL_PROTOCOLCHAR(x) SERIAL_CHAR(x)
67
-#define SERIAL_PROTOCOL(x) MYSERIAL.print(x)
68
-#define SERIAL_PROTOCOL_F(x,y) MYSERIAL.print(x,y)
69
-#define SERIAL_PROTOCOLPGM(x) serialprintPGM(PSTR(x))
70
-#define SERIAL_PROTOCOLLN(x) do{ MYSERIAL.print(x); SERIAL_EOL; }while(0)
71
-#define SERIAL_PROTOCOLLNPGM(x) do{ serialprintPGM(PSTR(x "\n")); }while(0)
72
-
73
-#define SERIAL_PROTOCOLPAIR(name, value) SERIAL_ECHOPAIR(name, value)
74
-#define SERIAL_PROTOCOLLNPAIR(name, value) do{ SERIAL_ECHOPAIR(name, value); SERIAL_EOL; }while(0)
75
-
76
-extern const char errormagic[] PROGMEM;
77 63
 extern const char echomagic[] PROGMEM;
64
+extern const char errormagic[] PROGMEM;
78 65
 
79
-#define SERIAL_ERROR_START serialprintPGM(errormagic)
80
-#define SERIAL_ERROR(x) SERIAL_PROTOCOL(x)
81
-#define SERIAL_ERRORPGM(x) SERIAL_PROTOCOLPGM(x)
82
-#define SERIAL_ERRORLN(x) SERIAL_PROTOCOLLN(x)
83
-#define SERIAL_ERRORLNPGM(x) SERIAL_PROTOCOLLNPGM(x)
84
-
85
-#define SERIAL_ECHO_START serialprintPGM(echomagic)
86
-#define SERIAL_ECHO(x) SERIAL_PROTOCOL(x)
87
-#define SERIAL_ECHOPGM(x) SERIAL_PROTOCOLPGM(x)
88
-#define SERIAL_ECHOLN(x) SERIAL_PROTOCOLLN(x)
89
-#define SERIAL_ECHOLNPGM(x) SERIAL_PROTOCOLLNPGM(x)
66
+#define SERIAL_CHAR(x) (MYSERIAL.write(x))
67
+#define SERIAL_EOL SERIAL_CHAR('\n')
90 68
 
91
-#define SERIAL_ECHOPAIR(name,value) (serial_echopair_P(PSTR(name),(value)))
69
+#define SERIAL_PROTOCOLCHAR(x)              SERIAL_CHAR(x)
70
+#define SERIAL_PROTOCOL(x)                  (MYSERIAL.print(x))
71
+#define SERIAL_PROTOCOL_F(x,y)              (MYSERIAL.print(x,y))
72
+#define SERIAL_PROTOCOLPGM(x)               (serialprintPGM(PSTR(x)))
73
+#define SERIAL_PROTOCOLLN(x)                do{ MYSERIAL.print(x); SERIAL_EOL; }while(0)
74
+#define SERIAL_PROTOCOLLNPGM(x)             (serialprintPGM(PSTR(x "\n")))
75
+#define SERIAL_PROTOCOLPAIR(name, value)    (serial_echopair_P(PSTR(name),(value)))
76
+#define SERIAL_PROTOCOLLNPAIR(name, value)  do{ SERIAL_PROTOCOLPAIR(name, value); SERIAL_EOL; }while(0)
77
+
78
+#define SERIAL_ECHO_START             (serialprintPGM(echomagic))
79
+#define SERIAL_ECHO(x)                 SERIAL_PROTOCOL(x)
80
+#define SERIAL_ECHOPGM(x)              SERIAL_PROTOCOLPGM(x)
81
+#define SERIAL_ECHOLN(x)               SERIAL_PROTOCOLLN(x)
82
+#define SERIAL_ECHOLNPGM(x)            SERIAL_PROTOCOLLNPGM(x)
83
+#define SERIAL_ECHOPAIR(name,value)    SERIAL_PROTOCOLPAIR(name, value)
84
+#define SERIAL_ECHOLNPAIR(name, value) SERIAL_PROTOCOLLNPAIR(name, value)
85
+
86
+#define SERIAL_ERROR_START            (serialprintPGM(errormagic))
87
+#define SERIAL_ERROR(x)                SERIAL_PROTOCOL(x)
88
+#define SERIAL_ERRORPGM(x)             SERIAL_PROTOCOLPGM(x)
89
+#define SERIAL_ERRORLN(x)              SERIAL_PROTOCOLLN(x)
90
+#define SERIAL_ERRORLNPGM(x)           SERIAL_PROTOCOLLNPGM(x)
92 91
 
93 92
 void serial_echopair_P(const char* s_P, const char *v);
94 93
 void serial_echopair_P(const char* s_P, char v);

+ 27
- 36
Marlin/cardreader.cpp View File

@@ -32,12 +32,9 @@
32 32
 #if ENABLED(SDSUPPORT)
33 33
 
34 34
 CardReader::CardReader() {
35
+  sdprinting = cardOK = saving = logging = false;
35 36
   filesize = 0;
36 37
   sdpos = 0;
37
-  sdprinting = false;
38
-  cardOK = false;
39
-  saving = false;
40
-  logging = false;
41 38
   workDirDepth = 0;
42 39
   file_subcall_ctr = 0;
43 40
   memset(workDirParents, 0, sizeof(workDirParents));
@@ -276,19 +273,12 @@ void CardReader::openAndPrintFile(const char *name) {
276 273
 }
277 274
 
278 275
 void CardReader::startFileprint() {
279
-  if (cardOK)
280
-    sdprinting = true;
281
-}
282
-
283
-void CardReader::pauseSDPrint() {
284
-  if (sdprinting) sdprinting = false;
276
+  if (cardOK) sdprinting = true;
285 277
 }
286 278
 
287 279
 void CardReader::stopSDPrint() {
288
-  if (sdprinting) {
289
-    sdprinting = false;
290
-    file.close();
291
-  }
280
+  sdprinting = false;
281
+  if (isFileOpen()) file.close();
292 282
 }
293 283
 
294 284
 void CardReader::openLogFile(char* name) {
@@ -310,8 +300,11 @@ void CardReader::getAbsFilename(char *t) {
310 300
 }
311 301
 
312 302
 void CardReader::openFile(char* name, bool read, bool push_current/*=false*/) {
303
+
313 304
   if (!cardOK) return;
314
-  if (file.isOpen()) { //replacing current file by new file, or subfile call
305
+
306
+  uint8_t doing = 0;
307
+  if (isFileOpen()) { //replacing current file by new file, or subfile call
315 308
     if (push_current) {
316 309
       if (file_subcall_ctr > SD_PROCEDURE_DEPTH - 1) {
317 310
         SERIAL_ERROR_START;
@@ -321,40 +314,39 @@ void CardReader::openFile(char* name, bool read, bool push_current/*=false*/) {
321 314
         return;
322 315
       }
323 316
 
324
-      SERIAL_ECHO_START;
325
-      SERIAL_ECHOPGM("SUBROUTINE CALL target:\"");
326
-      SERIAL_ECHO(name);
327
-      SERIAL_ECHOPGM("\" parent:\"");
328
-
329
-      //store current filename and position
317
+      // Store current filename and position
330 318
       getAbsFilename(proc_filenames[file_subcall_ctr]);
331 319
 
332
-      SERIAL_ECHO(proc_filenames[file_subcall_ctr]);
333
-      SERIAL_ECHOPGM("\" pos");
334
-      SERIAL_ECHOLN(sdpos);
320
+      SERIAL_ECHO_START;
321
+      SERIAL_ECHOPAIR("SUBROUTINE CALL target:\"", name);
322
+      SERIAL_ECHOPAIR("\" parent:\"", proc_filenames[file_subcall_ctr]);
323
+      SERIAL_ECHOLNPAIR("\" pos", sdpos);
335 324
       filespos[file_subcall_ctr] = sdpos;
336 325
       file_subcall_ctr++;
337 326
     }
338 327
     else {
339
-     SERIAL_ECHO_START;
340
-     SERIAL_ECHOPGM("Now doing file: ");
341
-     SERIAL_ECHOLN(name);
328
+      doing = 1;
342 329
     }
343
-    file.close();
344 330
   }
345
-  else { //opening fresh file
346
-    file_subcall_ctr = 0; //resetting procedure depth in case user cancels print while in procedure
331
+  else { // Opening fresh file
332
+    doing = 2;
333
+    file_subcall_ctr = 0; // Reset procedure depth in case user cancels print while in procedure
334
+  }
335
+
336
+  if (doing) {
347 337
     SERIAL_ECHO_START;
348
-    SERIAL_ECHOPGM("Now fresh file: ");
349
-    SERIAL_ECHOLN(name);
338
+    SERIAL_ECHOPGM("Now ");
339
+    SERIAL_ECHO(doing == 1 ? "doing" : "fresh");
340
+    SERIAL_ECHOLNPAIR(" file: ", name);
350 341
   }
351
-  sdprinting = false;
342
+
343
+  stopSDPrint();
352 344
 
353 345
   SdFile myDir;
354 346
   curDir = &root;
355 347
   char *fname = name;
356
-
357 348
   char *dirname_start, *dirname_end;
349
+
358 350
   if (name[0] == '/') {
359 351
     dirname_start = &name[1];
360 352
     while (dirname_start != NULL) {
@@ -425,8 +417,7 @@ void CardReader::openFile(char* name, bool read, bool push_current/*=false*/) {
425 417
 void CardReader::removeFile(char* name) {
426 418
   if (!cardOK) return;
427 419
 
428
-  file.close();
429
-  sdprinting = false;
420
+  stopSDPrint();
430 421
 
431 422
   SdFile myDir;
432 423
   curDir = &root;

+ 1
- 1
Marlin/cardreader.h View File

@@ -51,7 +51,6 @@ public:
51 51
   void release();
52 52
   void openAndPrintFile(const char *name);
53 53
   void startFileprint();
54
-  void pauseSDPrint();
55 54
   void stopSDPrint();
56 55
   void getStatus();
57 56
   void printingHasFinished();
@@ -70,6 +69,7 @@ public:
70 69
   void updir();
71 70
   void setroot();
72 71
 
72
+  FORCE_INLINE void pauseSDPrint() { sdprinting = false; }
73 73
   FORCE_INLINE bool isFileOpen() { return file.isOpen(); }
74 74
   FORCE_INLINE bool eof() { return sdpos >= filesize; }
75 75
   FORCE_INLINE int16_t get() { sdpos = file.curPosition(); return (int16_t)file.read(); }

Loading…
Cancel
Save