D:/DRISSI/arduino-0022/arduino-0022/libraries/SD/SD.h
00001 /*
00002 
00003  SD - a slightly more friendly wrapper for sdfatlib
00004 
00005  This library aims to expose a subset of SD card functionality
00006  in the form of a higher level "wrapper" object.
00007 
00008  License: GNU General Public License V3
00009           (Because sdfatlib is licensed with this.)
00010 
00011  (C) Copyright 2010 SparkFun Electronics
00012 
00013  */
00014 
00015 #ifndef __SD_H__
00016 #define __SD_H__
00017 
00018 #include <WProgram.h>
00019 
00020 #include <utility/SdFat.h>
00021 #include <utility/SdFatUtil.h>
00022 
00023 #define FILE_READ O_READ
00024 #define FILE_WRITE (O_READ | O_WRITE | O_CREAT | O_SYNC)
00025 
00026 class File : public Stream {
00027 public:
00028   virtual void write(uint8_t);
00029   virtual void write(const char *str);
00030   virtual void write(const uint8_t *buf, size_t size);
00031   virtual int read();
00032   virtual int peek();
00033   virtual int available();
00034   virtual void flush();
00035   boolean seek(uint32_t pos);
00036   uint32_t position();
00037   uint32_t size();
00038   void close();
00039   operator bool();
00040 };
00041 
00042 class SDClass {
00043 
00044 private:
00045   // These are required for initialisation and use of sdfatlib
00046   Sd2Card card;
00047   SdVolume volume;
00048   SdFile root;
00049   
00050 public:
00051   // This needs to be called to set up the connection to the SD card
00052   // before other methods are used.
00053   boolean begin(uint8_t csPin = SD_CHIP_SELECT_PIN);
00054   
00055   // Open the specified file/directory with the supplied mode (e.g. read or
00056   // write, etc). Returns a File object for interacting with the file.
00057   // Note that currently only one file can be open at a time.
00058   File open(char *filename, uint8_t mode = FILE_READ);
00059 
00060   // Methods to determine if the requested file path exists.
00061   boolean exists(char *filepath);
00062 
00063   // Create the requested directory heirarchy--if intermediate directories
00064   // do not exist they will be created.
00065   boolean mkdir(char *filepath);
00066   
00067   // Delete the file.
00068   boolean remove(char *filepath);
00069   
00070   boolean rmdir(char *filepath);
00071 
00072 private:
00073   SdFile file;
00074 
00075   // This is used to determine the mode used to open a file
00076   // it's here because it's the easiest place to pass the 
00077   // information through the directory walking function. But
00078   // it's probably not the best place for it.
00079   // It shouldn't be set directly--it is set via the parameters to `open`.
00080   int fileOpenMode;
00081   
00082   friend class File;
00083   friend boolean callback_openPath(SdFile&, char *, boolean, void *); 
00084 };
00085 
00086 extern SDClass SD;
00087 
00088 #endif