PageRenderTime 45ms CodeModel.GetById 37ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 18
 19#ifndef SDCARD_HH_
 20#define SDCARD_HH_
 21
 22#include <stdint.h>
 23#include "Packet.hh"
 24
 25/// Interface to the SD card library. Provides straightforward functions for
 26/// listing directory contents, and reading and writing jobs to files.
 27namespace sdcard {
 28
 29    /// This enumeration lists all the SD card call error/success codes.
 30    /// Any non-zero value is an error condition.
 31    typedef enum {
 32      SD_SUCCESS              = 0,  ///< Operation succeeded
 33      SD_ERR_NO_CARD_PRESENT  = 1,  ///< No SD card is inserted in the slot
 34      SD_ERR_INIT_FAILED      = 2,  ///< SD card initialization failed
 35      SD_ERR_PARTITION_READ   = 3,  ///< Couldn't read the card's partition table
 36      SD_ERR_OPEN_FILESYSTEM  = 4,  ///< Couldn't open the FAT16 filesystem --
 37                                    ///<  check that it's real FAT16
 38      SD_ERR_NO_ROOT          = 5,  ///< No root directory found
 39      SD_ERR_CARD_LOCKED      = 6,  ///< Card is locked, writing forbidden
 40      SD_ERR_FILE_NOT_FOUND   = 7,  ///< Could not find specific file
 41      SD_ERR_GENERIC          = 8   ///< General error
 42    } SdErrorCode;
 43
 44    /// Reset the SD card subsystem.
 45    void reset();
 46
 47
 48    /// Start a directory scan.
 49    /// \return SD_SUCCESS if successful
 50    SdErrorCode directoryReset();
 51
 52
 53    /// Get the next filename in a directory scan.
 54    /// \param[in] buffer Character buffer to store name in
 55    /// \param[in] bufsize Size of buffer
 56    /// \return SD_SUCCESS if successful
 57    SdErrorCode directoryNextEntry(char* buffer, uint8_t bufsize);
 58
 59
 60    /// Begin capturing bufffered commands to a new file with the given filename.
 61    /// Returns an SD card error/success code.
 62    /// \param[in] filename Name of file to write to
 63    /// \return SD_SUCCESS if successful
 64    SdErrorCode startCapture(char* filename);
 65
 66
 67    /// Capture the contents of a packet to the currently open file.
 68    /// \param[in] packet Packet to write to file.
 69    void capturePacket(const Packet& packet);
 70
 71
 72    /// Complete the capture, and flush buffers.  Return the number of bytes
 73    /// written to the card.
 74    /// \return Number of bytes written to the card.
 75    uint32_t finishCapture();
 76
 77
 78    /// Check whether a job is being captured to SD card
 79    /// \return True if we're capturing buffered commands to a file, false otherwise
 80    bool isCapturing();
 81
 82
 83    /// Begin playing back commands from a file on the SD card.
 84    /// Returns an SD card error/success code
 85    /// \param[in] filename Name of file to write to
 86    /// \return SD_SUCCESS if successful
 87    SdErrorCode startPlayback(char* filename);
 88
 89
 90    /// See if there is more data available in the playback file.
 91    /// \return True if there is more data in the file
 92    bool playbackHasNext();
 93
 94
 95    /// Return the next byte from the currently open file.
 96    /// \return The next byre in the file.
 97    uint8_t playbackNext();
 98
 99
100    /// Rewind the given number of bytes in the input stream.
101    /// \param[in] bytes Number of bytes to rewind
102    void playbackRewind(uint8_t bytes);
103
104
105    /// Halt playback.  Should be called at the end of playback, or on manual
106    /// halt; frees up resources.
107    void finishPlayback();
108
109    /// Check whether a job is being played back from the SD card
110    /// \return True if we're playing back buffered commands from a file, false otherwise
111    bool isPlaying();
112
113} // namespace sdcard
114
115#endif // SDCARD_HH_