chiark / gitweb /
set SD file delete to M30; switch printime output to M31
authorChristian Thalhammer <christian_thalhammer@gmx.at>
Sat, 3 Mar 2012 20:58:12 +0000 (21:58 +0100)
committerChristian Thalhammer <christian_thalhammer@gmx.at>
Sat, 3 Mar 2012 20:58:12 +0000 (21:58 +0100)
Marlin/Marlin.pde
Marlin/cardreader.cpp
Marlin/cardreader.h

index 5c213e2838d4c11e709fe04c82cf199c298c6a3f..a3e60d4081b5e589a9226432a3c72e2be082a5da 100644 (file)
@@ -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 <filename> Delete File 
+    case 30: //M30 <filename> 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];
index 052ce2030226952a076395bcdb5621535ba39fd0..7b0a4d24590b69d3cafde2b403a3a783f1df5ee9 100644 (file)
@@ -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){
index 67fe58a90a69cc17b340d67becda040e61ac51e2..a411f3d2b026fef32e0e99d1c8d218de798eb102 100644 (file)
@@ -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