Bladeren bron

overworked cardreader for folder support; not finished yet.

Bernhard Kubicek 13 jaren geleden
bovenliggende
commit
70abca195a
5 gewijzigde bestanden met toevoegingen van 154 en 474 verwijderingen
  1. 3
    2
      Marlin/Marlin.pde
  2. 0
    329
      Marlin/SdFat.cpp
  3. 0
    76
      Marlin/SdFat.h
  4. 15
    10
      Marlin/cardreader.h
  5. 136
    57
      Marlin/cardreader.pde

+ 3
- 2
Marlin/Marlin.pde Bestand weergeven

@@ -176,6 +176,7 @@ static unsigned long stoptime=0;
176 176
 //=============================ROUTINES=============================
177 177
 //===========================================================================
178 178
 
179
+void get_arc_coordinates();
179 180
 
180 181
 extern "C"{
181 182
   extern unsigned int __bss_end;
@@ -588,7 +589,7 @@ inline void process_commands()
588 589
       starpos = (strchr(strchr_pointer + 4,'*'));
589 590
       if(starpos!=NULL)
590 591
         *(starpos-1)='\0';
591
-      card.selectFile(strchr_pointer + 4);
592
+      card.openFile(strchr_pointer + 4,true);
592 593
       break;
593 594
     case 24: //M24 - Start SD print
594 595
       card.startFileprint();
@@ -613,7 +614,7 @@ inline void process_commands()
613 614
         strchr_pointer = strchr(npos,' ') + 1;
614 615
         *(starpos-1) = '\0';
615 616
       }
616
-      card.startFilewrite(strchr_pointer+4);
617
+      card.openFile(strchr_pointer+4,false);
617 618
       
618 619
       break;
619 620
     case 29: //M29 - Stop SD write

+ 0
- 329
Marlin/SdFat.cpp Bestand weergeven

@@ -1,329 +0,0 @@
1
-/* Arduino SdFat Library
2
- * Copyright (C) 2009 by William Greiman
3
- *
4
- * This file is part of the Arduino SdFat Library
5
- *
6
- * This Library is free software: you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation, either version 3 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * This Library is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License
17
- * along with the Arduino SdFat Library.  If not, see
18
- * <http://www.gnu.org/licenses/>.
19
- */
20
-#include "SdFat.h"
21
-#include "SdFatUtil.h"
22
-//------------------------------------------------------------------------------
23
-/** Change a volume's working directory to root
24
- *
25
- * Changes the volume's working directory to the SD's root directory.
26
- * Optionally set the current working directory to the volume's
27
- * working directory.
28
- *
29
- * \param[in] set_cwd Set the current working directory to this volume's
30
- *  working directory if true.
31
- *
32
- * \return The value one, true, is returned for success and
33
- * the value zero, false, is returned for failure.
34
- */
35
-bool SdFat::chdir(bool set_cwd) {
36
-  if (set_cwd) SdBaseFile::cwd_ = &vwd_;
37
-  vwd_.close();
38
-  return vwd_.openRoot(&vol_);
39
-}
40
-//------------------------------------------------------------------------------
41
-/** Change a volume's working directory
42
- *
43
- * Changes the volume working directory to the \a path subdirectory.
44
- * Optionally set the current working directory to the volume's
45
- * working directory.
46
- *
47
- * Example: If the volume's working directory is "/DIR", chdir("SUB")
48
- * will change the volume's working directory from "/DIR" to "/DIR/SUB".
49
- *
50
- * If path is "/", the volume's working directory will be changed to the
51
- * root directory
52
- *
53
- * \param[in] path The name of the subdirectory.
54
- *
55
- * \param[in] set_cwd Set the current working directory to this volume's
56
- *  working directory if true.
57
- *
58
- * \return The value one, true, is returned for success and
59
- * the value zero, false, is returned for failure.
60
- */
61
-bool SdFat::chdir(const char *path, bool set_cwd) {
62
-  SdBaseFile dir;
63
-  if (path[0] == '/' && path[1] == '\0') return chdir(set_cwd);
64
-  if (!dir.open(&vwd_, path, O_READ)) goto fail;
65
-  if (!dir.isDir()) goto fail;
66
-  vwd_ = dir;
67
-  if (set_cwd) SdBaseFile::cwd_ = &vwd_;
68
-  return true;
69
-
70
- fail:
71
-  return false;
72
-}
73
-//------------------------------------------------------------------------------
74
-/** Set the current working directory to a volume's working directory.
75
- *
76
- * This is useful with multiple SD cards.
77
- *
78
- * The current working directory is changed to this volume's working directory.
79
- *
80
- * This is like the Windows/DOS \<drive letter>: command.
81
- */
82
-void SdFat::chvol() {
83
-  SdBaseFile::cwd_ = &vwd_;
84
-}
85
-//------------------------------------------------------------------------------
86
-/** %Print any SD error code and halt. */
87
-void SdFat::errorHalt() {
88
-  errorPrint();
89
-  while (1);
90
-}
91
-//------------------------------------------------------------------------------
92
-/** %Print msg, any SD error code, and halt.
93
- *
94
- * \param[in] msg Message to print.
95
- */
96
-void SdFat::errorHalt(char const* msg) {
97
-  errorPrint(msg);
98
-  while (1);
99
-}
100
-//------------------------------------------------------------------------------
101
-/** %Print msg, any SD error code, and halt.
102
- *
103
- * \param[in] msg Message in program space (flash memory) to print.
104
- */
105
-void SdFat::errorHalt_P(PGM_P msg) {
106
-  errorPrint_P(msg);
107
-  while (1);
108
-}
109
-//------------------------------------------------------------------------------
110
-/** %Print any SD error code. */
111
-void SdFat::errorPrint() {
112
-  if (!card_.errorCode()) return;
113
-  PgmPrint("SD errorCode: 0X");
114
-  Serial.println(card_.errorCode(), HEX);
115
-}
116
-//------------------------------------------------------------------------------
117
-/** %Print msg, any SD error code.
118
- *
119
- * \param[in] msg Message to print.
120
- */
121
-void SdFat::errorPrint(char const* msg) {
122
-  PgmPrint("error: ");
123
-  Serial.println(msg);
124
-  errorPrint();
125
-}
126
-//------------------------------------------------------------------------------
127
-/** %Print msg, any SD error code.
128
- *
129
- * \param[in] msg Message in program space (flash memory) to print.
130
- */
131
-void SdFat::errorPrint_P(PGM_P msg) {
132
-  PgmPrint("error: ");
133
-  SerialPrintln_P(msg);
134
-  errorPrint();
135
-}
136
-//------------------------------------------------------------------------------
137
-/**
138
- * Test for the existence of a file.
139
- *
140
- * \param[in] name Name of the file to be tested for.
141
- *
142
- * \return true if the file exists else false.
143
- */
144
-bool SdFat::exists(const char* name) {
145
-  return vwd_.exists(name);
146
-}
147
-//------------------------------------------------------------------------------
148
-/**
149
- * Initialize an SdFat object.
150
- *
151
- * Initializes the SD card, SD volume, and root directory.
152
- *
153
- * \param[in] sckRateID value for SPI SCK rate. See Sd2Card::init().
154
- * \param[in] chipSelectPin SD chip select pin. See Sd2Card::init().
155
- *
156
- * \return The value one, true, is returned for success and
157
- * the value zero, false, is returned for failure.
158
- */
159
-bool SdFat::init(uint8_t sckRateID, uint8_t chipSelectPin) {
160
-  return card_.init(sckRateID, chipSelectPin) && vol_.init(&card_) && chdir(1);
161
-}
162
-//------------------------------------------------------------------------------
163
-/** %Print error details and halt after SdFat::init() fails. */
164
-void SdFat::initErrorHalt() {
165
-  initErrorPrint();
166
-  while (1);
167
-}
168
-//------------------------------------------------------------------------------
169
-/**Print message, error details, and halt after SdFat::init() fails.
170
- *
171
- * \param[in] msg Message to print.
172
- */
173
-void SdFat::initErrorHalt(char const *msg) {
174
-  Serial.println(msg);
175
-  initErrorHalt();
176
-}
177
-//------------------------------------------------------------------------------
178
-/**Print message, error details, and halt after SdFat::init() fails.
179
- *
180
- * \param[in] msg Message in program space (flash memory) to print.
181
- */
182
-void SdFat::initErrorHalt_P(PGM_P msg) {
183
-  SerialPrintln_P(msg);
184
-  initErrorHalt();
185
-}
186
-//------------------------------------------------------------------------------
187
-/** Print error details after SdFat::init() fails. */
188
-void SdFat::initErrorPrint() {
189
-  if (card_.errorCode()) {
190
-    PgmPrintln("Can't access SD card. Do not reformat.");
191
-    if (card_.errorCode() == SD_CARD_ERROR_CMD0) {
192
-      PgmPrintln("No card, wrong chip select pin, or SPI problem?");
193
-    }
194
-    errorPrint();
195
-  } else if (vol_.fatType() == 0) {
196
-    PgmPrintln("Invalid format, reformat SD.");
197
-  } else if (!vwd_.isOpen()) {
198
-    PgmPrintln("Can't open root directory.");
199
-  } else {
200
-    PgmPrintln("No error found.");
201
-  }
202
-}
203
-//------------------------------------------------------------------------------
204
-/**Print message and error details and halt after SdFat::init() fails.
205
- *
206
- * \param[in] msg Message to print.
207
- */
208
-void SdFat::initErrorPrint(char const *msg) {
209
-  Serial.println(msg);
210
-  initErrorPrint();
211
-}
212
-//------------------------------------------------------------------------------
213
-/**Print message and error details after SdFat::init() fails.
214
- *
215
- * \param[in] msg Message in program space (flash memory) to print.
216
- */
217
-void SdFat::initErrorPrint_P(PGM_P msg) {
218
-  SerialPrintln_P(msg);
219
-  initErrorHalt();
220
-}
221
-//------------------------------------------------------------------------------
222
-/** List the directory contents of the volume working directory to Serial.
223
- *
224
- * \param[in] flags The inclusive OR of
225
- *
226
- * LS_DATE - %Print file modification date
227
- *
228
- * LS_SIZE - %Print file size.
229
- *
230
- * LS_R - Recursive list of subdirectories.
231
- */
232
-void SdFat::ls(uint8_t flags) {
233
-  vwd_.ls(&Serial, flags);
234
-}
235
-//------------------------------------------------------------------------------
236
-/** List the directory contents of the volume working directory to Serial.
237
- *
238
- * \param[in] pr Print stream for list.
239
- *
240
- * \param[in] flags The inclusive OR of
241
- *
242
- * LS_DATE - %Print file modification date
243
- *
244
- * LS_SIZE - %Print file size.
245
- *
246
- * LS_R - Recursive list of subdirectories.
247
- */
248
-void SdFat::ls(Print* pr, uint8_t flags) {
249
-  vwd_.ls(pr, flags);
250
-}
251
-//------------------------------------------------------------------------------
252
-/** Make a subdirectory in the volume working directory.
253
- *
254
- * \param[in] path A path with a valid 8.3 DOS name for the subdirectory.
255
- *
256
- * \param[in] pFlag Create missing parent directories if true.
257
- *
258
- * \return The value one, true, is returned for success and
259
- * the value zero, false, is returned for failure.
260
- */
261
-bool SdFat::mkdir(const char* path, bool pFlag) {
262
-  SdBaseFile sub;
263
-  return sub.mkdir(&vwd_, path, pFlag);
264
-}
265
-//------------------------------------------------------------------------------
266
-/** Remove a file from the volume working directory.
267
-*
268
-* \param[in] path A path with a valid 8.3 DOS name for the file.
269
-*
270
-* \return The value one, true, is returned for success and
271
-* the value zero, false, is returned for failure.
272
-*/
273
-bool SdFat::remove(const char* path) {
274
-  return SdBaseFile::remove(&vwd_, path);
275
-}
276
-//------------------------------------------------------------------------------
277
-/** Rename a file or subdirectory.
278
- *
279
- * \param[in] oldPath Path name to the file or subdirectory to be renamed.
280
- *
281
- * \param[in] newPath New path name of the file or subdirectory.
282
- *
283
- * The \a newPath object must not exist before the rename call.
284
- *
285
- * The file to be renamed must not be open.  The directory entry may be
286
- * moved and file system corruption could occur if the file is accessed by
287
- * a file object that was opened before the rename() call.
288
- *
289
- * \return The value one, true, is returned for success and
290
- * the value zero, false, is returned for failure.
291
- */
292
-bool SdFat::rename(const char *oldPath, const char *newPath) {
293
-  SdBaseFile file;
294
-  if (!file.open(oldPath, O_READ)) return false;
295
-  return file.rename(&vwd_, newPath);
296
-}
297
-//------------------------------------------------------------------------------
298
-/** Remove a subdirectory from the volume's working directory.
299
- *
300
- * \param[in] path A path with a valid 8.3 DOS name for the subdirectory.
301
- *
302
- * The subdirectory file will be removed only if it is empty.
303
- *
304
- * \return The value one, true, is returned for success and
305
- * the value zero, false, is returned for failure.
306
- */
307
-bool SdFat::rmdir(const char* path) {
308
-  SdBaseFile sub;
309
-  if (!sub.open(path, O_READ)) return false;
310
-  return sub.rmdir();
311
-}
312
-//------------------------------------------------------------------------------
313
-/** Truncate a file to a specified length.  The current file position
314
- * will be maintained if it is less than or equal to \a length otherwise
315
- * it will be set to end of file.
316
- *
317
- * \param[in] path A path with a valid 8.3 DOS name for the file.
318
- * \param[in] length The desired length for the file.
319
- *
320
- * \return The value one, true, is returned for success and
321
- * the value zero, false, is returned for failure.
322
- * Reasons for failure include file is read only, file is a directory,
323
- * \a length is greater than the current file size or an I/O error occurs.
324
- */
325
-bool SdFat::truncate(const char* path, uint32_t length) {
326
-  SdBaseFile file;
327
-  if (!file.open(path, O_WRITE)) return false;
328
-  return file.truncate(length);
329
-}

+ 0
- 76
Marlin/SdFat.h Bestand weergeven

@@ -1,76 +0,0 @@
1
-/* Arduino SdFat Library
2
- * Copyright (C) 2009 by William Greiman
3
- *
4
- * This file is part of the Arduino SdFat Library
5
- *
6
- * This Library is free software: you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation, either version 3 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * This Library is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License
17
- * along with the Arduino SdFat Library.  If not, see
18
- * <http://www.gnu.org/licenses/>.
19
- */
20
-#ifndef SdFat_h
21
-#define SdFat_h
22
-/**
23
- * \file
24
- * \brief SdFat class
25
- */
26
-#include "SdFile.h"
27
-//#include <SdStream.h>
28
-//#include <ArduinoStream.h>
29
-//------------------------------------------------------------------------------
30
-/** SdFat version YYYYMMDD */
31
-#define SD_FAT_VERSION 20110902
32
-//------------------------------------------------------------------------------
33
-/**
34
- * \class SdFat
35
- * \brief Integration class for the %SdFat library.
36
- */
37
-class SdFat {
38
- public:
39
-  SdFat() {}
40
-  /** \return a pointer to the Sd2Card object. */
41
-  Sd2Card* card() {return &card_;}
42
-  bool chdir(bool set_cwd = false);
43
-  bool chdir(const char* path, bool set_cwd = false);
44
-  void chvol();
45
-  void errorHalt();
46
-  void errorHalt_P(PGM_P msg);
47
-  void errorHalt(char const *msg);
48
-  void errorPrint();
49
-  void errorPrint_P(PGM_P msg);
50
-  void errorPrint(char const *msg);
51
-  bool exists(const char* name);
52
-  bool init(uint8_t sckRateID = SPI_FULL_SPEED,
53
-    uint8_t chipSelectPin = SD_CHIP_SELECT_PIN);
54
-  void initErrorHalt();
55
-  void initErrorHalt(char const *msg);
56
-  void initErrorHalt_P(PGM_P msg);
57
-  void initErrorPrint();
58
-  void initErrorPrint(char const *msg);
59
-  void initErrorPrint_P(PGM_P msg);
60
-  void ls(uint8_t flags = 0);
61
-  void ls(Print* pr, uint8_t flags = 0);
62
-  bool mkdir(const char* path, bool pFlag = true);
63
-  bool remove(const char* path);
64
-  bool rename(const char *oldPath, const char *newPath);
65
-  bool rmdir(const char* path);
66
-  bool truncate(const char* path, uint32_t length);
67
-  /** \return a pointer to the SdVolume object. */
68
-  SdVolume* vol() {return &vol_;}
69
-  /** \return a pointer to the volume working directory. */
70
-  SdBaseFile* vwd() {return &vwd_;}
71
- private:
72
-  Sd2Card card_;
73
-  SdVolume vol_;
74
-  SdBaseFile vwd_;
75
-};
76
-#endif  // SdFat_h

+ 15
- 10
Marlin/cardreader.h Bestand weergeven

@@ -3,9 +3,8 @@
3 3
 
4 4
 #ifdef SDSUPPORT
5 5
  
6
-
7
-#include "SdFat.h"
8
-
6
+#include "SdFile.h"
7
+enum LsAction {LS_SerialPrint,LS_Count,LS_GetFilename};
9 8
 class CardReader
10 9
 {
11 10
 public:
@@ -17,20 +16,22 @@ public:
17 16
   //this is to delay autostart and hence the initialisaiton of the sd card to some seconds after the normal init, so the device is available quick after a reset
18 17
 
19 18
   void checkautostart(bool x); 
20
-  
19
+  void openFile(char* name,bool read);
21 20
   void closefile();
22 21
   void release();
23 22
   void startFileprint();
24
-  void startFilewrite(char *name);
23
+  //void startFilewrite(char *name);
25 24
   void pauseSDPrint();
26 25
   void getStatus();
27
-  
28
-  void selectFile(char* name);
26
+  void cd(char * absolutPath);
27
+  //void selectFile(char* name);
29 28
   void getfilename(const uint8_t nr);
30
-  uint8_t getnrfilenames();
29
+  uint16_t getnrfilenames();
31 30
   
32 31
 
33
-  inline void ls() {root.ls();};
32
+  void ls();
33
+  void lsDive(char *prepend,SdFile parent);
34
+
34 35
   inline bool eof() { return sdpos>=filesize ;};
35 36
   inline int16_t get() {  sdpos = file.curPosition();return (int16_t)file.read();};
36 37
   inline void setIndex(long index) {sdpos = index;file.seekSet(index);};
@@ -42,7 +43,7 @@ public:
42 43
   bool cardOK ;
43 44
   char filename[11];
44 45
 private:
45
-  SdFile root;
46
+  SdFile root,*curDir;
46 47
   Sd2Card card;
47 48
   SdVolume volume;
48 49
   SdFile file;
@@ -52,6 +53,10 @@ private:
52 53
   uint32_t sdpos ;
53 54
 
54 55
   bool autostart_stilltocheck; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.
56
+  
57
+  LsAction lsAction; //stored for recursion.
58
+  int16_t nrFiles; //counter for the files in the current directory and recycled as position counter for getting the nrFiles'th name in the directory.
59
+  char* diveDirName;
55 60
 };
56 61
   
57 62
 

+ 136
- 57
Marlin/cardreader.pde Bestand weergeven

@@ -20,6 +20,106 @@ CardReader::CardReader()
20 20
   autostart_atmillis=millis()+5000;
21 21
 }
22 22
 
23
+char *createFilename(char *buffer,const dir_t &p) //buffer>12characters
24
+{
25
+  char *pos=buffer;
26
+  for (uint8_t i = 0; i < 11; i++) 
27
+  {
28
+    if (p.name[i] == ' ')continue;
29
+    if (i == 8) 
30
+    {
31
+      *pos++='.';
32
+    }
33
+    *pos++=p.name[i];
34
+  }
35
+  *pos++=0;
36
+  return buffer;
37
+}
38
+
39
+// bool SdFat::chdir(bool set_cwd) {
40
+//   if (set_cwd) SdBaseFile::cwd_ = &vwd_;
41
+//   vwd_.close();
42
+//   return vwd_.openRoot(&vol_);
43
+// }
44
+void  CardReader::lsDive(char *prepend,SdFile parent)
45
+{
46
+  dir_t p;
47
+ uint8_t cnt=0;
48
+ 
49
+  while (parent.readDir(p) > 0)
50
+  {
51
+    if( DIR_IS_SUBDIR(&p) && lsAction!=LS_Count && lsAction!=LS_GetFilename)
52
+    {
53
+
54
+      char path[13*2];
55
+      char lfilename[13];
56
+      createFilename(lfilename,p);
57
+      
58
+      path[0]=0;
59
+      if(strlen(prepend)==0) //avoid leading / if already in prepend
60
+      {
61
+       strcat(path,"/");
62
+      }
63
+      strcat(path,prepend);
64
+      strcat(path,lfilename);
65
+      strcat(path,"/");
66
+      
67
+      Serial.print(path);
68
+      
69
+      SdFile dir;
70
+      if(!dir.open(parent,lfilename, O_READ))
71
+      {
72
+        if(lsAction==LS_SerialPrint)
73
+        {
74
+          SERIAL_ECHO_START;
75
+          SERIAL_ECHOLN("Cannot open subdir");
76
+          SERIAL_ECHOLN(lfilename);
77
+        }
78
+      }
79
+      lsDive(path,dir);
80
+      //close done automatically by destructor of SdFile
81
+
82
+      
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)
103
+    {
104
+      if(cnt==nrFiles)
105
+        return;
106
+      cnt++;
107
+      
108
+    }
109
+  }
110
+}
111
+
112
+void CardReader::ls() 
113
+{
114
+  lsAction=LS_SerialPrint;
115
+  if(lsAction==LS_Count)
116
+  nrFiles=0;
117
+
118
+  root.rewind();
119
+  lsDive("",root);
120
+}
121
+
122
+
23 123
 void CardReader::initsd()
24 124
 {
25 125
   cardOK = false;
@@ -48,6 +148,7 @@ void CardReader::initsd()
48 148
       SERIAL_ECHO_START;
49 149
       SERIAL_ECHOLNPGM("SD card ok");
50 150
     }
151
+    curDir=&root;
51 152
   #endif //SDSS
52 153
 }
53 154
 void CardReader::release()
@@ -73,13 +174,20 @@ void CardReader::pauseSDPrint()
73 174
   }
74 175
 }
75 176
 
76
-void CardReader::selectFile(char* name)
177
+
178
+
179
+void CardReader::openFile(char* name,bool read)
77 180
 {
78
-  if(cardOK){
79
-    sdprinting = false;
80
-    file.close();
81
-   
82
-    if (file.open(&root, name, O_READ)) {
181
+  if(!cardOK)
182
+    return;
183
+  
184
+    
185
+  file.close();
186
+  sdprinting = false;
187
+  if(read)
188
+  {
189
+    if (file.open(&root, name, O_READ)) 
190
+    {
83 191
       filesize = file.fileSize();
84 192
       SERIAL_PROTOCOLPGM("File opened:");
85 193
       SERIAL_PROTOCOL(name);
@@ -89,32 +197,27 @@ void CardReader::selectFile(char* name)
89 197
       
90 198
       SERIAL_PROTOCOLLNPGM("File selected");
91 199
     }
92
-    else{
200
+    else
201
+    {
93 202
       SERIAL_PROTOCOLLNPGM("file.open failed");
94 203
     }
95 204
   }
96
-}
97
-
98
-void CardReader::startFilewrite(char *name)
99
-{
100
-  if(cardOK)
101
-  {
102
-    
103
-    file.close();
104
-    sdprinting = false;
105
-    
205
+  else 
206
+  { //write
106 207
     if (!file.open(&root, name, O_CREAT | O_APPEND | O_WRITE | O_TRUNC))
107 208
     {
108 209
       SERIAL_PROTOCOLPGM("open failed, File: ");
109 210
       SERIAL_PROTOCOL(name);
110 211
       SERIAL_PROTOCOLLNPGM(".");
111 212
     }
112
-    else{
213
+    else
214
+    {
113 215
       saving = true;
114 216
       SERIAL_PROTOCOLPGM("Writing to file: ");
115 217
       SERIAL_PROTOCOLLN(name);
116 218
     }
117 219
   }
220
+  
118 221
 }
119 222
 
120 223
 void CardReader::getStatus()
@@ -212,49 +315,25 @@ void CardReader::closefile()
212 315
 
213 316
 void CardReader::getfilename(const uint8_t nr)
214 317
 {
215
-
216
-  dir_t p;
217
-  root.rewind();
218
-  uint8_t cnt=0;
219
-  filename[0]='\0';
220
-  while (root.readDir(p) > 0)
221
-  {
222
-    if (p.name[0] == DIR_NAME_FREE) break;
223
-    if (p.name[0] == DIR_NAME_DELETED || p.name[0] == '.'|| p.name[0] == '_') continue;
224
-    if (!DIR_IS_FILE_OR_SUBDIR(&p)) continue;
225
-    if(p.name[8]!='G') continue;
226
-    if(p.name[9]=='~') continue;
227
-    if(cnt++!=nr) continue;
228
-    //Serial.println((char*)p.name);
229
-    uint8_t writepos=0;
230
-    for (int8_t i = 0; i < 11; i++) 
231
-    {
232
-      if (p.name[i] == ' ') continue;
233
-      if (i == 8) {
234
-        filename[writepos++]='.';
235
-      }
236
-      filename[writepos++]=p.name[i];
237
-    }
238
-    filename[writepos++]=0;
239
-  }
318
+  lsAction=LS_GetFilename;
319
+  nrFiles=nr;
320
+  curDir->rewind();
321
+  lsDive("",*curDir);
322
+  
240 323
 }
241 324
 
242
-uint8_t CardReader::getnrfilenames()
325
+uint16_t CardReader::getnrfilenames()
243 326
 {
244
-  dir_t p;
245
-  root.rewind();
246
-  uint8_t cnt=0;
247
-  while (root.readDir(p) > 0)
248
-  {
249
-    if (p.name[0] == DIR_NAME_FREE) break;
250
-    if (p.name[0] == DIR_NAME_DELETED || p.name[0] == '.'|| p.name[0] == '_') continue;
251
-    if (!DIR_IS_FILE_OR_SUBDIR(&p)) continue;
252
-    if(p.name[8]!='G') continue;
253
-    if(p.name[9]=='~') continue;
254
-    cnt++;
255
-  }
256
-  return cnt;
327
+  lsAction=LS_Count;
328
+  nrFiles=0;
329
+  curDir->rewind();
330
+  lsDive("",*curDir);
331
+  return nrFiles;
257 332
 }
258 333
 
334
+void CardReader::cd(char * absolutPath)
335
+{
336
+  
337
+}
259 338
 
260 339
 #endif //SDSUPPORT

Laden…
Annuleren
Opslaan