Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

100 lines
3.5KB

  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 20141023
  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 <ArduinoStream.h>
  41. #include <MinimumSerial.h>
  42. //------------------------------------------------------------------------------
  43. /**
  44. * \class SdFat
  45. * \brief Integration class for the %SdFat library.
  46. */
  47. class SdFat {
  48. public:
  49. SdFat() {}
  50. /** \return a pointer to the Sd2Card object. */
  51. Sd2Card* card() {return &m_card;}
  52. bool chdir(bool set_cwd = false);
  53. bool chdir(const char* path, bool set_cwd = false);
  54. void chvol();
  55. void errorHalt();
  56. void errorHalt(char const *msg);
  57. void errorPrint();
  58. void errorPrint(char const *msg);
  59. bool exists(const char* name);
  60. bool begin(uint8_t chipSelectPin = SD_CHIP_SELECT_PIN,
  61. uint8_t sckDivisor = SPI_FULL_SPEED);
  62. void initErrorHalt();
  63. void initErrorHalt(char const *msg);
  64. void initErrorPrint();
  65. void initErrorPrint(char const *msg);
  66. void ls(uint8_t flags = 0);
  67. void ls(const char* path, uint8_t flags = 0);
  68. void ls(Print* pr, uint8_t flags = 0);
  69. void ls(Print* pr, const char* path, uint8_t flags = 0);
  70. bool mkdir(const char* path, bool pFlag = true);
  71. bool remove(const char* path);
  72. bool rename(const char *oldPath, const char *newPath);
  73. bool rmdir(const char* path);
  74. bool truncate(const char* path, uint32_t length);
  75. /** \return a pointer to the SdVolume object. */
  76. SdVolume* vol() {return &m_vol;}
  77. /** \return a pointer to the volume working directory. */
  78. SdBaseFile* vwd() {return &m_vwd;}
  79. //----------------------------------------------------------------------------
  80. void errorHalt_P(PGM_P msg);
  81. void errorPrint_P(PGM_P msg);
  82. void initErrorHalt_P(PGM_P msg);
  83. void initErrorPrint_P(PGM_P msg);
  84. //----------------------------------------------------------------------------
  85. /**
  86. * Set stdOut Print stream for messages.
  87. * \param[in] stream The new Print stream.
  88. */
  89. static void setStdOut(Print* stream) {m_stdOut = stream;}
  90. /** \return Print stream for messages. */
  91. static Print* stdOut() {return m_stdOut;}
  92. private:
  93. Sd2Card m_card;
  94. SdVolume m_vol;
  95. SdBaseFile m_vwd;
  96. static Print* m_stdOut;
  97. };
  98. #endif // SdFat_h