Browse Source

Merge pull request #3276 from thinkyhead/rc_sdprint_and_lcd_sleuth

Refinements, fixes, reduced stack usage in CardReader
Scott Lahteine 8 years ago
parent
commit
f0b96f5cae
4 changed files with 26 additions and 35 deletions
  1. 1
    1
      Marlin/Marlin_main.cpp
  2. 19
    28
      Marlin/cardreader.cpp
  3. 5
    5
      Marlin/cardreader.h
  4. 1
    1
      Marlin/ultralcd.cpp

+ 1
- 1
Marlin/Marlin_main.cpp View File

3704
     bool call_procedure = code_seen('P') && (seen_pointer < namestartpos);
3704
     bool call_procedure = code_seen('P') && (seen_pointer < namestartpos);
3705
 
3705
 
3706
     if (card.cardOK) {
3706
     if (card.cardOK) {
3707
-      card.openFile(namestartpos, true, !call_procedure);
3707
+      card.openFile(namestartpos, true, call_procedure);
3708
 
3708
 
3709
       if (code_seen('S') && seen_pointer < namestartpos) // "S" (must occur _before_ the filename!)
3709
       if (code_seen('S') && seen_pointer < namestartpos) // "S" (must occur _before_ the filename!)
3710
         card.setIndex(code_value_short());
3710
         card.setIndex(code_value_short());

+ 19
- 28
Marlin/cardreader.cpp View File

266
 }
266
 }
267
 
267
 
268
 void CardReader::openAndPrintFile(const char *name) {
268
 void CardReader::openAndPrintFile(const char *name) {
269
-  char cmd[4 + (FILENAME_LENGTH + 1) * MAX_DIR_DEPTH + 2]; // Room for "M23 ", names with slashes, a null, and one extra
269
+  char cmd[4 + strlen(name) + 1]; // Room for "M23 ", filename, and null
270
   sprintf_P(cmd, PSTR("M23 %s"), name);
270
   sprintf_P(cmd, PSTR("M23 %s"), name);
271
   for (char *c = &cmd[4]; *c; c++) *c = tolower(*c);
271
   for (char *c = &cmd[4]; *c; c++) *c = tolower(*c);
272
-  enqueue_and_echo_command_now(cmd);
272
+  enqueue_and_echo_command(cmd);
273
   enqueue_and_echo_commands_P(PSTR("M24"));
273
   enqueue_and_echo_commands_P(PSTR("M24"));
274
 }
274
 }
275
 
275
 
300
     t[0] = 0;
300
     t[0] = 0;
301
 }
301
 }
302
 
302
 
303
-void CardReader::openFile(char* name, bool read, bool replace_current/*=true*/) {
303
+void CardReader::openFile(char* name, bool read, bool push_current/*=false*/) {
304
   if (!cardOK) return;
304
   if (!cardOK) return;
305
   if (file.isOpen()) { //replacing current file by new file, or subfile call
305
   if (file.isOpen()) { //replacing current file by new file, or subfile call
306
-    if (!replace_current) {
306
+    if (push_current) {
307
       if (file_subcall_ctr > SD_PROCEDURE_DEPTH - 1) {
307
       if (file_subcall_ctr > SD_PROCEDURE_DEPTH - 1) {
308
         SERIAL_ERROR_START;
308
         SERIAL_ERROR_START;
309
         SERIAL_ERRORPGM("trying to call sub-gcode files with too many levels. MAX level is:");
309
         SERIAL_ERRORPGM("trying to call sub-gcode files with too many levels. MAX level is:");
318
       SERIAL_ECHOPGM("\" parent:\"");
318
       SERIAL_ECHOPGM("\" parent:\"");
319
 
319
 
320
       //store current filename and position
320
       //store current filename and position
321
-      getAbsFilename(filenames[file_subcall_ctr]);
321
+      getAbsFilename(proc_filenames[file_subcall_ctr]);
322
 
322
 
323
-      SERIAL_ECHO(filenames[file_subcall_ctr]);
323
+      SERIAL_ECHO(proc_filenames[file_subcall_ctr]);
324
       SERIAL_ECHOPGM("\" pos");
324
       SERIAL_ECHOPGM("\" pos");
325
       SERIAL_ECHOLN(sdpos);
325
       SERIAL_ECHOLN(sdpos);
326
       filespos[file_subcall_ctr] = sdpos;
326
       filespos[file_subcall_ctr] = sdpos;
327
       file_subcall_ctr++;
327
       file_subcall_ctr++;
328
-     }
329
-     else {
330
-      SERIAL_ECHO_START;
331
-      SERIAL_ECHOPGM("Now doing file: ");
332
-      SERIAL_ECHOLN(name);
333
-     }
334
-     file.close();
328
+    }
329
+    else {
330
+     SERIAL_ECHO_START;
331
+     SERIAL_ECHOPGM("Now doing file: ");
332
+     SERIAL_ECHOLN(name);
333
+    }
334
+    file.close();
335
   }
335
   }
336
   else { //opening fresh file
336
   else { //opening fresh file
337
     file_subcall_ctr = 0; //resetting procedure depth in case user cancels print while in procedure
337
     file_subcall_ctr = 0; //resetting procedure depth in case user cancels print while in procedure
584
     SERIAL_ECHOLN(relpath);
584
     SERIAL_ECHOLN(relpath);
585
   }
585
   }
586
   else {
586
   else {
587
-    if (workDirDepth < MAX_DIR_DEPTH) {
588
-      ++workDirDepth;
589
-      for (int d = workDirDepth; d--;) workDirParents[d + 1] = workDirParents[d];
590
-      workDirParents[0] = *parent;
591
-    }
587
+    if (workDirDepth < MAX_DIR_DEPTH)
588
+      workDirParents[workDirDepth++] = *parent;
592
     workDir = newfile;
589
     workDir = newfile;
593
   }
590
   }
594
 }
591
 }
595
 
592
 
596
 void CardReader::updir() {
593
 void CardReader::updir() {
597
-  if (workDirDepth > 0) {
598
-    --workDirDepth;
599
-    workDir = workDirParents[0];
600
-    for (uint16_t d = 0; d < workDirDepth; d++)
601
-      workDirParents[d] = workDirParents[d+1];
602
-  }
594
+  if (workDirDepth > 0)
595
+    workDir = workDirParents[--workDirDepth];
603
 }
596
 }
604
 
597
 
605
 void CardReader::printingHasFinished() {
598
 void CardReader::printingHasFinished() {
607
   if (file_subcall_ctr > 0) { // Heading up to a parent file that called current as a procedure.
600
   if (file_subcall_ctr > 0) { // Heading up to a parent file that called current as a procedure.
608
     file.close();
601
     file.close();
609
     file_subcall_ctr--;
602
     file_subcall_ctr--;
610
-    openFile(filenames[file_subcall_ctr], true, true);
603
+    openFile(proc_filenames[file_subcall_ctr], true, true);
611
     setIndex(filespos[file_subcall_ctr]);
604
     setIndex(filespos[file_subcall_ctr]);
612
     startFileprint();
605
     startFileprint();
613
   }
606
   }
614
   else {
607
   else {
615
     file.close();
608
     file.close();
616
     sdprinting = false;
609
     sdprinting = false;
617
-    if (SD_FINISHED_STEPPERRELEASE) {
618
-      //finishAndDisableSteppers();
610
+    if (SD_FINISHED_STEPPERRELEASE)
619
       enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
611
       enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
620
-    }
621
     autotempShutdown();
612
     autotempShutdown();
622
   }
613
   }
623
 }
614
 }

+ 5
- 5
Marlin/cardreader.h View File

40
   //this is to delay autostart and hence the initialisaiton of the sd card to some seconds after the normal init, so the device is available quick after a reset
40
   //this is to delay autostart and hence the initialisaiton of the sd card to some seconds after the normal init, so the device is available quick after a reset
41
 
41
 
42
   void checkautostart(bool x);
42
   void checkautostart(bool x);
43
-  void openFile(char* name,bool read,bool replace_current=true);
43
+  void openFile(char* name, bool read, bool push_current=false);
44
   void openLogFile(char* name);
44
   void openLogFile(char* name);
45
   void removeFile(char* name);
45
   void removeFile(char* name);
46
   void closefile(bool store_location=false);
46
   void closefile(bool store_location=false);
65
   void updir();
65
   void updir();
66
   void setroot();
66
   void setroot();
67
 
67
 
68
-
69
   FORCE_INLINE bool isFileOpen() { return file.isOpen(); }
68
   FORCE_INLINE bool isFileOpen() { return file.isOpen(); }
70
   FORCE_INLINE bool eof() { return sdpos >= filesize; }
69
   FORCE_INLINE bool eof() { return sdpos >= filesize; }
71
   FORCE_INLINE int16_t get() { sdpos = file.curPosition(); return (int16_t)file.read(); }
70
   FORCE_INLINE int16_t get() { sdpos = file.curPosition(); return (int16_t)file.read(); }
79
   int autostart_index;
78
   int autostart_index;
80
 private:
79
 private:
81
   SdFile root, *curDir, workDir, workDirParents[MAX_DIR_DEPTH];
80
   SdFile root, *curDir, workDir, workDirParents[MAX_DIR_DEPTH];
82
-  uint16_t workDirDepth;
81
+  uint8_t workDirDepth;
83
   Sd2Card card;
82
   Sd2Card card;
84
   SdVolume volume;
83
   SdVolume volume;
85
   SdFile file;
84
   SdFile file;
85
+
86
   #define SD_PROCEDURE_DEPTH 1
86
   #define SD_PROCEDURE_DEPTH 1
87
   #define MAXPATHNAMELENGTH (FILENAME_LENGTH*MAX_DIR_DEPTH + MAX_DIR_DEPTH + 1)
87
   #define MAXPATHNAMELENGTH (FILENAME_LENGTH*MAX_DIR_DEPTH + MAX_DIR_DEPTH + 1)
88
   uint8_t file_subcall_ctr;
88
   uint8_t file_subcall_ctr;
89
   uint32_t filespos[SD_PROCEDURE_DEPTH];
89
   uint32_t filespos[SD_PROCEDURE_DEPTH];
90
-  char filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH];
90
+  char proc_filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH];
91
   uint32_t filesize;
91
   uint32_t filesize;
92
-  millis_t next_autostart_ms;
93
   uint32_t sdpos;
92
   uint32_t sdpos;
94
 
93
 
94
+  millis_t next_autostart_ms;
95
   bool autostart_stilltocheck; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.
95
   bool autostart_stilltocheck; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.
96
 
96
 
97
   LsAction lsAction; //stored for recursion.
97
   LsAction lsAction; //stored for recursion.

+ 1
- 1
Marlin/ultralcd.cpp View File

1114
         autotune_temp[e]
1114
         autotune_temp[e]
1115
       #endif
1115
       #endif
1116
     );
1116
     );
1117
-    enqueue_and_echo_command_now(cmd);
1117
+    enqueue_and_echo_command(cmd);
1118
   }
1118
   }
1119
 
1119
 
1120
 #endif //PID_AUTOTUNE_MENU
1120
 #endif //PID_AUTOTUNE_MENU

Loading…
Cancel
Save