Browse Source

Squish some CardReader code

Scott Lahteine 8 years ago
parent
commit
192ac2dfd7
2 changed files with 46 additions and 48 deletions
  1. 25
    26
      Marlin/Marlin.h
  2. 21
    22
      Marlin/cardreader.cpp

+ 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);

+ 21
- 22
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));
@@ -303,8 +300,11 @@ void CardReader::getAbsFilename(char *t) {
303 300
 }
304 301
 
305 302
 void CardReader::openFile(char* name, bool read, bool push_current/*=false*/) {
303
+
306 304
   if (!cardOK) return;
307
-  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
308 308
     if (push_current) {
309 309
       if (file_subcall_ctr > SD_PROCEDURE_DEPTH - 1) {
310 310
         SERIAL_ERROR_START;
@@ -314,31 +314,30 @@ void CardReader::openFile(char* name, bool read, bool push_current/*=false*/) {
314 314
         return;
315 315
       }
316 316
 
317
-      SERIAL_ECHO_START;
318
-      SERIAL_ECHOPGM("SUBROUTINE CALL target:\"");
319
-      SERIAL_ECHO(name);
320
-      SERIAL_ECHOPGM("\" parent:\"");
321
-
322
-      //store current filename and position
317
+      // Store current filename and position
323 318
       getAbsFilename(proc_filenames[file_subcall_ctr]);
324 319
 
325
-      SERIAL_ECHO(proc_filenames[file_subcall_ctr]);
326
-      SERIAL_ECHOPGM("\" pos");
327
-      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);
328 324
       filespos[file_subcall_ctr] = sdpos;
329 325
       file_subcall_ctr++;
330 326
     }
331 327
     else {
332
-     SERIAL_ECHO_START;
333
-     SERIAL_ECHOPGM("Now doing file: ");
334
-     SERIAL_ECHOLN(name);
328
+      doing = 1;
335 329
     }
336 330
   }
337
-  else { //opening fresh file
338
-    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) {
339 337
     SERIAL_ECHO_START;
340
-    SERIAL_ECHOPGM("Now fresh file: ");
341
-    SERIAL_ECHOLN(name);
338
+    SERIAL_ECHOPGM("Now ");
339
+    SERIAL_ECHO(doing == 1 ? "doing" : "fresh");
340
+    SERIAL_ECHOLNPAIR(" file: ", name);
342 341
   }
343 342
 
344 343
   stopSDPrint();
@@ -346,8 +345,8 @@ void CardReader::openFile(char* name, bool read, bool push_current/*=false*/) {
346 345
   SdFile myDir;
347 346
   curDir = &root;
348 347
   char *fname = name;
349
-
350 348
   char *dirname_start, *dirname_end;
349
+
351 350
   if (name[0] == '/') {
352 351
     dirname_start = &name[1];
353 352
     while (dirname_start != NULL) {

Loading…
Cancel
Save