Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 115 lines (88 sloc) 3.032 kb
b707f7a Limor "Ladyada" Fried added seek() and buffered read()
ladyada authored
1 /*
2
3 SD - a slightly more friendly wrapper for sdfatlib
4
5 This library aims to expose a subset of SD card functionality
6 in the form of a higher level "wrapper" object.
7
8 License: GNU General Public License V3
9 (Because sdfatlib is licensed with this.)
10
11 (C) Copyright 2010 SparkFun Electronics
12
13 */
14
15 #ifndef __SD_H__
16 #define __SD_H__
17
587d4ec Paint Your Dragon Arduino 1.0 compliant
PaintYourDragon authored
18 #if ARDUINO >= 100
19 #include "Arduino.h"
20 #else
21 #include "WProgram.h"
22 #endif
b707f7a Limor "Ladyada" Fried added seek() and buffered read()
ladyada authored
23
24 #include <utility/SdFat.h>
25 #include <utility/SdFatUtil.h>
26
27 #define FILE_READ O_READ
bc92377 Limor "Ladyada" Fried fresh start :/
ladyada authored
28 #define FILE_WRITE (O_READ | O_WRITE | O_CREAT)
b707f7a Limor "Ladyada" Fried added seek() and buffered read()
ladyada authored
29
30 class File : public Stream {
3a9ad07 Limor "Ladyada" Fried Multifile! you can now have many files open at once which allows recursi...
ladyada authored
31 private:
32 char _name[13]; // our name
33 SdFile *_file; // underlying file pointer
34
b707f7a Limor "Ladyada" Fried added seek() and buffered read()
ladyada authored
35 public:
3a9ad07 Limor "Ladyada" Fried Multifile! you can now have many files open at once which allows recursi...
ladyada authored
36 File(SdFile f, char *name); // wraps an underlying SdFile
37 File(void); // 'empty' constructor
38 ~File(void); // destructor
587d4ec Paint Your Dragon Arduino 1.0 compliant
PaintYourDragon authored
39 #if ARDUINO >= 100
40 virtual size_t write(uint8_t);
41 virtual size_t write(const char *str);
42 virtual size_t write(const uint8_t *buf, size_t size);
43 #else
b707f7a Limor "Ladyada" Fried added seek() and buffered read()
ladyada authored
44 virtual void write(uint8_t);
45 virtual void write(const char *str);
46 virtual void write(const uint8_t *buf, size_t size);
587d4ec Paint Your Dragon Arduino 1.0 compliant
PaintYourDragon authored
47 #endif
b707f7a Limor "Ladyada" Fried added seek() and buffered read()
ladyada authored
48 virtual int read();
49 virtual int peek();
50 virtual int available();
51 virtual void flush();
d912252 Limor "Ladyada" Fried Added buffered read
ladyada authored
52 int read(void *buf, uint16_t nbyte);
bc92377 Limor "Ladyada" Fried fresh start :/
ladyada authored
53 boolean seek(uint32_t pos);
54 uint32_t position();
55 uint32_t size();
b707f7a Limor "Ladyada" Fried added seek() and buffered read()
ladyada authored
56 void close();
57 operator bool();
3a9ad07 Limor "Ladyada" Fried Multifile! you can now have many files open at once which allows recursi...
ladyada authored
58 char * name();
59
60 boolean isDirectory(void);
61 File openNextFile(uint8_t mode = O_RDONLY);
62 void rewindDirectory(void);
b707f7a Limor "Ladyada" Fried added seek() and buffered read()
ladyada authored
63 };
64
65 class SDClass {
66
bc92377 Limor "Ladyada" Fried fresh start :/
ladyada authored
67 private:
b707f7a Limor "Ladyada" Fried added seek() and buffered read()
ladyada authored
68 // These are required for initialisation and use of sdfatlib
69 Sd2Card card;
70 SdVolume volume;
bc92377 Limor "Ladyada" Fried fresh start :/
ladyada authored
71 SdFile root;
72
3a9ad07 Limor "Ladyada" Fried Multifile! you can now have many files open at once which allows recursi...
ladyada authored
73 // my quick&dirty iterator, should be replaced
74 SdFile getParentDir(char *filepath, int *indx);
bc92377 Limor "Ladyada" Fried fresh start :/
ladyada authored
75 public:
b707f7a Limor "Ladyada" Fried added seek() and buffered read()
ladyada authored
76 // This needs to be called to set up the connection to the SD card
77 // before other methods are used.
3216c04 Limor "Ladyada" Fried can now select any 4 pins with card.init(), needs testing
ladyada authored
78 boolean begin(uint8_t csPin = SD_CHIP_SELECT_PIN, int8_t mosi = -1, int8_t miso = -1, int8_t sck = -1);
b707f7a Limor "Ladyada" Fried added seek() and buffered read()
ladyada authored
79
80 // Open the specified file/directory with the supplied mode (e.g. read or
81 // write, etc). Returns a File object for interacting with the file.
82 // Note that currently only one file can be open at a time.
83 File open(char *filename, uint8_t mode = FILE_READ);
84
85 // Methods to determine if the requested file path exists.
86 boolean exists(char *filepath);
87
88 // Create the requested directory heirarchy--if intermediate directories
89 // do not exist they will be created.
90 boolean mkdir(char *filepath);
91
92 // Delete the file.
93 boolean remove(char *filepath);
94
95 boolean rmdir(char *filepath);
96
bd7b667 Paint Your Dragon CRC16 calc for Eye-Fi X2 cards
PaintYourDragon authored
97 void enableCRC(boolean mode);
98
b707f7a Limor "Ladyada" Fried added seek() and buffered read()
ladyada authored
99 private:
100
101 // This is used to determine the mode used to open a file
102 // it's here because it's the easiest place to pass the
103 // information through the directory walking function. But
104 // it's probably not the best place for it.
105 // It shouldn't be set directly--it is set via the parameters to `open`.
106 int fileOpenMode;
107
108 friend class File;
109 friend boolean callback_openPath(SdFile&, char *, boolean, void *);
110 };
111
112 extern SDClass SD;
113
114 #endif
Something went wrong with that request. Please try again.