瀏覽代碼

set SD file delete to M30; switch printime output to M31

Christian Thalhammer 13 年之前
父節點
當前提交
fde51084f3
共有 3 個文件被更改,包括 75 次插入4 次删除
  1. 4
    3
      Marlin/Marlin.pde
  2. 69
    0
      Marlin/cardreader.cpp
  3. 2
    1
      Marlin/cardreader.h

+ 4
- 3
Marlin/Marlin.pde 查看文件

@@ -75,7 +75,8 @@
75 75
 // M27  - Report SD print status
76 76
 // M28  - Start SD write (M28 filename.g)
77 77
 // M29  - Stop SD write
78
-// M30  - Output time since last M109 or SD card start to serial
78
+// M30  - Delete file from SD (M30 filename.g)
79
+// M31  - Output time since last M109 or SD card start to serial
79 80
 // M42  - Change pin status via gcode
80 81
 // M80  - Turn on Power Supply
81 82
 // M81  - Turn off Power Supply
@@ -739,7 +740,7 @@ void process_commands()
739 740
       //processed in write to file routine above
740 741
       //card,saving = false;
741 742
       break;
742
-    case 30: //M31 <filename> Delete File 
743
+    case 30: //M30 <filename> Delete File 
743 744
 	if (card.cardOK){
744 745
 		card.closefile();
745 746
 		starpos = (strchr(strchr_pointer + 4,'*'));
@@ -754,7 +755,7 @@ void process_commands()
754 755
 	
755 756
 #endif //SDSUPPORT
756 757
 
757
-    case 31: //M30 take time since the start of the SD print or an M109 command
758
+    case 31: //M31 take time since the start of the SD print or an M109 command
758 759
       {
759 760
       stoptime=millis();
760 761
       char time[30];

+ 69
- 0
Marlin/cardreader.cpp 查看文件

@@ -295,6 +295,75 @@ void CardReader::openFile(char* name,bool read)
295 295
   
296 296
 }
297 297
 
298
+void CardReader::removeFile(char* name)
299
+{
300
+  if(!cardOK)
301
+    return;
302
+  file.close();
303
+  sdprinting = false;
304
+  
305
+  
306
+  SdFile myDir;
307
+  curDir=&root;
308
+  char *fname=name;
309
+  
310
+  char *dirname_start,*dirname_end;
311
+  if(name[0]=='/')
312
+  {
313
+    dirname_start=strchr(name,'/')+1;
314
+    while(dirname_start>0)
315
+    {
316
+      dirname_end=strchr(dirname_start,'/');
317
+      //SERIAL_ECHO("start:");SERIAL_ECHOLN((int)(dirname_start-name));
318
+      //SERIAL_ECHO("end  :");SERIAL_ECHOLN((int)(dirname_end-name));
319
+      if(dirname_end>0 && dirname_end>dirname_start)
320
+      {
321
+        char subdirname[13];
322
+        strncpy(subdirname, dirname_start, dirname_end-dirname_start);
323
+        subdirname[dirname_end-dirname_start]=0;
324
+        SERIAL_ECHOLN(subdirname);
325
+        if(!myDir.open(curDir,subdirname,O_READ))
326
+        {
327
+          SERIAL_PROTOCOLPGM("open failed, File: ");
328
+          SERIAL_PROTOCOL(subdirname);
329
+          SERIAL_PROTOCOLLNPGM(".");
330
+          return;
331
+        }
332
+        else
333
+          ;//SERIAL_ECHOLN("dive ok");
334
+          
335
+        curDir=&myDir; 
336
+        dirname_start=dirname_end+1;
337
+      }
338
+      else // the reminder after all /fsa/fdsa/ is the filename
339
+      {
340
+        fname=dirname_start;
341
+        //SERIAL_ECHOLN("remaider");
342
+        //SERIAL_ECHOLN(fname);
343
+        break;
344
+      }
345
+      
346
+    }
347
+  }
348
+  else //relative path
349
+  {
350
+    curDir=&workDir;
351
+  }
352
+    if (file.remove(curDir, fname)) 
353
+    {
354
+      SERIAL_PROTOCOLPGM("File deleted:");
355
+      SERIAL_PROTOCOL(fname);
356
+      sdpos = 0;
357
+    }
358
+    else
359
+    {
360
+      SERIAL_PROTOCOLPGM("Deletion failed, File: ");
361
+      SERIAL_PROTOCOL(fname);
362
+      SERIAL_PROTOCOLLNPGM(".");
363
+    }
364
+  
365
+}
366
+
298 367
 void CardReader::getStatus()
299 368
 {
300 369
   if(cardOK){

+ 2
- 1
Marlin/cardreader.h 查看文件

@@ -17,6 +17,7 @@ public:
17 17
 
18 18
   void checkautostart(bool x); 
19 19
   void openFile(char* name,bool read);
20
+  void removeFile(char* name);
20 21
   void closefile();
21 22
   void release();
22 23
   void startFileprint();
@@ -99,4 +100,4 @@ public:
99 100
   FORCE_INLINE uint8_t percentDone(){return 0;};
100 101
 };
101 102
 #endif //SDSUPPORT
102
-#endif
103
+#endif

Loading…
取消
儲存