ソースを参照

host-based sd card printing seems now to work with folders

Bernhard Kubicek 12年前
コミット
869cee74e6
1個のファイルの変更72行の追加29行の削除
  1. 72
    29
      Marlin/cardreader.pde

+ 72
- 29
Marlin/cardreader.pde ファイルの表示

@@ -64,7 +64,7 @@ void  CardReader::lsDive(char *prepend,SdFile parent)
64 64
       strcat(path,lfilename);
65 65
       strcat(path,"/");
66 66
       
67
-      Serial.print(path);
67
+      //Serial.print(path);
68 68
       
69 69
       SdFile dir;
70 70
       if(!dir.open(parent,lfilename, O_READ))
@@ -81,30 +81,33 @@ void  CardReader::lsDive(char *prepend,SdFile parent)
81 81
 
82 82
       
83 83
     }
84
-    if (p.name[0] == DIR_NAME_FREE) break;
85
-    if (p.name[0] == DIR_NAME_DELETED || p.name[0] == '.'|| p.name[0] == '_') continue;
86
-    if (!DIR_IS_FILE_OR_SUBDIR(&p)) continue;
87
-    
88
-    
89
-    if(p.name[8]!='G') continue;
90
-    if(p.name[9]=='~') continue;
91
-    //if(cnt++!=nr) continue;
92
-    createFilename(filename,p);
93
-    if(lsAction==LS_SerialPrint)
94
-    {
95
-      SERIAL_PROTOCOL(prepend);
96
-      SERIAL_PROTOCOLLN(filename);
97
-    }
98
-    else if(lsAction==LS_Count)
99
-    {
100
-      nrFiles++;
101
-    } 
102
-    else if(lsAction==LS_GetFilename)
84
+    else
103 85
     {
104
-      if(cnt==nrFiles)
105
-        return;
106
-      cnt++;
86
+      if (p.name[0] == DIR_NAME_FREE) break;
87
+      if (p.name[0] == DIR_NAME_DELETED || p.name[0] == '.'|| p.name[0] == '_') continue;
88
+      if (!DIR_IS_FILE_OR_SUBDIR(&p)) continue;
89
+      
107 90
       
91
+      if(p.name[8]!='G') continue;
92
+      if(p.name[9]=='~') continue;
93
+      //if(cnt++!=nr) continue;
94
+      createFilename(filename,p);
95
+      if(lsAction==LS_SerialPrint)
96
+      {
97
+        SERIAL_PROTOCOL(prepend);
98
+        SERIAL_PROTOCOLLN(filename);
99
+      }
100
+      else if(lsAction==LS_Count)
101
+      {
102
+        nrFiles++;
103
+      } 
104
+      else if(lsAction==LS_GetFilename)
105
+      {
106
+        if(cnt==nrFiles)
107
+          return;
108
+        cnt++;
109
+        
110
+      }
108 111
     }
109 112
   }
110 113
 }
@@ -180,17 +183,57 @@ void CardReader::openFile(char* name,bool read)
180 183
 {
181 184
   if(!cardOK)
182 185
     return;
183
-  
184
-    
185 186
   file.close();
186 187
   sdprinting = false;
188
+  
189
+  
190
+  SdFile myDir;
191
+  curDir=&root;
192
+  char *fname=name;
193
+  
194
+  char *dirname_start,*dirname_end;
195
+  dirname_start=strchr(name,'/')+1;
196
+  while(dirname_start!=NULL)
197
+  {
198
+    dirname_end=strchr(dirname_start,'/');
199
+    //SERIAL_ECHO("start:");SERIAL_ECHOLN((int)(dirname_start-name));
200
+    //SERIAL_ECHO("end  :");SERIAL_ECHOLN((int)(dirname_end-name));
201
+    if(dirname_end!=NULL && dirname_end>dirname_start)
202
+    {
203
+      char subdirname[13];
204
+      strncpy(subdirname, dirname_start, dirname_end-dirname_start);
205
+      subdirname[dirname_end-dirname_start]=0;
206
+      SERIAL_ECHOLN(subdirname);
207
+      if(!myDir.open(curDir,subdirname,O_READ))
208
+      {
209
+        SERIAL_PROTOCOLPGM("open failed, File: ");
210
+        SERIAL_PROTOCOL(subdirname);
211
+        SERIAL_PROTOCOLLNPGM(".");
212
+        return;
213
+      }
214
+      else
215
+        SERIAL_ECHOLN("dive ok");
216
+        
217
+      curDir=&myDir; 
218
+      dirname_start=dirname_end+1;
219
+    }
220
+    else // the reminder after all /fsa/fdsa/ is the filename
221
+    {
222
+      fname=dirname_start;
223
+      //SERIAL_ECHOLN("remaider");
224
+      //SERIAL_ECHOLN(fname);
225
+      break;
226
+    }
227
+    
228
+  }
229
+ 
187 230
   if(read)
188 231
   {
189
-    if (file.open(&root, name, O_READ)) 
232
+    if (file.open(curDir, fname, O_READ)) 
190 233
     {
191 234
       filesize = file.fileSize();
192 235
       SERIAL_PROTOCOLPGM("File opened:");
193
-      SERIAL_PROTOCOL(name);
236
+      SERIAL_PROTOCOL(fname);
194 237
       SERIAL_PROTOCOLPGM(" Size:");
195 238
       SERIAL_PROTOCOLLN(filesize);
196 239
       sdpos = 0;
@@ -204,10 +247,10 @@ void CardReader::openFile(char* name,bool read)
204 247
   }
205 248
   else 
206 249
   { //write
207
-    if (!file.open(&root, name, O_CREAT | O_APPEND | O_WRITE | O_TRUNC))
250
+    if (!file.open(curDir, fname, O_CREAT | O_APPEND | O_WRITE | O_TRUNC))
208 251
     {
209 252
       SERIAL_PROTOCOLPGM("open failed, File: ");
210
-      SERIAL_PROTOCOL(name);
253
+      SERIAL_PROTOCOL(fname);
211 254
       SERIAL_PROTOCOLLNPGM(".");
212 255
     }
213 256
     else

読み込み中…
キャンセル
保存