Ver código fonte

Merge pull request #3276 from thinkyhead/rc_sdprint_and_lcd_sleuth

Refinements, fixes, reduced stack usage in CardReader
Scott Lahteine 8 anos atrás
pai
commit
f0b96f5cae
4 arquivos alterados com 26 adições e 35 exclusões
  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 Ver arquivo

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

+ 19
- 28
Marlin/cardreader.cpp Ver arquivo

@@ -266,10 +266,10 @@ void CardReader::release() {
266 266
 }
267 267
 
268 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 270
   sprintf_P(cmd, PSTR("M23 %s"), name);
271 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 273
   enqueue_and_echo_commands_P(PSTR("M24"));
274 274
 }
275 275
 
@@ -300,10 +300,10 @@ void CardReader::getAbsFilename(char *t) {
300 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 304
   if (!cardOK) return;
305 305
   if (file.isOpen()) { //replacing current file by new file, or subfile call
306
-    if (!replace_current) {
306
+    if (push_current) {
307 307
       if (file_subcall_ctr > SD_PROCEDURE_DEPTH - 1) {
308 308
         SERIAL_ERROR_START;
309 309
         SERIAL_ERRORPGM("trying to call sub-gcode files with too many levels. MAX level is:");
@@ -318,20 +318,20 @@ void CardReader::openFile(char* name, bool read, bool replace_current/*=true*/)
318 318
       SERIAL_ECHOPGM("\" parent:\"");
319 319
 
320 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 324
       SERIAL_ECHOPGM("\" pos");
325 325
       SERIAL_ECHOLN(sdpos);
326 326
       filespos[file_subcall_ctr] = sdpos;
327 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 336
   else { //opening fresh file
337 337
     file_subcall_ctr = 0; //resetting procedure depth in case user cancels print while in procedure
@@ -584,22 +584,15 @@ void CardReader::chdir(const char * relpath) {
584 584
     SERIAL_ECHOLN(relpath);
585 585
   }
586 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 589
     workDir = newfile;
593 590
   }
594 591
 }
595 592
 
596 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 598
 void CardReader::printingHasFinished() {
@@ -607,17 +600,15 @@ void CardReader::printingHasFinished() {
607 600
   if (file_subcall_ctr > 0) { // Heading up to a parent file that called current as a procedure.
608 601
     file.close();
609 602
     file_subcall_ctr--;
610
-    openFile(filenames[file_subcall_ctr], true, true);
603
+    openFile(proc_filenames[file_subcall_ctr], true, true);
611 604
     setIndex(filespos[file_subcall_ctr]);
612 605
     startFileprint();
613 606
   }
614 607
   else {
615 608
     file.close();
616 609
     sdprinting = false;
617
-    if (SD_FINISHED_STEPPERRELEASE) {
618
-      //finishAndDisableSteppers();
610
+    if (SD_FINISHED_STEPPERRELEASE)
619 611
       enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
620
-    }
621 612
     autotempShutdown();
622 613
   }
623 614
 }

+ 5
- 5
Marlin/cardreader.h Ver arquivo

@@ -40,7 +40,7 @@ public:
40 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 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 44
   void openLogFile(char* name);
45 45
   void removeFile(char* name);
46 46
   void closefile(bool store_location=false);
@@ -65,7 +65,6 @@ public:
65 65
   void updir();
66 66
   void setroot();
67 67
 
68
-
69 68
   FORCE_INLINE bool isFileOpen() { return file.isOpen(); }
70 69
   FORCE_INLINE bool eof() { return sdpos >= filesize; }
71 70
   FORCE_INLINE int16_t get() { sdpos = file.curPosition(); return (int16_t)file.read(); }
@@ -79,19 +78,20 @@ public:
79 78
   int autostart_index;
80 79
 private:
81 80
   SdFile root, *curDir, workDir, workDirParents[MAX_DIR_DEPTH];
82
-  uint16_t workDirDepth;
81
+  uint8_t workDirDepth;
83 82
   Sd2Card card;
84 83
   SdVolume volume;
85 84
   SdFile file;
85
+
86 86
   #define SD_PROCEDURE_DEPTH 1
87 87
   #define MAXPATHNAMELENGTH (FILENAME_LENGTH*MAX_DIR_DEPTH + MAX_DIR_DEPTH + 1)
88 88
   uint8_t file_subcall_ctr;
89 89
   uint32_t filespos[SD_PROCEDURE_DEPTH];
90
-  char filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH];
90
+  char proc_filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH];
91 91
   uint32_t filesize;
92
-  millis_t next_autostart_ms;
93 92
   uint32_t sdpos;
94 93
 
94
+  millis_t next_autostart_ms;
95 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 97
   LsAction lsAction; //stored for recursion.

+ 1
- 1
Marlin/ultralcd.cpp Ver arquivo

@@ -1114,7 +1114,7 @@ static void lcd_control_menu() {
1114 1114
         autotune_temp[e]
1115 1115
       #endif
1116 1116
     );
1117
-    enqueue_and_echo_command_now(cmd);
1117
+    enqueue_and_echo_command(cmd);
1118 1118
   }
1119 1119
 
1120 1120
 #endif //PID_AUTOTUNE_MENU

Carregando…
Cancelar
Salvar