From 16a5d94eb95cdbe9d8404d451793f4081a0d3b14 Mon Sep 17 00:00:00 2001 From: Kacper Samolej Date: Wed, 6 Mar 2024 19:19:18 +0100 Subject: [PATCH 1/4] initial commit --- projects/SD/.gitignore | 5 ++++ projects/SD/.vscode/extensions.json | 10 +++++++ projects/SD/include/README | 39 ++++++++++++++++++++++++ projects/SD/include/sd.hpp | 0 projects/SD/lib/README | 46 +++++++++++++++++++++++++++++ projects/SD/platformio.ini | 14 +++++++++ projects/SD/src/main.cpp | 18 +++++++++++ projects/SD/src/sd.cpp | 0 projects/SD/test/README | 11 +++++++ 9 files changed, 143 insertions(+) create mode 100644 projects/SD/.gitignore create mode 100644 projects/SD/.vscode/extensions.json create mode 100644 projects/SD/include/README create mode 100644 projects/SD/include/sd.hpp create mode 100644 projects/SD/lib/README create mode 100644 projects/SD/platformio.ini create mode 100644 projects/SD/src/main.cpp create mode 100644 projects/SD/src/sd.cpp create mode 100644 projects/SD/test/README diff --git a/projects/SD/.gitignore b/projects/SD/.gitignore new file mode 100644 index 0000000..89cc49c --- /dev/null +++ b/projects/SD/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/projects/SD/.vscode/extensions.json b/projects/SD/.vscode/extensions.json new file mode 100644 index 0000000..080e70d --- /dev/null +++ b/projects/SD/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ], + "unwantedRecommendations": [ + "ms-vscode.cpptools-extension-pack" + ] +} diff --git a/projects/SD/include/README b/projects/SD/include/README new file mode 100644 index 0000000..194dcd4 --- /dev/null +++ b/projects/SD/include/README @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/projects/SD/include/sd.hpp b/projects/SD/include/sd.hpp new file mode 100644 index 0000000..e69de29 diff --git a/projects/SD/lib/README b/projects/SD/lib/README new file mode 100644 index 0000000..6debab1 --- /dev/null +++ b/projects/SD/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/projects/SD/platformio.ini b/projects/SD/platformio.ini new file mode 100644 index 0000000..9680fa8 --- /dev/null +++ b/projects/SD/platformio.ini @@ -0,0 +1,14 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:lolin32_lite] +platform = espressif32 +board = lolin32_lite +framework = arduino diff --git a/projects/SD/src/main.cpp b/projects/SD/src/main.cpp new file mode 100644 index 0000000..cb9fbba --- /dev/null +++ b/projects/SD/src/main.cpp @@ -0,0 +1,18 @@ +#include + +// put function declarations here: +int myFunction(int, int); + +void setup() { + // put your setup code here, to run once: + int result = myFunction(2, 3); +} + +void loop() { + // put your main code here, to run repeatedly: +} + +// put function definitions here: +int myFunction(int x, int y) { + return x + y; +} \ No newline at end of file diff --git a/projects/SD/src/sd.cpp b/projects/SD/src/sd.cpp new file mode 100644 index 0000000..e69de29 diff --git a/projects/SD/test/README b/projects/SD/test/README new file mode 100644 index 0000000..9b1e87b --- /dev/null +++ b/projects/SD/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PlatformIO Test Runner and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PlatformIO Unit Testing: +- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html From 42781406853e1beb2def941f27a38346206aedfd Mon Sep 17 00:00:00 2001 From: Kacper Samolej Date: Wed, 13 Mar 2024 20:44:24 +0100 Subject: [PATCH 2/4] read write --- projects/SD/include/sd.hpp | 11 +++++ projects/SD/src/main.cpp | 52 +++++++++++++++++----- projects/SD/src/sd.cpp | 91 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+), 12 deletions(-) diff --git a/projects/SD/include/sd.hpp b/projects/SD/include/sd.hpp index e69de29..f743d42 100644 --- a/projects/SD/include/sd.hpp +++ b/projects/SD/include/sd.hpp @@ -0,0 +1,11 @@ +#pragma once +#include "FS.h" +#include "SD.h" +#include "SPI.h" + + +void createDir(fs::FS &fs, const char * path); +void writeFile(fs::FS &fs, const char * path, const char * message); +void listDir(fs::FS &fs, const char * dirname, uint8_t levels); +void readFile(fs::FS &fs, const char * path); +void writeData(fs::FS &fs, const char * path, const char * message); diff --git a/projects/SD/src/main.cpp b/projects/SD/src/main.cpp index cb9fbba..b734296 100644 --- a/projects/SD/src/main.cpp +++ b/projects/SD/src/main.cpp @@ -1,18 +1,46 @@ -#include +#include "FS.h" +#include "SD.h" +#include "SPI.h" +#include "sd.hpp" -// put function declarations here: -int myFunction(int, int); +void setup(){ + Serial.begin(9600); + if(!SD.begin(5)){ + Serial.println("Card Mount Failed"); + return; + } + uint8_t cardType = SD.cardType(); -void setup() { - // put your setup code here, to run once: - int result = myFunction(2, 3); -} + if(cardType == CARD_NONE){ + Serial.println("No SD card attached"); + return; + } + + Serial.print("SD Card Type: "); + if(cardType == CARD_MMC){ + Serial.println("MMC"); + } else if(cardType == CARD_SD){ + Serial.println("SDSC"); + } else if(cardType == CARD_SDHC){ + + Serial.println("SDHC"); + } else { + Serial.println("UNKNOWN"); + } -void loop() { - // put your main code here, to run repeatedly: + uint64_t cardSize = SD.cardSize() / (1024 * 1024); + Serial.printf("SD Card Size: %lluMB\n", cardSize); + + + + writeFile(SD, "/mydir/hello.txt", "siemano3"); + listDir(SD, "/mydir", 0); + readFile(SD, "/mydir/hello.txt"); + + Serial.printf("Total space: %lluMB\n", SD.totalBytes() / (1024 * 1024)); + Serial.printf("Used space: %lluMB\n", SD.usedBytes() / (1024 * 1024)); } -// put function definitions here: -int myFunction(int x, int y) { - return x + y; +void loop(){ + } \ No newline at end of file diff --git a/projects/SD/src/sd.cpp b/projects/SD/src/sd.cpp index e69de29..c135dab 100644 --- a/projects/SD/src/sd.cpp +++ b/projects/SD/src/sd.cpp @@ -0,0 +1,91 @@ +#include "sd.hpp" + + +void writeFile(fs::FS &fs, const char * path, const char * message){ + Serial.printf("Writing file: %s\n", path); + + File file = fs.open(path, FILE_APPEND); + if(!file){ + Serial.println("Failed to open file for writing"); + return; + } + if(file.println(message)){ + Serial.println("File written"); + } else { + Serial.println("Write failed"); + } + file.close(); +} + +void createDir(fs::FS &fs, const char * path){ + Serial.printf("Creating Dir: %s\n", path); + if(fs.mkdir(path)){ + Serial.println("Dir created"); + } else { + Serial.println("mkdir failed"); + } +} + +void listDir(fs::FS &fs, const char * dirname, uint8_t levels){ + Serial.printf("Listing directory: %s\n", dirname); + + + + File root = fs.open(dirname); + if(!root){ + Serial.println("Failed to open directory"); + return; + } + if(!root.isDirectory()){ + Serial.println("Not a directory"); + return; + } + + File file = root.openNextFile(); + while(file){ + if(file.isDirectory()){ + Serial.print(" DIR : "); + Serial.println(file.name()); + if(levels){ + listDir(fs, file.name(), levels-1); + } + } else { + Serial.print(" FILE: "); + Serial.print(file.name()); + Serial.print(" SIZE: "); + Serial.println(file.size()); + } + file = root.openNextFile(); + } +} + + +void readFile(fs::FS &fs, const char * path){ + Serial.printf("Reading file: %s\n", path); + + File file = fs.open(path); + if(!file){ + Serial.println("Failed to open file for reading"); + return; + } + + Serial.print("Read from file: "); + while(file.available()){ + Serial.write(file.read()); + } + file.close(); +} + +void writeData(fs::FS &fs, const char * path, const char * message){ + File file = fs.open(path, FILE_APPEND); + if(!file){ + Serial.println("Failed to open file for writing"); + return; + } + if(file.println(message)){ + Serial.println("File written"); + } else { + Serial.println("Write failed"); + } + file.close(); +} \ No newline at end of file From 05f5322d403dac8cf51276ae2dbc63fc7f681a9d Mon Sep 17 00:00:00 2001 From: Kacper Samolej Date: Wed, 22 May 2024 19:17:15 +0200 Subject: [PATCH 3/4] update --- projects/SD/include/sd.hpp | 15 ++-- projects/SD/src/main.cpp | 38 +------- projects/SD/src/sd.cpp | 179 +++++++++++++++++++++++-------------- 3 files changed, 124 insertions(+), 108 deletions(-) diff --git a/projects/SD/include/sd.hpp b/projects/SD/include/sd.hpp index f743d42..eda8f3a 100644 --- a/projects/SD/include/sd.hpp +++ b/projects/SD/include/sd.hpp @@ -3,9 +3,12 @@ #include "SD.h" #include "SPI.h" - -void createDir(fs::FS &fs, const char * path); -void writeFile(fs::FS &fs, const char * path, const char * message); -void listDir(fs::FS &fs, const char * dirname, uint8_t levels); -void readFile(fs::FS &fs, const char * path); -void writeData(fs::FS &fs, const char * path, const char * message); +namespace sd +{ + void createDir(fs::FS &fs, const char *path); + void writeFile(fs::FS &fs, const char *path, const char *message); + void listDir(fs::FS &fs, const char *dirname, uint8_t levels); + void readFile(fs::FS &fs, const char *path); + void writeData(fs::FS &fs, const char *path, const char *message); + void setup(); +} \ No newline at end of file diff --git a/projects/SD/src/main.cpp b/projects/SD/src/main.cpp index b734296..f3ac8a8 100644 --- a/projects/SD/src/main.cpp +++ b/projects/SD/src/main.cpp @@ -5,40 +5,10 @@ void setup(){ Serial.begin(9600); - if(!SD.begin(5)){ - Serial.println("Card Mount Failed"); - return; - } - uint8_t cardType = SD.cardType(); - - if(cardType == CARD_NONE){ - Serial.println("No SD card attached"); - return; - } - - Serial.print("SD Card Type: "); - if(cardType == CARD_MMC){ - Serial.println("MMC"); - } else if(cardType == CARD_SD){ - Serial.println("SDSC"); - } else if(cardType == CARD_SDHC){ - - Serial.println("SDHC"); - } else { - Serial.println("UNKNOWN"); - } - - uint64_t cardSize = SD.cardSize() / (1024 * 1024); - Serial.printf("SD Card Size: %lluMB\n", cardSize); - - - - writeFile(SD, "/mydir/hello.txt", "siemano3"); - listDir(SD, "/mydir", 0); - readFile(SD, "/mydir/hello.txt"); - - Serial.printf("Total space: %lluMB\n", SD.totalBytes() / (1024 * 1024)); - Serial.printf("Used space: %lluMB\n", SD.usedBytes() / (1024 * 1024)); + sd::setup(); + sd::writeFile(SD, "/mydir/hello.txt", "siemano4"); + delay(1000); + sd::readFile(SD, "/mydir/hello.txt"); } void loop(){ diff --git a/projects/SD/src/sd.cpp b/projects/SD/src/sd.cpp index c135dab..339538a 100644 --- a/projects/SD/src/sd.cpp +++ b/projects/SD/src/sd.cpp @@ -1,91 +1,134 @@ #include "sd.hpp" +namespace sd +{ -void writeFile(fs::FS &fs, const char * path, const char * message){ - Serial.printf("Writing file: %s\n", path); + void writeFile(fs::FS &fs, const char *path, const char *message) + { + Serial.printf("Writing file: %s\n", path); - File file = fs.open(path, FILE_APPEND); - if(!file){ - Serial.println("Failed to open file for writing"); - return; - } - if(file.println(message)){ - Serial.println("File written"); - } else { - Serial.println("Write failed"); - } - file.close(); -} + File file = fs.open(path, FILE_APPEND); -void createDir(fs::FS &fs, const char * path){ - Serial.printf("Creating Dir: %s\n", path); - if(fs.mkdir(path)){ - Serial.println("Dir created"); - } else { - Serial.println("mkdir failed"); + if (!file) + { + Serial.println("Failed to open file for writing"); + return; + } + + if (file.println(message)) + { + Serial.println("File written"); + } + else + { + Serial.println("Write failed"); + } + file.close(); } -} -void listDir(fs::FS &fs, const char * dirname, uint8_t levels){ - Serial.printf("Listing directory: %s\n", dirname); + void createDir(fs::FS &fs, const char *path) + { + Serial.printf("Creating Dir: %s\n", path); + if (fs.mkdir(path)) + { + Serial.println("Dir created"); + } + else + { + Serial.println("mkdir failed"); + } + } + void listDir(fs::FS &fs, const char *dirname, uint8_t levels) + { + Serial.printf("Listing directory: %s\n", dirname); - File root = fs.open(dirname); - if(!root){ - Serial.println("Failed to open directory"); - return; - } - if(!root.isDirectory()){ - Serial.println("Not a directory"); - return; - } + File root = fs.open(dirname); + if (!root) + { + Serial.println("Failed to open directory"); + return; + } + if (!root.isDirectory()) + { + Serial.println("Not a directory"); + return; + } - File file = root.openNextFile(); - while(file){ - if(file.isDirectory()){ - Serial.print(" DIR : "); - Serial.println(file.name()); - if(levels){ - listDir(fs, file.name(), levels-1); + File file = root.openNextFile(); + while (file) + { + if (file.isDirectory()) + { + Serial.print(" DIR : "); + Serial.println(file.name()); + if (levels) + { + listDir(fs, file.name(), levels - 1); + } + } + else + { + Serial.print(" FILE: "); + Serial.print(file.name()); + Serial.print(" SIZE: "); + Serial.println(file.size()); } - } else { - Serial.print(" FILE: "); - Serial.print(file.name()); - Serial.print(" SIZE: "); - Serial.println(file.size()); + file = root.openNextFile(); } - file = root.openNextFile(); } -} - -void readFile(fs::FS &fs, const char * path){ - Serial.printf("Reading file: %s\n", path); + void readFile(fs::FS &fs, const char *path) + { + Serial.printf("Reading file: %s\n", path); - File file = fs.open(path); - if(!file){ - Serial.println("Failed to open file for reading"); - return; - } + File file = fs.open(path); + if (!file) + { + Serial.println("Failed to open file for reading"); + return; + } - Serial.print("Read from file: "); - while(file.available()){ - Serial.write(file.read()); + Serial.print("Read from file: \n"); + while (file.available()) + { + Serial.write(file.read()); + } + file.close(); } - file.close(); -} -void writeData(fs::FS &fs, const char * path, const char * message){ + void writeData(fs::FS &fs, const char *path, const char *message) + { File file = fs.open(path, FILE_APPEND); - if(!file){ - Serial.println("Failed to open file for writing"); - return; + if (!file) + { + Serial.println("Failed to open file for writing"); + return; + } + if (file.println(message)) + { + Serial.println("File written"); + } + else + { + Serial.println("Write failed"); + } + file.close(); } - if(file.println(message)){ - Serial.println("File written"); - } else { - Serial.println("Write failed"); + void setup() + { + if (!SD.begin(5)) + { + Serial.println("Card Mount Failed"); + return; + } + uint8_t cardType = SD.cardType(); + + if (cardType == CARD_NONE) + { + Serial.println("No SD card attached"); + return; + } } - file.close(); } \ No newline at end of file From 67170b6604c61578a6d38408f75544fa454e9991 Mon Sep 17 00:00:00 2001 From: Kacper Samolej Date: Wed, 22 May 2024 19:35:26 +0200 Subject: [PATCH 4/4] formatowanie kodu --- projects/SD/.gitignore | 3 +- projects/SD/include/sd.hpp | 17 ++-- projects/SD/src/main.cpp | 8 +- projects/SD/src/sd.cpp | 191 ++++++++++++++++--------------------- 4 files changed, 94 insertions(+), 125 deletions(-) diff --git a/projects/SD/.gitignore b/projects/SD/.gitignore index 89cc49c..04228b4 100644 --- a/projects/SD/.gitignore +++ b/projects/SD/.gitignore @@ -2,4 +2,5 @@ .vscode/.browse.c_cpp.db* .vscode/c_cpp_properties.json .vscode/launch.json -.vscode/ipch +.vscode/settings.json +.vscode/ipch \ No newline at end of file diff --git a/projects/SD/include/sd.hpp b/projects/SD/include/sd.hpp index eda8f3a..0a1191c 100644 --- a/projects/SD/include/sd.hpp +++ b/projects/SD/include/sd.hpp @@ -3,12 +3,11 @@ #include "SD.h" #include "SPI.h" -namespace sd -{ - void createDir(fs::FS &fs, const char *path); - void writeFile(fs::FS &fs, const char *path, const char *message); - void listDir(fs::FS &fs, const char *dirname, uint8_t levels); - void readFile(fs::FS &fs, const char *path); - void writeData(fs::FS &fs, const char *path, const char *message); - void setup(); -} \ No newline at end of file +namespace sd { +void createDir(fs::FS &fs, const char *path); +void writeFile(fs::FS &fs, const char *path, const char *message); +void listDir(fs::FS &fs, const char *dirname, uint8_t levels); +void readFile(fs::FS &fs, const char *path); +void writeData(fs::FS &fs, const char *path, const char *message); +void setup(); +} // namespace sd \ No newline at end of file diff --git a/projects/SD/src/main.cpp b/projects/SD/src/main.cpp index f3ac8a8..a2b5dbd 100644 --- a/projects/SD/src/main.cpp +++ b/projects/SD/src/main.cpp @@ -3,14 +3,12 @@ #include "SPI.h" #include "sd.hpp" -void setup(){ +void setup() { Serial.begin(9600); sd::setup(); - sd::writeFile(SD, "/mydir/hello.txt", "siemano4"); + // sd::writeFile(SD, "/mydir/hello.txt", "siemano4"); delay(1000); sd::readFile(SD, "/mydir/hello.txt"); } -void loop(){ - -} \ No newline at end of file +void loop() {} \ No newline at end of file diff --git a/projects/SD/src/sd.cpp b/projects/SD/src/sd.cpp index 339538a..bec8a5e 100644 --- a/projects/SD/src/sd.cpp +++ b/projects/SD/src/sd.cpp @@ -1,134 +1,105 @@ #include "sd.hpp" -namespace sd -{ +namespace sd { - void writeFile(fs::FS &fs, const char *path, const char *message) - { - Serial.printf("Writing file: %s\n", path); +void writeFile(fs::FS &fs, const char *path, const char *message) { + Serial.printf("Writing file: %s\n", path); - File file = fs.open(path, FILE_APPEND); + File file = fs.open(path, FILE_APPEND); - if (!file) - { - Serial.println("Failed to open file for writing"); - return; - } + if (!file) { + Serial.println("Failed to open file for writing"); + return; + } - if (file.println(message)) - { - Serial.println("File written"); - } - else - { - Serial.println("Write failed"); - } - file.close(); + if (file.println(message)) { + Serial.println("File written"); + } else { + Serial.println("Write failed"); } + file.close(); +} - void createDir(fs::FS &fs, const char *path) - { - Serial.printf("Creating Dir: %s\n", path); +void createDir(fs::FS &fs, const char *path) { + Serial.printf("Creating Dir: %s\n", path); - if (fs.mkdir(path)) - { - Serial.println("Dir created"); - } - else - { - Serial.println("mkdir failed"); - } + if (fs.mkdir(path)) { + Serial.println("Dir created"); + } else { + Serial.println("mkdir failed"); } +} - void listDir(fs::FS &fs, const char *dirname, uint8_t levels) - { - Serial.printf("Listing directory: %s\n", dirname); +void listDir(fs::FS &fs, const char *dirname, uint8_t levels) { + Serial.printf("Listing directory: %s\n", dirname); - File root = fs.open(dirname); - if (!root) - { - Serial.println("Failed to open directory"); - return; - } - if (!root.isDirectory()) - { - Serial.println("Not a directory"); - return; - } + File root = fs.open(dirname); + if (!root) { + Serial.println("Failed to open directory"); + return; + } + if (!root.isDirectory()) { + Serial.println("Not a directory"); + return; + } - File file = root.openNextFile(); - while (file) - { - if (file.isDirectory()) - { - Serial.print(" DIR : "); - Serial.println(file.name()); - if (levels) - { - listDir(fs, file.name(), levels - 1); - } - } - else - { - Serial.print(" FILE: "); - Serial.print(file.name()); - Serial.print(" SIZE: "); - Serial.println(file.size()); + File file = root.openNextFile(); + while (file) { + if (file.isDirectory()) { + Serial.print(" DIR : "); + Serial.println(file.name()); + if (levels) { + listDir(fs, file.name(), levels - 1); } - file = root.openNextFile(); + } else { + Serial.print(" FILE: "); + Serial.print(file.name()); + Serial.print(" SIZE: "); + Serial.println(file.size()); } + file = root.openNextFile(); } +} - void readFile(fs::FS &fs, const char *path) - { - Serial.printf("Reading file: %s\n", path); +void readFile(fs::FS &fs, const char *path) { + Serial.printf("Reading file: %s\n", path); - File file = fs.open(path); - if (!file) - { - Serial.println("Failed to open file for reading"); - return; - } + File file = fs.open(path); + if (!file) { + Serial.println("Failed to open file for reading"); + return; + } - Serial.print("Read from file: \n"); - while (file.available()) - { - Serial.write(file.read()); - } - file.close(); + Serial.print("Read from file: \n"); + while (file.available()) { + Serial.write(file.read()); } + file.close(); +} - void writeData(fs::FS &fs, const char *path, const char *message) - { - File file = fs.open(path, FILE_APPEND); - if (!file) - { - Serial.println("Failed to open file for writing"); - return; - } - if (file.println(message)) - { - Serial.println("File written"); - } - else - { - Serial.println("Write failed"); - } - file.close(); +void writeData(fs::FS &fs, const char *path, const char *message) { + File file = fs.open(path, FILE_APPEND); + if (!file) { + Serial.println("Failed to open file for writing"); + return; } - void setup() - { - if (!SD.begin(5)) - { - Serial.println("Card Mount Failed"); - return; - } - uint8_t cardType = SD.cardType(); + if (file.println(message)) { + Serial.println("File written"); + } else { + Serial.println("Write failed"); + } + file.close(); +} +void setup() { + if (!SD.begin(5)) { + Serial.println("Card Mount Failed"); + return; + } + uint8_t cardType = SD.cardType(); - if (cardType == CARD_NONE) - { - Serial.println("No SD card attached"); - return; - } + if (cardType == CARD_NONE) { + Serial.println("No SD card attached"); + return; } -} \ No newline at end of file +} +} // namespace sd \ No newline at end of file