Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File inherits from Stream: proper support for print and println of al… #72

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
41 changes: 0 additions & 41 deletions src/SD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,47 +547,6 @@ size_t File::write(const uint8_t *buf, size_t size)
return write((const char *)buf, size);
}

/**
* @brief Print data to the file
* @param data: Data to write to the file
* @retval Number of data written (1)
*/
size_t File::print(const char *data)
{
return write(data, strlen(data));
}

/**
* @brief Print data to the file
* @retval Number of data written (1)
*/
size_t File::println()
{
return write("\r\n", 2);
}

/**
* @brief Print data to the file
* @param data: Data to write to the file
* @retval Number of data written (1)
*/
size_t File::println(const char *data)
{
size_t bytewritten = write(data, strlen(data));
bytewritten += println();
return bytewritten;
}

/**
* @brief Print data to the file
* @param data: Data of type String to write to the file
* @retval Number of data written (1)
*/
size_t File::println(String &data)
{
return println(data.c_str());
}

/**
* @brief Check if there are any bytes available for reading from the file
* @retval Number of bytes available
Expand Down
9 changes: 3 additions & 6 deletions 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 All @@ -57,11 +57,6 @@ class File {
File openNextFile(uint8_t mode = FILE_READ);
void rewindDirectory(void);

virtual size_t print(const char *data);
virtual size_t println();
virtual size_t println(const char *data);
virtual size_t println(String &data);

// Print to Serial line
void ls(uint8_t flags, uint8_t indent = 0);
static void printFatDate(uint16_t fatDate);
Expand All @@ -78,6 +73,8 @@ class File {
{
return _res;
}
using Print::println;
using Print::print;

};

Expand Down