Subversion Repositories MK-Marlin

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 ron 1
/**
2
 * Marlin 3D Printer Firmware
3
 * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
 *
5
 * Based on Sprinter and grbl.
6
 * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 */
22
 
23
/**
24
 * Arduino SdFat Library
25
 * Copyright (C) 2009 by William Greiman
26
 *
27
 * This file is part of the Arduino Sd2Card Library
28
 */
29
#include "MarlinConfig.h"
30
 
31
#if ENABLED(SDSUPPORT)
32
 
33
#include "SdFile.h"
34
 
35
/**
36
 *  Create a file object and open it in the current working directory.
37
 *
38
 * \param[in] path A path with a valid 8.3 DOS name for a file to be opened.
39
 *
40
 * \param[in] oflag Values for \a oflag are constructed by a bitwise-inclusive
41
 * OR of open flags. see SdBaseFile::open(SdBaseFile*, const char*, uint8_t).
42
 */
43
SdFile::SdFile(const char* path, uint8_t oflag) : SdBaseFile(path, oflag) { }
44
 
45
/**
46
 * Write data to an open file.
47
 *
48
 * \note Data is moved to the cache but may not be written to the
49
 * storage device until sync() is called.
50
 *
51
 * \param[in] buf Pointer to the location of the data to be written.
52
 *
53
 * \param[in] nbyte Number of bytes to write.
54
 *
55
 * \return For success write() returns the number of bytes written, always
56
 * \a nbyte.  If an error occurs, write() returns -1.  Possible errors
57
 * include write() is called before a file has been opened, write is called
58
 * for a read-only file, device is full, a corrupt file system or an I/O error.
59
 *
60
 */
61
int16_t SdFile::write(const void* buf, uint16_t nbyte) { return SdBaseFile::write(buf, nbyte); }
62
 
63
/**
64
 * Write a byte to a file. Required by the Arduino Print class.
65
 * \param[in] b the byte to be written.
66
 * Use writeError to check for errors.
67
 */
68
#if ARDUINO >= 100
69
  size_t SdFile::write(uint8_t b) { return SdBaseFile::write(&b, 1); }
70
#else
71
  void SdFile::write(uint8_t b) { SdBaseFile::write(&b, 1); }
72
#endif
73
 
74
/**
75
 * Write a string to a file. Used by the Arduino Print class.
76
 * \param[in] str Pointer to the string.
77
 * Use writeError to check for errors.
78
 */
79
void SdFile::write(const char* str) { SdBaseFile::write(str, strlen(str)); }
80
 
81
/**
82
 * Write a PROGMEM string to a file.
83
 * \param[in] str Pointer to the PROGMEM string.
84
 * Use writeError to check for errors.
85
 */
86
void SdFile::write_P(PGM_P str) {
87
  for (uint8_t c; (c = pgm_read_byte(str)); str++) write(c);
88
}
89
 
90
/**
91
 * Write a PROGMEM string followed by CR/LF to a file.
92
 * \param[in] str Pointer to the PROGMEM string.
93
 * Use writeError to check for errors.
94
 */
95
void SdFile::writeln_P(PGM_P str) {
96
  write_P(str);
97
  write_P(PSTR("\r\n"));
98
}
99
 
100
#endif // SDSUPPORT