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.

10 年之前
10 年之前
10 年之前
10 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. /**
  21. * \file
  22. * \brief SdFile class
  23. */
  24. #ifndef SdFile_h
  25. #define SdFile_h
  26. #include <limits.h>
  27. #include <SdBaseFile.h>
  28. //------------------------------------------------------------------------------
  29. /**
  30. * \class SdFile
  31. * \brief SdBaseFile with Arduino Stream.
  32. */
  33. class SdFile : public SdBaseFile, public Stream {
  34. public:
  35. SdFile() {}
  36. SdFile(const char* name, uint8_t oflag);
  37. #if DESTRUCTOR_CLOSES_FILE
  38. ~SdFile() {}
  39. #endif // DESTRUCTOR_CLOSES_FILE
  40. /** \return number of bytes available from the current position to EOF
  41. * or INT_MAX if more than INT_MAX bytes are available.
  42. */
  43. int available() {
  44. uint32_t n = SdBaseFile::available();
  45. return n > INT_MAX ? INT_MAX : n;
  46. }
  47. /** Ensure that any bytes written to the file are saved to the SD card. */
  48. void flush() {SdBaseFile::sync();}
  49. /** Return the next available byte without consuming it.
  50. *
  51. * \return The byte if no error and not at eof else -1;
  52. */
  53. int peek() {return SdBaseFile::peek();}
  54. /** Read the next byte from a file.
  55. *
  56. * \return For success return the next byte in the file as an int.
  57. * If an error occurs or end of file is reached return -1.
  58. */
  59. int read() {return SdBaseFile::read();}
  60. /** \return value of writeError */
  61. bool getWriteError() {return SdBaseFile::getWriteError();}
  62. /** Set writeError to zero */
  63. void clearWriteError() {SdBaseFile::clearWriteError();}
  64. size_t write(uint8_t b);
  65. int write(const char* str);
  66. int write(const void* buf, size_t nbyte);
  67. size_t write(const uint8_t *buf, size_t size) {
  68. return SdBaseFile::write(buf, size);}
  69. void write_P(PGM_P str);
  70. void writeln_P(PGM_P str);
  71. };
  72. #endif // SdFile_h