Skip to content

Commit 0259bc9

Browse files
committed
File inherits from Stream: proper support for print and println of all supported data type
1 parent 8e85a6d commit 0259bc9

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
*.swp
2+
.vscode

examples/Full/Full.ino

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ void setup()
251251
MyFile.println();
252252
MyFile.println("This should be line 6");
253253
MyFile.println(str);
254+
MyFile.print("This should be line ");
255+
MyFile.println(8);
254256
Serial.println("OK");
255257
Serial.print("Closing 'ARDUINO/SD/PRINT.txt' file");
256258
Serial.println("OK");
@@ -291,7 +293,26 @@ void setup()
291293
} else {
292294
Serial.println("KO --> Error to open 'ARDUINO/SD/WRITE.txt' file");
293295
}
296+
297+
/* Test readBytes(buf, len) method */
298+
Serial.print("Opening 'ARDUINO/SD/WRITE.txt' file...");
299+
MyFile = SD.open("ARDUINO/SD/WRITE.txt");
300+
if (MyFile) {
301+
Serial.println("OK");
302+
Serial.print(" Reading 'ARDUINO/SD/WRITE.txt' file: ");
303+
bytesread = MyFile.readBytes(rtext, MyFile.size());
304+
Serial.print(bytesread);
305+
Serial.println(" bytes read");
306+
Serial.println((const char*)rtext);
307+
Serial.print("Closing 'ARDUINO/SD/WRITE.txt' file...");
308+
MyFile.close();
309+
Serial.println("OK");
310+
} else {
311+
Serial.println("KO --> Error to open 'ARDUINO/SD/WRITE.txt' file");
312+
}
294313
Serial.println("###### End of the SD tests ######");
314+
315+
295316
}
296317

297318
void loop()

src/STM32SD.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ uint8_t const LS_SIZE = 2;
3030
/** ls() flag for recursive list of subdirectories */
3131
uint8_t const LS_R = 4;
3232

33-
class File {
33+
class File : public Stream {
3434
public:
3535
File(FRESULT res = FR_OK);
3636
virtual size_t write(uint8_t);
@@ -78,6 +78,9 @@ class File {
7878
{
7979
return _res;
8080
}
81+
82+
using Print::println;
83+
using Print::print;
8184

8285
};
8386

0 commit comments

Comments
 (0)