You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
3.9KB

  1. /* Arduino SdFat Library
  2. * Copyright (C) 2012 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. //------------------------------------------------------------------------------
  27. /** Macro for debug. */
  28. #define DBG_FAIL_MACRO // Serial.print(__FILE__);Serial.println(__LINE__)
  29. //------------------------------------------------------------------------------
  30. /** SdFat version YYYYMMDD */
  31. #define SD_FAT_VERSION 20141025
  32. //------------------------------------------------------------------------------
  33. /** error if old IDE */
  34. #if !defined(ARDUINO) || ARDUINO < 100
  35. #error Arduino IDE must be 1.0 or greater
  36. #endif // ARDUINO < 100
  37. //------------------------------------------------------------------------------
  38. #include <SdFile.h>
  39. #include <SdStream.h>
  40. #include <StdioStream.h>
  41. #include <ArduinoStream.h>
  42. #include <MinimumSerial.h>
  43. //------------------------------------------------------------------------------
  44. /**
  45. * \class SdFat
  46. * \brief Integration class for the %SdFat library.
  47. */
  48. class SdFat {
  49. public:
  50. SdFat() {}
  51. /** \return a pointer to the Sd2Card object. */
  52. Sd2Card* card() {return &m_card;}
  53. bool chdir(bool set_cwd = false);
  54. bool chdir(const char* path, bool set_cwd = false);
  55. void chvol();
  56. void errorHalt();
  57. void errorHalt(char const *msg);
  58. void errorPrint();
  59. void errorPrint(char const *msg);
  60. bool exists(const char* name);
  61. bool begin(uint8_t chipSelectPin = SD_CHIP_SELECT_PIN,
  62. uint8_t sckDivisor = SPI_FULL_SPEED);
  63. void initErrorHalt();
  64. void initErrorHalt(char const *msg);
  65. void initErrorPrint();
  66. void initErrorPrint(char const *msg);
  67. void ls(uint8_t flags = 0);
  68. void ls(const char* path, uint8_t flags = 0);
  69. void ls(Print* pr, uint8_t flags = 0);
  70. void ls(Print* pr, const char* path, uint8_t flags = 0);
  71. bool mkdir(const char* path, bool pFlag = true);
  72. bool remove(const char* path);
  73. bool rename(const char *oldPath, const char *newPath);
  74. bool rmdir(const char* path);
  75. bool truncate(const char* path, uint32_t length);
  76. /** \return a pointer to the SdVolume object. */
  77. SdVolume* vol() {return &m_vol;}
  78. /** \return a pointer to the volume working directory. */
  79. SdBaseFile* vwd() {return &m_vwd;}
  80. //----------------------------------------------------------------------------
  81. void errorHalt_P(PGM_P msg);
  82. void errorPrint_P(PGM_P msg);
  83. void initErrorHalt_P(PGM_P msg);
  84. void initErrorPrint_P(PGM_P msg);
  85. //----------------------------------------------------------------------------
  86. /**
  87. * Set stdOut Print stream for messages.
  88. * \param[in] stream The new Print stream.
  89. */
  90. static void setStdOut(Print* stream) {m_stdOut = stream;}
  91. /** \return Print stream for messages. */
  92. static Print* stdOut() {return m_stdOut;}
  93. //----------------------------------------------------------------------------
  94. /** open a file
  95. *
  96. * \param[in] path location of file to be opened.
  97. * \param[in] mode open mode flags.
  98. * \return a File object.
  99. */
  100. File open(const char *path, uint8_t mode = FILE_READ) {
  101. File tmpFile;
  102. tmpFile.open(&m_vwd, path, mode);
  103. return tmpFile;
  104. }
  105. private:
  106. Sd2Card m_card;
  107. SdVolume m_vol;
  108. SdBaseFile m_vwd;
  109. static Print* m_stdOut;
  110. };
  111. #endif // SdFat_h