|
@@ -1,4 +1,5 @@
|
1
|
1
|
#include "cardreader.h"
|
|
2
|
+//#include <unistd.h>
|
2
|
3
|
#ifdef SDSUPPORT
|
3
|
4
|
|
4
|
5
|
CardReader::CardReader()
|
|
@@ -36,11 +37,7 @@ char *createFilename(char *buffer,const dir_t &p) //buffer>12characters
|
36
|
37
|
return buffer;
|
37
|
38
|
}
|
38
|
39
|
|
39
|
|
-// bool SdFat::chdir(bool set_cwd) {
|
40
|
|
-// if (set_cwd) SdBaseFile::cwd_ = &vwd_;
|
41
|
|
-// vwd_.close();
|
42
|
|
-// return vwd_.openRoot(&vol_);
|
43
|
|
-// }
|
|
40
|
+
|
44
|
41
|
void CardReader::lsDive(char *prepend,SdFile parent)
|
45
|
42
|
{
|
46
|
43
|
dir_t p;
|
|
@@ -85,11 +82,19 @@ void CardReader::lsDive(char *prepend,SdFile parent)
|
85
|
82
|
{
|
86
|
83
|
if (p.name[0] == DIR_NAME_FREE) break;
|
87
|
84
|
if (p.name[0] == DIR_NAME_DELETED || p.name[0] == '.'|| p.name[0] == '_') continue;
|
|
85
|
+ if ( p.name[0] == '.')
|
|
86
|
+ {
|
|
87
|
+ if ( p.name[1] != '.')
|
|
88
|
+ continue;
|
|
89
|
+ }
|
88
|
90
|
if (!DIR_IS_FILE_OR_SUBDIR(&p)) continue;
|
|
91
|
+ filenameIsDir=DIR_IS_SUBDIR(&p);
|
89
|
92
|
|
90
|
|
-
|
91
|
|
- if(p.name[8]!='G') continue;
|
92
|
|
- if(p.name[9]=='~') continue;
|
|
93
|
+ if(!filenameIsDir)
|
|
94
|
+ {
|
|
95
|
+ if(p.name[8]!='G') continue;
|
|
96
|
+ if(p.name[9]=='~') continue;
|
|
97
|
+ }
|
93
|
98
|
//if(cnt++!=nr) continue;
|
94
|
99
|
createFilename(filename,p);
|
95
|
100
|
if(lsAction==LS_SerialPrint)
|
|
@@ -126,33 +131,35 @@ void CardReader::ls()
|
126
|
131
|
void CardReader::initsd()
|
127
|
132
|
{
|
128
|
133
|
cardOK = false;
|
129
|
|
- #if SDSS >- 1
|
130
|
|
- if(root.isOpen())
|
131
|
|
- root.close();
|
132
|
|
- if (!card.init(SPI_FULL_SPEED,SDSS))
|
133
|
|
- {
|
134
|
|
- //if (!card.init(SPI_HALF_SPEED,SDSS))
|
135
|
|
- SERIAL_ECHO_START;
|
136
|
|
- SERIAL_ECHOLNPGM("SD init fail");
|
137
|
|
- }
|
138
|
|
- else if (!volume.init(&card))
|
139
|
|
- {
|
140
|
|
- SERIAL_ERROR_START;
|
141
|
|
- SERIAL_ERRORLNPGM("volume.init failed");
|
142
|
|
- }
|
143
|
|
- else if (!root.openRoot(&volume))
|
144
|
|
- {
|
145
|
|
- SERIAL_ERROR_START;
|
146
|
|
- SERIAL_ERRORLNPGM("openRoot failed");
|
147
|
|
- }
|
148
|
|
- else
|
149
|
|
- {
|
150
|
|
- cardOK = true;
|
151
|
|
- SERIAL_ECHO_START;
|
152
|
|
- SERIAL_ECHOLNPGM("SD card ok");
|
153
|
|
- }
|
154
|
|
- curDir=&root;
|
155
|
|
- #endif //SDSS
|
|
134
|
+ if(root.isOpen())
|
|
135
|
+ root.close();
|
|
136
|
+ if (!card.init(SPI_FULL_SPEED,SDSS))
|
|
137
|
+ {
|
|
138
|
+ //if (!card.init(SPI_HALF_SPEED,SDSS))
|
|
139
|
+ SERIAL_ECHO_START;
|
|
140
|
+ SERIAL_ECHOLNPGM("SD init fail");
|
|
141
|
+ }
|
|
142
|
+ else if (!volume.init(&card))
|
|
143
|
+ {
|
|
144
|
+ SERIAL_ERROR_START;
|
|
145
|
+ SERIAL_ERRORLNPGM("volume.init failed");
|
|
146
|
+ }
|
|
147
|
+ else if (!root.openRoot(&volume))
|
|
148
|
+ {
|
|
149
|
+ SERIAL_ERROR_START;
|
|
150
|
+ SERIAL_ERRORLNPGM("openRoot failed");
|
|
151
|
+ }
|
|
152
|
+ else
|
|
153
|
+ {
|
|
154
|
+ cardOK = true;
|
|
155
|
+ SERIAL_ECHO_START;
|
|
156
|
+ SERIAL_ECHOLNPGM("SD card ok");
|
|
157
|
+ }
|
|
158
|
+ curDir=&root;
|
|
159
|
+ if(!workDir.openRoot(&volume))
|
|
160
|
+ {
|
|
161
|
+ SERIAL_ECHOLNPGM("workDir open failed");
|
|
162
|
+ }
|
156
|
163
|
}
|
157
|
164
|
void CardReader::release()
|
158
|
165
|
{
|
|
@@ -229,6 +236,10 @@ void CardReader::openFile(char* name,bool read)
|
229
|
236
|
|
230
|
237
|
}
|
231
|
238
|
}
|
|
239
|
+ else //relative path
|
|
240
|
+ {
|
|
241
|
+ curDir=&workDir;
|
|
242
|
+ }
|
232
|
243
|
if(read)
|
233
|
244
|
{
|
234
|
245
|
if (file.open(curDir, fname, O_READ))
|
|
@@ -362,6 +373,7 @@ void CardReader::closefile()
|
362
|
373
|
|
363
|
374
|
void CardReader::getfilename(const uint8_t nr)
|
364
|
375
|
{
|
|
376
|
+ curDir=&workDir;
|
365
|
377
|
lsAction=LS_GetFilename;
|
366
|
378
|
nrFiles=nr;
|
367
|
379
|
curDir->rewind();
|
|
@@ -371,12 +383,45 @@ void CardReader::getfilename(const uint8_t nr)
|
371
|
383
|
|
372
|
384
|
uint16_t CardReader::getnrfilenames()
|
373
|
385
|
{
|
|
386
|
+ curDir=&workDir;
|
374
|
387
|
lsAction=LS_Count;
|
375
|
388
|
nrFiles=0;
|
376
|
389
|
curDir->rewind();
|
377
|
390
|
lsDive("",*curDir);
|
|
391
|
+ //SERIAL_ECHOLN(nrFiles);
|
378
|
392
|
return nrFiles;
|
379
|
393
|
}
|
380
|
394
|
|
|
395
|
+void CardReader::chdir(const char * relpath)
|
|
396
|
+{
|
|
397
|
+ SdFile newfile;
|
|
398
|
+ SdFile *parent=&root;
|
|
399
|
+
|
|
400
|
+ if(workDir.isOpen())
|
|
401
|
+ parent=&workDir;
|
|
402
|
+
|
|
403
|
+ if(!newfile.open(*parent,relpath, O_READ))
|
|
404
|
+ {
|
|
405
|
+ SERIAL_ECHO_START;
|
|
406
|
+ SERIAL_ECHOPGM("Cannot enter subdir:");
|
|
407
|
+ SERIAL_ECHOLN(relpath);
|
|
408
|
+ }
|
|
409
|
+ else
|
|
410
|
+ {
|
|
411
|
+ workDirParentParent=workDirParent;
|
|
412
|
+ workDirParent=*parent;
|
|
413
|
+
|
|
414
|
+ workDir=newfile;
|
|
415
|
+ }
|
|
416
|
+}
|
|
417
|
+
|
|
418
|
+void CardReader::updir()
|
|
419
|
+{
|
|
420
|
+ if(!workDir.isRoot())
|
|
421
|
+ {
|
|
422
|
+ workDir=workDirParent;
|
|
423
|
+ workDirParent=workDirParentParent;
|
|
424
|
+ }
|
|
425
|
+}
|
381
|
426
|
|
382
|
427
|
#endif //SDSUPPORT
|