From fde51084f310d4031a415d529a93038a8c34d3ed Mon Sep 17 00:00:00 2001 From: Christian Thalhammer Date: Sat, 3 Mar 2012 21:58:12 +0100 Subject: [PATCH] set SD file delete to M30; switch printime output to M31 --- Marlin/Marlin.pde | 7 +++-- Marlin/cardreader.cpp | 69 +++++++++++++++++++++++++++++++++++++++++++ Marlin/cardreader.h | 3 +- 3 files changed, 75 insertions(+), 4 deletions(-) diff --git a/Marlin/Marlin.pde b/Marlin/Marlin.pde index 5c213e283..a3e60d408 100644 --- a/Marlin/Marlin.pde +++ b/Marlin/Marlin.pde @@ -75,7 +75,8 @@ // M27 - Report SD print status // M28 - Start SD write (M28 filename.g) // M29 - Stop SD write -// M30 - Output time since last M109 or SD card start to serial +// M30 - Delete file from SD (M30 filename.g) +// M31 - Output time since last M109 or SD card start to serial // M42 - Change pin status via gcode // M80 - Turn on Power Supply // M81 - Turn off Power Supply @@ -739,7 +740,7 @@ void process_commands() //processed in write to file routine above //card,saving = false; break; - case 30: //M31 Delete File + case 30: //M30 Delete File if (card.cardOK){ card.closefile(); starpos = (strchr(strchr_pointer + 4,'*')); @@ -754,7 +755,7 @@ void process_commands() #endif //SDSUPPORT - case 31: //M30 take time since the start of the SD print or an M109 command + case 31: //M31 take time since the start of the SD print or an M109 command { stoptime=millis(); char time[30]; diff --git a/Marlin/cardreader.cpp b/Marlin/cardreader.cpp index 052ce2030..7b0a4d245 100644 --- a/Marlin/cardreader.cpp +++ b/Marlin/cardreader.cpp @@ -295,6 +295,75 @@ void CardReader::openFile(char* name,bool read) } +void CardReader::removeFile(char* name) +{ + if(!cardOK) + return; + file.close(); + sdprinting = false; + + + SdFile myDir; + curDir=&root; + char *fname=name; + + char *dirname_start,*dirname_end; + if(name[0]=='/') + { + dirname_start=strchr(name,'/')+1; + while(dirname_start>0) + { + dirname_end=strchr(dirname_start,'/'); + //SERIAL_ECHO("start:");SERIAL_ECHOLN((int)(dirname_start-name)); + //SERIAL_ECHO("end :");SERIAL_ECHOLN((int)(dirname_end-name)); + if(dirname_end>0 && dirname_end>dirname_start) + { + char subdirname[13]; + strncpy(subdirname, dirname_start, dirname_end-dirname_start); + subdirname[dirname_end-dirname_start]=0; + SERIAL_ECHOLN(subdirname); + if(!myDir.open(curDir,subdirname,O_READ)) + { + SERIAL_PROTOCOLPGM("open failed, File: "); + SERIAL_PROTOCOL(subdirname); + SERIAL_PROTOCOLLNPGM("."); + return; + } + else + ;//SERIAL_ECHOLN("dive ok"); + + curDir=&myDir; + dirname_start=dirname_end+1; + } + else // the reminder after all /fsa/fdsa/ is the filename + { + fname=dirname_start; + //SERIAL_ECHOLN("remaider"); + //SERIAL_ECHOLN(fname); + break; + } + + } + } + else //relative path + { + curDir=&workDir; + } + if (file.remove(curDir, fname)) + { + SERIAL_PROTOCOLPGM("File deleted:"); + SERIAL_PROTOCOL(fname); + sdpos = 0; + } + else + { + SERIAL_PROTOCOLPGM("Deletion failed, File: "); + SERIAL_PROTOCOL(fname); + SERIAL_PROTOCOLLNPGM("."); + } + +} + void CardReader::getStatus() { if(cardOK){ diff --git a/Marlin/cardreader.h b/Marlin/cardreader.h index 67fe58a90..a411f3d2b 100644 --- a/Marlin/cardreader.h +++ b/Marlin/cardreader.h @@ -17,6 +17,7 @@ public: void checkautostart(bool x); void openFile(char* name,bool read); + void removeFile(char* name); void closefile(); void release(); void startFileprint(); @@ -99,4 +100,4 @@ public: FORCE_INLINE uint8_t percentDone(){return 0;}; }; #endif //SDSUPPORT -#endif \ No newline at end of file +#endif