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
4 changed files with 26 additions and 35 deletions
|
@ -3704,7 +3704,7 @@ inline void gcode_M31() {
|
|||
bool call_procedure = code_seen('P') && (seen_pointer < namestartpos);
|
||||
|
||||
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!)
|
||||
card.setIndex(code_value_short());
|
||||
|
|
|
@ -266,10 +266,10 @@ void CardReader::release() {
|
|||
}
|
||||
|
||||
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);
|
||||
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"));
|
||||
}
|
||||
|
||||
|
@ -300,10 +300,10 @@ void CardReader::getAbsFilename(char *t) {
|
|||
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 (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) {
|
||||
SERIAL_ERROR_START;
|
||||
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:\"");
|
||||
|
||||
//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_ECHOLN(sdpos);
|
||||
filespos[file_subcall_ctr] = sdpos;
|
||||
file_subcall_ctr++;
|
||||
}
|
||||
else {
|
||||
SERIAL_ECHO_START;
|
||||
SERIAL_ECHOPGM("Now doing file: ");
|
||||
SERIAL_ECHOLN(name);
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
else {
|
||||
SERIAL_ECHO_START;
|
||||
SERIAL_ECHOPGM("Now doing file: ");
|
||||
SERIAL_ECHOLN(name);
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
else { //opening fresh file
|
||||
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);
|
||||
}
|
||||
else {
|
||||
if (workDirDepth < MAX_DIR_DEPTH) {
|
||||
++workDirDepth;
|
||||
for (int d = workDirDepth; d--;) workDirParents[d + 1] = workDirParents[d];
|
||||
workDirParents[0] = *parent;
|
||||
}
|
||||
if (workDirDepth < MAX_DIR_DEPTH)
|
||||
workDirParents[workDirDepth++] = *parent;
|
||||
workDir = newfile;
|
||||
}
|
||||
}
|
||||
|
||||
void CardReader::updir() {
|
||||
if (workDirDepth > 0) {
|
||||
--workDirDepth;
|
||||
workDir = workDirParents[0];
|
||||
for (uint16_t d = 0; d < workDirDepth; d++)
|
||||
workDirParents[d] = workDirParents[d+1];
|
||||
}
|
||||
if (workDirDepth > 0)
|
||||
workDir = workDirParents[--workDirDepth];
|
||||
}
|
||||
|
||||
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.
|
||||
file.close();
|
||||
file_subcall_ctr--;
|
||||
openFile(filenames[file_subcall_ctr], true, true);
|
||||
openFile(proc_filenames[file_subcall_ctr], true, true);
|
||||
setIndex(filespos[file_subcall_ctr]);
|
||||
startFileprint();
|
||||
}
|
||||
else {
|
||||
file.close();
|
||||
sdprinting = false;
|
||||
if (SD_FINISHED_STEPPERRELEASE) {
|
||||
//finishAndDisableSteppers();
|
||||
if (SD_FINISHED_STEPPERRELEASE)
|
||||
enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
|
||||
}
|
||||
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
|
||||
|
||||
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 removeFile(char* name);
|
||||
void closefile(bool store_location=false);
|
||||
|
@ -65,7 +65,6 @@ public:
|
|||
void updir();
|
||||
void setroot();
|
||||
|
||||
|
||||
FORCE_INLINE bool isFileOpen() { return file.isOpen(); }
|
||||
FORCE_INLINE bool eof() { return sdpos >= filesize; }
|
||||
FORCE_INLINE int16_t get() { sdpos = file.curPosition(); return (int16_t)file.read(); }
|
||||
|
@ -79,19 +78,20 @@ public:
|
|||
int autostart_index;
|
||||
private:
|
||||
SdFile root, *curDir, workDir, workDirParents[MAX_DIR_DEPTH];
|
||||
uint16_t workDirDepth;
|
||||
uint8_t workDirDepth;
|
||||
Sd2Card card;
|
||||
SdVolume volume;
|
||||
SdFile file;
|
||||
|
||||
#define SD_PROCEDURE_DEPTH 1
|
||||
#define MAXPATHNAMELENGTH (FILENAME_LENGTH*MAX_DIR_DEPTH + MAX_DIR_DEPTH + 1)
|
||||
uint8_t file_subcall_ctr;
|
||||
uint32_t filespos[SD_PROCEDURE_DEPTH];
|
||||
char filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH];
|
||||
char proc_filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH];
|
||||
uint32_t filesize;
|
||||
millis_t next_autostart_ms;
|
||||
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.
|
||||
|
||||
LsAction lsAction; //stored for recursion.
|
||||
|
|
|
@ -1114,7 +1114,7 @@ static void lcd_control_menu() {
|
|||
autotune_temp[e]
|
||||
#endif
|
||||
);
|
||||
enqueue_and_echo_command_now(cmd);
|
||||
enqueue_and_echo_command(cmd);
|
||||
}
|
||||
|
||||
#endif //PID_AUTOTUNE_MENU
|
||||
|
|
Reference in a new issue