2011-11-05 08:19:57 -05:00
|
|
|
/* Arduino SdFat Library
|
|
|
|
* Copyright (C) 2009 by William Greiman
|
|
|
|
*
|
|
|
|
* This file is part of the Arduino SdFat Library
|
|
|
|
*
|
|
|
|
* This Library is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This Library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with the Arduino SdFat Library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2015-01-15 17:52:10 -06:00
|
|
|
#include "Marlin.h"
|
|
|
|
|
|
|
|
#ifdef SDSUPPORT
|
2011-11-18 15:17:37 -06:00
|
|
|
#include "SdFile.h"
|
|
|
|
/** Create a file object and open it in the current working directory.
|
2011-11-05 08:19:57 -05:00
|
|
|
*
|
2011-11-18 15:17:37 -06:00
|
|
|
* \param[in] path A path with a valid 8.3 DOS name for a file to be opened.
|
2011-11-05 08:19:57 -05:00
|
|
|
*
|
|
|
|
* \param[in] oflag Values for \a oflag are constructed by a bitwise-inclusive
|
2011-11-18 15:17:37 -06:00
|
|
|
* OR of open flags. see SdBaseFile::open(SdBaseFile*, const char*, uint8_t).
|
2011-11-05 08:19:57 -05:00
|
|
|
*/
|
2011-11-18 15:17:37 -06:00
|
|
|
SdFile::SdFile(const char* path, uint8_t oflag) : SdBaseFile(path, oflag) {
|
2011-11-05 08:19:57 -05:00
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
2011-11-18 15:17:37 -06:00
|
|
|
/** Write data to an open file.
|
2011-11-05 08:19:57 -05:00
|
|
|
*
|
|
|
|
* \note Data is moved to the cache but may not be written to the
|
|
|
|
* storage device until sync() is called.
|
|
|
|
*
|
|
|
|
* \param[in] buf Pointer to the location of the data to be written.
|
|
|
|
*
|
|
|
|
* \param[in] nbyte Number of bytes to write.
|
|
|
|
*
|
|
|
|
* \return For success write() returns the number of bytes written, always
|
|
|
|
* \a nbyte. If an error occurs, write() returns -1. Possible errors
|
|
|
|
* include write() is called before a file has been opened, write is called
|
|
|
|
* for a read-only file, device is full, a corrupt file system or an I/O error.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
int16_t SdFile::write(const void* buf, uint16_t nbyte) {
|
2011-11-18 15:17:37 -06:00
|
|
|
return SdBaseFile::write(buf, nbyte);
|
2011-11-05 08:19:57 -05:00
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
2011-11-18 15:17:37 -06:00
|
|
|
/** Write a byte to a file. Required by the Arduino Print class.
|
|
|
|
* \param[in] b the byte to be written.
|
|
|
|
* Use writeError to check for errors.
|
2011-11-05 08:19:57 -05:00
|
|
|
*/
|
2011-12-01 09:38:01 -06:00
|
|
|
#if ARDUINO >= 100
|
2012-11-06 05:06:41 -06:00
|
|
|
size_t SdFile::write(uint8_t b)
|
|
|
|
{
|
|
|
|
return SdBaseFile::write(&b, 1);
|
|
|
|
}
|
2011-12-01 09:38:01 -06:00
|
|
|
#else
|
2012-11-06 05:06:41 -06:00
|
|
|
void SdFile::write(uint8_t b)
|
2011-12-01 09:38:01 -06:00
|
|
|
{
|
2012-11-06 05:06:41 -06:00
|
|
|
SdBaseFile::write(&b, 1);
|
2011-11-05 08:19:57 -05:00
|
|
|
}
|
2012-11-06 05:06:41 -06:00
|
|
|
#endif
|
2011-11-05 08:19:57 -05:00
|
|
|
//------------------------------------------------------------------------------
|
2011-11-18 15:17:37 -06:00
|
|
|
/** Write a string to a file. Used by the Arduino Print class.
|
|
|
|
* \param[in] str Pointer to the string.
|
|
|
|
* Use writeError to check for errors.
|
2011-11-05 08:19:57 -05:00
|
|
|
*/
|
|
|
|
void SdFile::write(const char* str) {
|
2011-11-18 15:17:37 -06:00
|
|
|
SdBaseFile::write(str, strlen(str));
|
2011-11-05 08:19:57 -05:00
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
2011-11-18 15:17:37 -06:00
|
|
|
/** Write a PROGMEM string to a file.
|
|
|
|
* \param[in] str Pointer to the PROGMEM string.
|
|
|
|
* Use writeError to check for errors.
|
2011-11-05 08:19:57 -05:00
|
|
|
*/
|
|
|
|
void SdFile::write_P(PGM_P str) {
|
|
|
|
for (uint8_t c; (c = pgm_read_byte(str)); str++) write(c);
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
2011-11-18 15:17:37 -06:00
|
|
|
/** Write a PROGMEM string followed by CR/LF to a file.
|
|
|
|
* \param[in] str Pointer to the PROGMEM string.
|
|
|
|
* Use writeError to check for errors.
|
2011-11-05 08:19:57 -05:00
|
|
|
*/
|
|
|
|
void SdFile::writeln_P(PGM_P str) {
|
|
|
|
write_P(str);
|
2011-11-18 15:17:37 -06:00
|
|
|
write_P(PSTR("\r\n"));
|
2011-11-05 08:19:57 -05:00
|
|
|
}
|
2015-01-15 17:52:10 -06:00
|
|
|
|
|
|
|
|
|
|
|
#endif
|