Merge pull request #3276 from thinkyhead/rc_sdprint_and_lcd_sleuth
Refinements, fixes, reduced stack usage in CardReader
This commit is contained in:
		
						commit
						f0b96f5cae
					
				| @ -3704,7 +3704,7 @@ inline void gcode_M31() { | |||||||
|     bool call_procedure = code_seen('P') && (seen_pointer < namestartpos); |     bool call_procedure = code_seen('P') && (seen_pointer < namestartpos); | ||||||
| 
 | 
 | ||||||
|     if (card.cardOK) { |     if (card.cardOK) { | ||||||
|       card.openFile(namestartpos, true, !call_procedure); |       card.openFile(namestartpos, true, call_procedure); | ||||||
| 
 | 
 | ||||||
|       if (code_seen('S') && seen_pointer < namestartpos) // "S" (must occur _before_ the filename!)
 |       if (code_seen('S') && seen_pointer < namestartpos) // "S" (must occur _before_ the filename!)
 | ||||||
|         card.setIndex(code_value_short()); |         card.setIndex(code_value_short()); | ||||||
|  | |||||||
| @ -266,10 +266,10 @@ void CardReader::release() { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void CardReader::openAndPrintFile(const char *name) { | void CardReader::openAndPrintFile(const char *name) { | ||||||
|   char cmd[4 + (FILENAME_LENGTH + 1) * MAX_DIR_DEPTH + 2]; // Room for "M23 ", names with slashes, a null, and one extra
 |   char cmd[4 + strlen(name) + 1]; // Room for "M23 ", filename, and null
 | ||||||
|   sprintf_P(cmd, PSTR("M23 %s"), name); |   sprintf_P(cmd, PSTR("M23 %s"), name); | ||||||
|   for (char *c = &cmd[4]; *c; c++) *c = tolower(*c); |   for (char *c = &cmd[4]; *c; c++) *c = tolower(*c); | ||||||
|   enqueue_and_echo_command_now(cmd); |   enqueue_and_echo_command(cmd); | ||||||
|   enqueue_and_echo_commands_P(PSTR("M24")); |   enqueue_and_echo_commands_P(PSTR("M24")); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -300,10 +300,10 @@ void CardReader::getAbsFilename(char *t) { | |||||||
|     t[0] = 0; |     t[0] = 0; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void CardReader::openFile(char* name, bool read, bool replace_current/*=true*/) { | void CardReader::openFile(char* name, bool read, bool push_current/*=false*/) { | ||||||
|   if (!cardOK) return; |   if (!cardOK) return; | ||||||
|   if (file.isOpen()) { //replacing current file by new file, or subfile call
 |   if (file.isOpen()) { //replacing current file by new file, or subfile call
 | ||||||
|     if (!replace_current) { |     if (push_current) { | ||||||
|       if (file_subcall_ctr > SD_PROCEDURE_DEPTH - 1) { |       if (file_subcall_ctr > SD_PROCEDURE_DEPTH - 1) { | ||||||
|         SERIAL_ERROR_START; |         SERIAL_ERROR_START; | ||||||
|         SERIAL_ERRORPGM("trying to call sub-gcode files with too many levels. MAX level is:"); |         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*/) | |||||||
|       SERIAL_ECHOPGM("\" parent:\""); |       SERIAL_ECHOPGM("\" parent:\""); | ||||||
| 
 | 
 | ||||||
|       //store current filename and position
 |       //store current filename and position
 | ||||||
|       getAbsFilename(filenames[file_subcall_ctr]); |       getAbsFilename(proc_filenames[file_subcall_ctr]); | ||||||
| 
 | 
 | ||||||
|       SERIAL_ECHO(filenames[file_subcall_ctr]); |       SERIAL_ECHO(proc_filenames[file_subcall_ctr]); | ||||||
|       SERIAL_ECHOPGM("\" pos"); |       SERIAL_ECHOPGM("\" pos"); | ||||||
|       SERIAL_ECHOLN(sdpos); |       SERIAL_ECHOLN(sdpos); | ||||||
|       filespos[file_subcall_ctr] = sdpos; |       filespos[file_subcall_ctr] = sdpos; | ||||||
|       file_subcall_ctr++; |       file_subcall_ctr++; | ||||||
|      } |     } | ||||||
|      else { |     else { | ||||||
|       SERIAL_ECHO_START; |      SERIAL_ECHO_START; | ||||||
|       SERIAL_ECHOPGM("Now doing file: "); |      SERIAL_ECHOPGM("Now doing file: "); | ||||||
|       SERIAL_ECHOLN(name); |      SERIAL_ECHOLN(name); | ||||||
|      } |     } | ||||||
|      file.close(); |     file.close(); | ||||||
|   } |   } | ||||||
|   else { //opening fresh file
 |   else { //opening fresh file
 | ||||||
|     file_subcall_ctr = 0; //resetting procedure depth in case user cancels print while in procedure
 |     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) { | |||||||
|     SERIAL_ECHOLN(relpath); |     SERIAL_ECHOLN(relpath); | ||||||
|   } |   } | ||||||
|   else { |   else { | ||||||
|     if (workDirDepth < MAX_DIR_DEPTH) { |     if (workDirDepth < MAX_DIR_DEPTH) | ||||||
|       ++workDirDepth; |       workDirParents[workDirDepth++] = *parent; | ||||||
|       for (int d = workDirDepth; d--;) workDirParents[d + 1] = workDirParents[d]; |  | ||||||
|       workDirParents[0] = *parent; |  | ||||||
|     } |  | ||||||
|     workDir = newfile; |     workDir = newfile; | ||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void CardReader::updir() { | void CardReader::updir() { | ||||||
|   if (workDirDepth > 0) { |   if (workDirDepth > 0) | ||||||
|     --workDirDepth; |     workDir = workDirParents[--workDirDepth]; | ||||||
|     workDir = workDirParents[0]; |  | ||||||
|     for (uint16_t d = 0; d < workDirDepth; d++) |  | ||||||
|       workDirParents[d] = workDirParents[d+1]; |  | ||||||
|   } |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void CardReader::printingHasFinished() { | void CardReader::printingHasFinished() { | ||||||
| @ -607,17 +600,15 @@ void CardReader::printingHasFinished() { | |||||||
|   if (file_subcall_ctr > 0) { // Heading up to a parent file that called current as a procedure.
 |   if (file_subcall_ctr > 0) { // Heading up to a parent file that called current as a procedure.
 | ||||||
|     file.close(); |     file.close(); | ||||||
|     file_subcall_ctr--; |     file_subcall_ctr--; | ||||||
|     openFile(filenames[file_subcall_ctr], true, true); |     openFile(proc_filenames[file_subcall_ctr], true, true); | ||||||
|     setIndex(filespos[file_subcall_ctr]); |     setIndex(filespos[file_subcall_ctr]); | ||||||
|     startFileprint(); |     startFileprint(); | ||||||
|   } |   } | ||||||
|   else { |   else { | ||||||
|     file.close(); |     file.close(); | ||||||
|     sdprinting = false; |     sdprinting = false; | ||||||
|     if (SD_FINISHED_STEPPERRELEASE) { |     if (SD_FINISHED_STEPPERRELEASE) | ||||||
|       //finishAndDisableSteppers();
 |  | ||||||
|       enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND)); |       enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND)); | ||||||
|     } |  | ||||||
|     autotempShutdown(); |     autotempShutdown(); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  | |||||||
| @ -40,7 +40,7 @@ public: | |||||||
|   //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
 |   //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
 | ||||||
| 
 | 
 | ||||||
|   void checkautostart(bool x); |   void checkautostart(bool x); | ||||||
|   void openFile(char* name,bool read,bool replace_current=true); |   void openFile(char* name, bool read, bool push_current=false); | ||||||
|   void openLogFile(char* name); |   void openLogFile(char* name); | ||||||
|   void removeFile(char* name); |   void removeFile(char* name); | ||||||
|   void closefile(bool store_location=false); |   void closefile(bool store_location=false); | ||||||
| @ -65,7 +65,6 @@ public: | |||||||
|   void updir(); |   void updir(); | ||||||
|   void setroot(); |   void setroot(); | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|   FORCE_INLINE bool isFileOpen() { return file.isOpen(); } |   FORCE_INLINE bool isFileOpen() { return file.isOpen(); } | ||||||
|   FORCE_INLINE bool eof() { return sdpos >= filesize; } |   FORCE_INLINE bool eof() { return sdpos >= filesize; } | ||||||
|   FORCE_INLINE int16_t get() { sdpos = file.curPosition(); return (int16_t)file.read(); } |   FORCE_INLINE int16_t get() { sdpos = file.curPosition(); return (int16_t)file.read(); } | ||||||
| @ -79,19 +78,20 @@ public: | |||||||
|   int autostart_index; |   int autostart_index; | ||||||
| private: | private: | ||||||
|   SdFile root, *curDir, workDir, workDirParents[MAX_DIR_DEPTH]; |   SdFile root, *curDir, workDir, workDirParents[MAX_DIR_DEPTH]; | ||||||
|   uint16_t workDirDepth; |   uint8_t workDirDepth; | ||||||
|   Sd2Card card; |   Sd2Card card; | ||||||
|   SdVolume volume; |   SdVolume volume; | ||||||
|   SdFile file; |   SdFile file; | ||||||
|  | 
 | ||||||
|   #define SD_PROCEDURE_DEPTH 1 |   #define SD_PROCEDURE_DEPTH 1 | ||||||
|   #define MAXPATHNAMELENGTH (FILENAME_LENGTH*MAX_DIR_DEPTH + MAX_DIR_DEPTH + 1) |   #define MAXPATHNAMELENGTH (FILENAME_LENGTH*MAX_DIR_DEPTH + MAX_DIR_DEPTH + 1) | ||||||
|   uint8_t file_subcall_ctr; |   uint8_t file_subcall_ctr; | ||||||
|   uint32_t filespos[SD_PROCEDURE_DEPTH]; |   uint32_t filespos[SD_PROCEDURE_DEPTH]; | ||||||
|   char filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH]; |   char proc_filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH]; | ||||||
|   uint32_t filesize; |   uint32_t filesize; | ||||||
|   millis_t next_autostart_ms; |  | ||||||
|   uint32_t sdpos; |   uint32_t sdpos; | ||||||
| 
 | 
 | ||||||
|  |   millis_t next_autostart_ms; | ||||||
|   bool autostart_stilltocheck; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.
 |   bool autostart_stilltocheck; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.
 | ||||||
| 
 | 
 | ||||||
|   LsAction lsAction; //stored for recursion.
 |   LsAction lsAction; //stored for recursion.
 | ||||||
|  | |||||||
| @ -1114,7 +1114,7 @@ static void lcd_control_menu() { | |||||||
|         autotune_temp[e] |         autotune_temp[e] | ||||||
|       #endif |       #endif | ||||||
|     ); |     ); | ||||||
|     enqueue_and_echo_command_now(cmd); |     enqueue_and_echo_command(cmd); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
| #endif //PID_AUTOTUNE_MENU
 | #endif //PID_AUTOTUNE_MENU
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user