Skip to content

Commit

Permalink
File inherits from Stream: proper support for print and println of al…
Browse files Browse the repository at this point in the history
…l supported data type
  • Loading branch information
pschatzmann committed Jul 10, 2024
1 parent 8e85a6d commit 0259bc9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.swp
.vscode
21 changes: 21 additions & 0 deletions examples/Full/Full.ino
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ void setup()
MyFile.println();
MyFile.println("This should be line 6");
MyFile.println(str);
MyFile.print("This should be line ");
MyFile.println(8);
Serial.println("OK");
Serial.print("Closing 'ARDUINO/SD/PRINT.txt' file");
Serial.println("OK");
Expand Down Expand Up @@ -291,7 +293,26 @@ void setup()
} else {
Serial.println("KO --> Error to open 'ARDUINO/SD/WRITE.txt' file");
}

/* Test readBytes(buf, len) method */
Serial.print("Opening 'ARDUINO/SD/WRITE.txt' file...");
MyFile = SD.open("ARDUINO/SD/WRITE.txt");
if (MyFile) {
Serial.println("OK");
Serial.print(" Reading 'ARDUINO/SD/WRITE.txt' file: ");
bytesread = MyFile.readBytes(rtext, MyFile.size());
Serial.print(bytesread);
Serial.println(" bytes read");
Serial.println((const char*)rtext);
Serial.print("Closing 'ARDUINO/SD/WRITE.txt' file...");
MyFile.close();
Serial.println("OK");
} else {
Serial.println("KO --> Error to open 'ARDUINO/SD/WRITE.txt' file");
}
Serial.println("###### End of the SD tests ######");


}

void loop()
Expand Down
5 changes: 4 additions & 1 deletion src/STM32SD.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ uint8_t const LS_SIZE = 2;
/** ls() flag for recursive list of subdirectories */
uint8_t const LS_R = 4;

class File {
class File : public Stream {
public:
File(FRESULT res = FR_OK);
virtual size_t write(uint8_t);
Expand Down Expand Up @@ -78,6 +78,9 @@ class File {
{
return _res;
}

using Print::println;
using Print::print;

};

Expand Down

0 comments on commit 0259bc9

Please sign in to comment.