SdFile.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Arduino SdFat Library
  2. * Copyright (C) 2009 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. #include "Marlin.h"
  25. #ifdef SDSUPPORT
  26. #include "SdBaseFile.h"
  27. //#include <Print.h>
  28. #ifndef SdFile_h
  29. #define SdFile_h
  30. //------------------------------------------------------------------------------
  31. /**
  32. * \class SdFile
  33. * \brief SdBaseFile with Print.
  34. */
  35. class SdFile : public SdBaseFile/*, public Print*/ {
  36. // GCode filtering vars and methods - due to optimization reasons not wrapped in a separate class
  37. // beware - this read ptr is manipulated inside just 2 methods - readFilteredGcode and gfReset
  38. // If you even want to call gfReset from readFilteredGcode, you must make sure
  39. // to update gfReadPtr inside readFilteredGcode from a local copy (see explanation of this trick in readFilteredGcode)
  40. const uint8_t *gfReadPtr;
  41. uint32_t gfBlock; // remember the current file block to be kept in cache - due to reuse of the memory, the block may fall out a must be read back
  42. uint16_t gfOffset;
  43. const uint8_t *gfBlockBuffBegin()const;
  44. void gfReset();
  45. bool gfEnsureBlock();
  46. bool gfComputeNextFileBlock();
  47. void gfUpdateCurrentPosition(uint16_t inc);
  48. public:
  49. SdFile() {}
  50. SdFile(const char* name, uint8_t oflag);
  51. #if ARDUINO >= 100
  52. size_t write(uint8_t b);
  53. #else
  54. void write(uint8_t b);
  55. #endif
  56. bool openFilteredGcode(SdBaseFile* dirFile, const char* path);
  57. int16_t readFilteredGcode();
  58. bool seekSetFilteredGcode(uint32_t pos);
  59. int16_t write(const void* buf, uint16_t nbyte);
  60. void write(const char* str);
  61. void write_P(PGM_P str);
  62. void writeln_P(PGM_P str);
  63. };
  64. #endif // SdFile_h
  65. #endif