/firmware/src/Motherboard/SDCard.hh

http://github.com/makerbot/G3Firmware · C++ Header · 115 lines · 31 code · 31 blank · 53 comment · 0 complexity · 5d4761084455bc3477b616a165745312 MD5 · raw file

  1. /*
  2. * Copyright 2010 by Adam Mayer <adam@makerbot.com>
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>
  16. */
  17. #ifndef SDCARD_HH_
  18. #define SDCARD_HH_
  19. #include <stdint.h>
  20. #include "Packet.hh"
  21. /// Interface to the SD card library. Provides straightforward functions for
  22. /// listing directory contents, and reading and writing jobs to files.
  23. namespace sdcard {
  24. /// This enumeration lists all the SD card call error/success codes.
  25. /// Any non-zero value is an error condition.
  26. typedef enum {
  27. SD_SUCCESS = 0, ///< Operation succeeded
  28. SD_ERR_NO_CARD_PRESENT = 1, ///< No SD card is inserted in the slot
  29. SD_ERR_INIT_FAILED = 2, ///< SD card initialization failed
  30. SD_ERR_PARTITION_READ = 3, ///< Couldn't read the card's partition table
  31. SD_ERR_OPEN_FILESYSTEM = 4, ///< Couldn't open the FAT16 filesystem --
  32. ///< check that it's real FAT16
  33. SD_ERR_NO_ROOT = 5, ///< No root directory found
  34. SD_ERR_CARD_LOCKED = 6, ///< Card is locked, writing forbidden
  35. SD_ERR_FILE_NOT_FOUND = 7, ///< Could not find specific file
  36. SD_ERR_GENERIC = 8 ///< General error
  37. } SdErrorCode;
  38. /// Reset the SD card subsystem.
  39. void reset();
  40. /// Start a directory scan.
  41. /// \return SD_SUCCESS if successful
  42. SdErrorCode directoryReset();
  43. /// Get the next filename in a directory scan.
  44. /// \param[in] buffer Character buffer to store name in
  45. /// \param[in] bufsize Size of buffer
  46. /// \return SD_SUCCESS if successful
  47. SdErrorCode directoryNextEntry(char* buffer, uint8_t bufsize);
  48. /// Begin capturing bufffered commands to a new file with the given filename.
  49. /// Returns an SD card error/success code.
  50. /// \param[in] filename Name of file to write to
  51. /// \return SD_SUCCESS if successful
  52. SdErrorCode startCapture(char* filename);
  53. /// Capture the contents of a packet to the currently open file.
  54. /// \param[in] packet Packet to write to file.
  55. void capturePacket(const Packet& packet);
  56. /// Complete the capture, and flush buffers. Return the number of bytes
  57. /// written to the card.
  58. /// \return Number of bytes written to the card.
  59. uint32_t finishCapture();
  60. /// Check whether a job is being captured to SD card
  61. /// \return True if we're capturing buffered commands to a file, false otherwise
  62. bool isCapturing();
  63. /// Begin playing back commands from a file on the SD card.
  64. /// Returns an SD card error/success code
  65. /// \param[in] filename Name of file to write to
  66. /// \return SD_SUCCESS if successful
  67. SdErrorCode startPlayback(char* filename);
  68. /// See if there is more data available in the playback file.
  69. /// \return True if there is more data in the file
  70. bool playbackHasNext();
  71. /// Return the next byte from the currently open file.
  72. /// \return The next byre in the file.
  73. uint8_t playbackNext();
  74. /// Rewind the given number of bytes in the input stream.
  75. /// \param[in] bytes Number of bytes to rewind
  76. void playbackRewind(uint8_t bytes);
  77. /// Halt playback. Should be called at the end of playback, or on manual
  78. /// halt; frees up resources.
  79. void finishPlayback();
  80. /// Check whether a job is being played back from the SD card
  81. /// \return True if we're playing back buffered commands from a file, false otherwise
  82. bool isPlaying();
  83. } // namespace sdcard
  84. #endif // SDCARD_HH_