Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

107 rindas
2.7KB

  1. #if defined(__arm__)
  2. #include "SD_t3.h"
  3. #endif
  4. /*
  5. SD - a slightly more friendly wrapper for sdfatlib
  6. This library aims to expose a subset of SD card functionality
  7. in the form of a higher level "wrapper" object.
  8. License: GNU General Public License V3
  9. (Because sdfatlib is licensed with this.)
  10. (C) Copyright 2010 SparkFun Electronics
  11. */
  12. #ifndef __SD_H__
  13. #define __SD_H__
  14. #include <Arduino.h>
  15. #include <utility/SdFat.h>
  16. #include <utility/SdFatUtil.h>
  17. #define FILE_READ O_READ
  18. #define FILE_WRITE (O_READ | O_WRITE | O_CREAT)
  19. class File : public Stream {
  20. private:
  21. char _name[13]; // our name
  22. SdFile *_file; // underlying file pointer
  23. public:
  24. File(SdFile f, const char *name); // wraps an underlying SdFile
  25. File(void); // 'empty' constructor
  26. ~File(void); // destructor
  27. virtual size_t write(uint8_t);
  28. virtual size_t write(const uint8_t *buf, size_t size);
  29. virtual int read();
  30. virtual int peek();
  31. virtual int available();
  32. virtual void flush();
  33. int read(void *buf, uint16_t nbyte);
  34. boolean seek(uint32_t pos);
  35. uint32_t position();
  36. uint32_t size();
  37. void close();
  38. operator bool();
  39. char * name();
  40. boolean isDirectory(void);
  41. File openNextFile(uint8_t mode = O_RDONLY);
  42. void rewindDirectory(void);
  43. using Print::write;
  44. };
  45. class SDClass {
  46. private:
  47. // These are required for initialisation and use of sdfatlib
  48. Sd2Card card;
  49. SdVolume volume;
  50. SdFile root;
  51. // my quick&dirty iterator, should be replaced
  52. SdFile getParentDir(const char *filepath, int *indx);
  53. public:
  54. // This needs to be called to set up the connection to the SD card
  55. // before other methods are used.
  56. boolean begin(uint8_t csPin = SD_CHIP_SELECT_PIN);
  57. // Open the specified file/directory with the supplied mode (e.g. read or
  58. // write, etc). Returns a File object for interacting with the file.
  59. // Note that currently only one file can be open at a time.
  60. File open(const char *filename, uint8_t mode = FILE_READ);
  61. // Methods to determine if the requested file path exists.
  62. boolean exists(const char *filepath);
  63. // Create the requested directory heirarchy--if intermediate directories
  64. // do not exist they will be created.
  65. boolean mkdir(const char *filepath);
  66. // Delete the file.
  67. boolean remove(const char *filepath);
  68. boolean rmdir(const char *filepath);
  69. private:
  70. // This is used to determine the mode used to open a file
  71. // it's here because it's the easiest place to pass the
  72. // information through the directory walking function. But
  73. // it's probably not the best place for it.
  74. // It shouldn't be set directly--it is set via the parameters to `open`.
  75. int fileOpenMode;
  76. friend class File;
  77. friend boolean callback_openPath(SdFile&, char *, boolean, void *);
  78. };
  79. extern SDClass SD;
  80. #endif