From fbd399023d8be0dea37035b793e42be5784d289a Mon Sep 17 00:00:00 2001 From: Stephan Enderlein Date: Tue, 30 Apr 2024 10:06:51 +0200 Subject: [PATCH 01/10] Fix whitespaces --- .../InternalStoragePartitioning.ino | 16 +++++++------- src/InternalStorage.h | 22 +++++++++---------- src/Partitioning.cpp | 14 ++++++------ src/Utils.h | 2 +- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/examples/InternalStoragePartitioning/InternalStoragePartitioning.ino b/examples/InternalStoragePartitioning/InternalStoragePartitioning.ino index 58d6934..2b9b66b 100644 --- a/examples/InternalStoragePartitioning/InternalStoragePartitioning.ino +++ b/examples/InternalStoragePartitioning/InternalStoragePartitioning.ino @@ -4,13 +4,13 @@ This example demonstrates the usage of the "Arduino_UnifiedStorage" library for retrieving and creating partitions on the internal storage. The code should help you understand how to work with partitions and perform file operations in different partitions. - It creates the partitions specified in the std::vector you find at the top of the sketch. + It creates the partitions specified in the std::vector you find at the top of the sketch. You can define your own, as long as the size of all partitions doesn't exceed the size of your board's QSPI flash( if you are in doubt about that check docs.arduino.com for more information) and as long as you don't have more than 4 partitions (MBR limitation) The Partition struct has two values: - `size` the size of your partition in kilobytes - 'fileSystemType` which can be either `FS_FAT` or `FS_LITTLEFS` - Here are a few examples of valid partitioning schemes: + Here are a few examples of valid partitioning schemes: - std::vector partitioningScheme = {{16384, FS_FAT}}; - std::vector partitioningScheme = {{2048, FS_FAT}, {6144, FS_FAT} {8192, FS_LITTLEFS}}; - std::vector partitioningScheme = {{4096, FS_LITTLEFS}, {4096, FS_FAT}, {4096, FS_LITTLEFS}, {4096, FS_FAT}}; @@ -24,8 +24,8 @@ INSTRUCTIONS: 1. Check compatibility with your board and make sure you have "POSIXStorage" and "Arduino_UnifiedStorage" installed 2. Connect your board to the serial monitor - 3. Wait for the sketch to run - 4. Modify the partitioning scheme according to your needs + 3. Wait for the sketch to run + 4. Modify the partitioning scheme according to your needs Created: 26th October 2023 By: Cristian Dragomir @@ -36,7 +36,7 @@ #include // Create a vector of partitions with one partition of 16MB using LittleFS -std::vector partitioningScheme = { +std::vector partitioningScheme = { {1024, FS_FAT}, // 1 MB for certificates {5120, FS_FAT}, // 5 MB for OTA firmware updates {8192, FS_LITTLEFS} // 8 MB for user data @@ -50,7 +50,7 @@ void testWriting(Arduino_UnifiedStorage *storage) { // Create a new file named "file.txt" for writing UFile file = root.createFile("file.txt", FileMode::WRITE); Serial.println("\t\t - File path: " + file.getPathAsString()); - + // Write data to the file file.write("writing stuff to the file"); @@ -65,7 +65,7 @@ void testWriting(Arduino_UnifiedStorage *storage) { void testAllPartitions(std::vector partitions) { for (size_t i = 1; i < partitions.size() + 1; ++i) { const char *partitionName = createPartitionName(i); - + // Create an InternalStorage object for the partition InternalStorage thisPartition = InternalStorage(i, partitionName, partitions[i - 1].fileSystemType); @@ -113,7 +113,7 @@ void setup() { delay(1000); - // Read the MBR sector and display the partitions + // Read the MBR sector and display the partitions listPartitions(); } diff --git a/src/InternalStorage.h b/src/InternalStorage.h index cfe4b10..42f33de 100644 --- a/src/InternalStorage.h +++ b/src/InternalStorage.h @@ -10,19 +10,19 @@ */ class InternalStorage : public Arduino_UnifiedStorage { public: - + /** * Constructs an InternalStorage object with default settings. * If no partitions are available, it restores the default partitioning scheme (See restoreDefaultPartitions() for more info). * If partitions are available, it sets the partition number, file system type, and partition name based on the last partition available. - * When using the default partitioning scheme the last partition would be the user partition. + * When using the default partitioning scheme the last partition would be the user partition. */ InternalStorage(); /** * Constructs an InternalStorage object with the specified partition, name, and file system. - * + * * @param partition The partition number. * @param name The name of the partition. * @param fs The desired file system (FS_FAT or FS_LITTLEFS). @@ -31,14 +31,14 @@ class InternalStorage : public Arduino_UnifiedStorage { /** * Initializes the internal storage. - * + * * @return true if successful, false if failed. */ bool begin() override; /** * Initializes the internal storage with the specified file system. - * + * * @param fs The desired file system (FS_FAT or FS_LITTLEFS). * @return true if successful, false if failed. */ @@ -46,14 +46,14 @@ class InternalStorage : public Arduino_UnifiedStorage { /** * Unmounts the internal storage. - * + * * @return true if successful, false if failed. */ bool unmount() override; /** * Retrieves the root folder of the internal storage. - * + * * @return The root folder as a Folder object. */ Folder getRootFolder() override; @@ -61,7 +61,7 @@ class InternalStorage : public Arduino_UnifiedStorage { /** * Formats the internal storage with the selected file system. - * + * * @return true if successful, false if failed. */ bool format(FileSystems fs) override; @@ -69,7 +69,7 @@ class InternalStorage : public Arduino_UnifiedStorage { /** * Retrieves the block device associated with the internal storage. - * + * * @return The block device as a BlockDevice object. */ BlockDeviceType *getBlockDevice(); @@ -86,7 +86,7 @@ class InternalStorage : public Arduino_UnifiedStorage { * Creates one partition spanning over the whole size of the internal storage drive erasing the existing partitions. * @return true if successful, false if failed. */ - static bool partition(); + static bool partition(); /** * Restores the default partitioning scheme (1MB FAT32 for Certificates, 5MB FAT32 for OTA, 8MB user storage) to the internal storage drive erasing the existing partitions. @@ -96,7 +96,7 @@ class InternalStorage : public Arduino_UnifiedStorage { /** * Reads the partitioning scheme from the MBR sector of the internal storage drive and returns a vector of structs of type Partition that represents the partitioning scheme - * @return vector of structs of type Partition + * @return vector of structs of type Partition */ static std::vector readPartitions(); diff --git a/src/Partitioning.cpp b/src/Partitioning.cpp index 2a4f196..13ba94c 100644 --- a/src/Partitioning.cpp +++ b/src/Partitioning.cpp @@ -21,7 +21,7 @@ bool Partitioning::eraseMBRSector(BlockDeviceType * blockDevice) } bool Partitioning::isPartitionSchemeValid(BlockDeviceType * blockDevice, std::vector partitions){ - size_t driveSize = blockDevice -> size() / 1024; // + size_t driveSize = blockDevice -> size() / 1024; // size_t totalSize = 0; for (size_t i = 1; i < partitions.size() + 1; ++i) { @@ -72,7 +72,7 @@ bool Partitioning::formatPartition(BlockDeviceType * blockDevice, int partitionN } bool Partitioning::createAndFormatPartitions(BlockDeviceType * blockDevice, std::vector partitions){ - + bool success = true; // initialize to true int lastPartitionEnd = 0; @@ -117,7 +117,7 @@ bool Partitioning::partitionDrive(BlockDeviceType * blockDevice, std::vector Partitioning::readPartitions(BlockDeviceType * blockDevice){ std::vector partitions; - + auto returnCode = blockDevice->init(); if (returnCode) { Arduino_UnifiedStorage::debugPrint("[Partitioning][readPartitions][ERROR] Unable to read the Block Device."); @@ -142,9 +142,9 @@ std::vector Partitioning::readPartitions(BlockDeviceType * blockDevic auto table_start_offset = buffer_size - sizeof(mbrTable); auto table = reinterpret_cast(&buffer[table_start_offset]); - + if (table->signature[0] != mbrMagicNumbers[0] || table->signature[1] != mbrMagicNumbers[1]) { - + Arduino_UnifiedStorage::debugPrint("[Partitioning][readPartitions][INFO] MBR Not Found - Flash Memory doesn't have partitions."); delete[] buffer; return partitions; @@ -156,9 +156,9 @@ std::vector Partitioning::readPartitions(BlockDeviceType * blockDevic Partition partition; /*This code calculates the size of a partition in kilobytes. - It takes the Logical Block Address (LBA) size of the partition, + It takes the Logical Block Address (LBA) size of the partition, multiplies it by 4096 (the size of a block in bytes), - and then shifts the result 10 bits to the right to convert it to kilobytes. + and then shifts the result 10 bits to the right to convert it to kilobytes. */ partition.size = (entry.lbaSize * 4096) >> 10; diff --git a/src/Utils.h b/src/Utils.h index 628664c..027725e 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -215,4 +215,4 @@ -#endif +#endif From bd8600ccc0c454631cc41bf2928c6c80b0bc95de Mon Sep 17 00:00:00 2001 From: Stephan Enderlein Date: Tue, 30 Apr 2024 10:05:36 +0200 Subject: [PATCH 02/10] Various fixes for begin(),umount(),format() --- .../InternalStoragePartitioning.ino | 2 + src/InternalStorage.cpp | 58 ++++++++++++------- src/InternalStorage.h | 4 +- src/Partitioning.cpp | 41 +++++++------ src/Utils.h | 37 +++++++++--- 5 files changed, 95 insertions(+), 47 deletions(-) diff --git a/examples/InternalStoragePartitioning/InternalStoragePartitioning.ino b/examples/InternalStoragePartitioning/InternalStoragePartitioning.ino index 2b9b66b..69b2693 100644 --- a/examples/InternalStoragePartitioning/InternalStoragePartitioning.ino +++ b/examples/InternalStoragePartitioning/InternalStoragePartitioning.ino @@ -74,6 +74,8 @@ void testAllPartitions(std::vector partitions) { Serial.println("\t - Successfully mounted partition: /" + String(partitionName)); Serial.println("\t - Testing file operations: "); testWriting(&thisPartition); // Test writing to a file in the partition + thisPartition.unmount(); + freePartitionName(partitionName); } Serial.println(); diff --git a/src/InternalStorage.cpp b/src/InternalStorage.cpp index 034ff81..3edc15d 100644 --- a/src/InternalStorage.cpp +++ b/src/InternalStorage.cpp @@ -6,21 +6,32 @@ InternalStorage::InternalStorage(){ //Arduino_UnifiedStorage::debugPrint("[InternalStorage][INFO] No partitions found, restoring default partitions"); restoreDefaultPartitions(); - } else { - int lastPartitionNumber = partitionsAvailable.size(); - FileSystems lastPartitionFileSystem = partitionsAvailable.back().fileSystemType; - //Arduino_UnifiedStorage::debugPrint("[InternalStorage][INFO] Found " + String(lastPartitionNumber) + " partitions, using last partition as internal storage"); - - this -> partitionNumber = lastPartitionNumber; - this -> fileSystemType = lastPartitionFileSystem; - this -> partitionName = (char *)"internal"; + // re-read table + partitionsAvailable = Partitioning::readPartitions(QSPIFBlockDeviceType::get_default_instance()); } + + int lastPartitionNumber = partitionsAvailable.size(); + FileSystems lastPartitionFileSystem = partitionsAvailable.back().fileSystemType; + //Arduino_UnifiedStorage::debugPrint("[InternalStorage][INFO] Found " + String(lastPartitionNumber) + " partitions, using last partition as internal storage"); + + this -> partitionNumber = lastPartitionNumber; + this -> fileSystemType = lastPartitionFileSystem; + this -> partitionName = (char *)"internal"; + this -> blockDevice = BlockDeviceType::get_default_instance(); + this -> mbrBlockDevice = new MBRBlockDeviceType(this -> blockDevice, this->partitionNumber); } InternalStorage::InternalStorage(int partition, const char * name, FileSystems fileSystemType){ this -> partitionNumber = partition; - this -> partitionName = (char *)name; + this -> partitionName = name; this -> fileSystemType = fileSystemType; + this -> blockDevice = BlockDeviceType::get_default_instance(); + this -> mbrBlockDevice = new MBRBlockDeviceType(this -> blockDevice, this->partitionNumber); +} + +InternalStorage::~InternalStorage() +{ + delete this -> mbrBlockDevice; } bool InternalStorage::begin(FileSystems fileSystemType){ @@ -49,9 +60,6 @@ std::vector InternalStorage::readPartitions(){ } bool InternalStorage::begin(){ - - this -> blockDevice = BlockDeviceType::get_default_instance(); - this -> mbrBlockDevice = new MBRBlockDeviceType(this->blockDevice, this->partitionNumber); if(this -> fileSystemType == FS_FAT){ this -> fileSystem = new FATFileSystemType(this->partitionName); @@ -61,7 +69,7 @@ bool InternalStorage::begin(){ Arduino_UnifiedStorage::debugPrint("[InternalStorage][begin][INFO] Mounting partition " + String(this->partitionNumber) + " as LittleFS"); } - int err = this -> fileSystem -> mount(mbrBlockDevice); + int err = this -> fileSystem -> mount(this -> mbrBlockDevice); if(err!=0){ Arduino_UnifiedStorage::debugPrint("[InternalStorage][ERROR] Could not mount partition " + String(this->partitionNumber) + " as " + prettyPrintFileSystemType(this->fileSystemType) + ", error code: " + String(errno)); } @@ -69,7 +77,15 @@ bool InternalStorage::begin(){ } bool InternalStorage::unmount(){ - int err = this -> fileSystem -> unmount(); + int err = 0; + + if(this -> fileSystem) + { + err = this -> fileSystem -> unmount(); + delete this -> fileSystem; + this -> fileSystem = NULL; + } + return err == 0; } @@ -78,23 +94,25 @@ Folder InternalStorage::getRootFolder(){ } bool InternalStorage::format(FileSystems fs){ - this -> begin(); + FileSystemType * tmpFileSystem = nullptr; this -> unmount(); this -> fileSystemType = fs; if(fs == FS_FAT){ - this -> fileSystem = new FATFileSystemType(this->partitionName); - int err = this -> fileSystem -> reformat(this-> mbrBlockDevice); + tmpFileSystem = new FATFileSystemType(this->partitionName); + int err = tmpFileSystem -> reformat(this-> mbrBlockDevice); if(err != 0){ Arduino_UnifiedStorage::debugPrint("[InternalStorage][format][ERROR] Error formatting partition " + String(this->partitionNumber) + " as FAT: " + String(errno)); - } + } + delete tmpFileSystem; return err == 0; } if (fs == FS_LITTLEFS) { - this -> fileSystem = new LittleFileSystemType(this->partitionName); - int err = this -> fileSystem -> reformat(this-> mbrBlockDevice); + tmpFileSystem = new LittleFileSystemType(this->partitionName); + int err = tmpFileSystem -> reformat(this-> mbrBlockDevice); if(err != 0){ Arduino_UnifiedStorage::debugPrint("[InternalStorage][format][ERROR] Error formatting partition " + String(this->partitionNumber) + " as LittleFS: " + String(errno)); } + delete tmpFileSystem; return err == 0; } diff --git a/src/InternalStorage.h b/src/InternalStorage.h index 42f33de..13ff514 100644 --- a/src/InternalStorage.h +++ b/src/InternalStorage.h @@ -29,6 +29,8 @@ class InternalStorage : public Arduino_UnifiedStorage { */ InternalStorage(int partition, const char *name, FileSystems fs); + ~InternalStorage(); + /** * Initializes the internal storage. * @@ -105,7 +107,7 @@ class InternalStorage : public Arduino_UnifiedStorage { MBRBlockDeviceType * mbrBlockDevice; FileSystemType * fileSystem; int partitionNumber; - char * partitionName; + const char * partitionName; FileSystems fileSystemType; }; diff --git a/src/Partitioning.cpp b/src/Partitioning.cpp index 13ba94c..8db353a 100644 --- a/src/Partitioning.cpp +++ b/src/Partitioning.cpp @@ -135,7 +135,7 @@ std::vector Partitioning::readPartitions(BlockDeviceType * blockDevic returnCode = blockDevice->read(buffer, 512 - buffer_size, buffer_size); if (returnCode) { Arduino_UnifiedStorage::debugPrint("[Partitioning][readPartitions][ERROR] Unable to read the Master Boot Record"); - + blockDevice->deinit(); delete[] buffer; return partitions; } @@ -146,6 +146,7 @@ std::vector Partitioning::readPartitions(BlockDeviceType * blockDevic if (table->signature[0] != mbrMagicNumbers[0] || table->signature[1] != mbrMagicNumbers[1]) { Arduino_UnifiedStorage::debugPrint("[Partitioning][readPartitions][INFO] MBR Not Found - Flash Memory doesn't have partitions."); + blockDevice->deinit(); delete[] buffer; return partitions; } @@ -171,24 +172,30 @@ std::vector Partitioning::readPartitions(BlockDeviceType * blockDevic MBRBlockDeviceType * mbrBlocKDevice = new MBRBlockDeviceType(blockDevice, partitionIndex); FATFileSystemType * fatProbeFileSystem = new FATFileSystemType("probing"); LittleFileSystemType * littleFsProbeFilesystem = new LittleFileSystemType("probing"); - - if(fatProbeFileSystem -> mount(mbrBlocKDevice) == 0){ - Arduino_UnifiedStorage::debugPrint("[Partitioning][readPartitions][INFO] Partition " + String(partitionIndex) + " is formatted with FAT file system"); - fatProbeFileSystem -> unmount(); - partition.fileSystemType = FS_FAT; - partitions.push_back(partition); - - } else if (littleFsProbeFilesystem -> mount(mbrBlocKDevice) == 0){ - Arduino_UnifiedStorage::debugPrint("[Partitioning][readPartitions][INFO] Partition " + String(partitionIndex) + " is formatted with LittleFS file system"); - littleFsProbeFilesystem -> unmount(); - partition.fileSystemType = FS_LITTLEFS; - partitions.push_back(partition); - } else { - Arduino_UnifiedStorage::debugPrint("[Partitioning][readPartitions][INFO] Partition " + String(partitionIndex) + " is not formatted with a recognized file system"); + + if(mbrBlocKDevice && fatProbeFileSystem && littleFsProbeFilesystem) + { + if(fatProbeFileSystem -> mount(mbrBlocKDevice) == 0){ + Arduino_UnifiedStorage::debugPrint("[Partitioning][readPartitions][INFO] Partition " + String(partitionIndex) + " is formatted with FAT file system"); + fatProbeFileSystem -> unmount(); + partition.fileSystemType = FS_FAT; + partitions.push_back(partition); + + } else if (littleFsProbeFilesystem -> mount(mbrBlocKDevice) == 0){ + Arduino_UnifiedStorage::debugPrint("[Partitioning][readPartitions][INFO] Partition " + String(partitionIndex) + " is formatted with LittleFS file system"); + littleFsProbeFilesystem -> unmount(); + partition.fileSystemType = FS_LITTLEFS; + partitions.push_back(partition); + } else { + Arduino_UnifiedStorage::debugPrint("[Partitioning][readPartitions][INFO] Partition " + String(partitionIndex) + " is not formatted with a recognized file system"); + } } - - } + delete mbrBlocKDevice; + delete fatProbeFileSystem; + delete littleFsProbeFilesystem; + } + blockDevice->deinit(); delete[] buffer; return partitions; } diff --git a/src/Utils.h b/src/Utils.h index 027725e..0d70578 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -56,11 +56,17 @@ // Dynamically allocate memory for the string and copy the generated value char* dynamicName = new char[strlen(partitionName) + 1]; - strcpy(dynamicName, partitionName); + if(dynamicName) + { + strcpy(dynamicName, partitionName); + } return dynamicName; } +[[gnu::unused]] static void freePartitionName(const char* partitionName) { + delete[] partitionName; +} [[gnu::unused]] static bool copyFolder(const char* source, const char* destination) { DIR* dir = opendir(source); @@ -88,7 +94,16 @@ size_t destinationPathLength = strlen(destination) + strlen(entry->d_name) + 1; char* sourcePath = new char[sourcePathLength]; + if(!sourcePath) + { + return false; + } char* destinationPath = new char[destinationPathLength]; + if(!destinationPath) + { + delete[] sourcePath; + return false; + } snprintf(sourcePath, sourcePathLength, "%s/%s", source, entry->d_name); @@ -97,8 +112,8 @@ struct stat fileInfo; if (stat(sourcePath, &fileInfo) != 0) { closedir(dir); - delete(sourcePath); - delete(destinationPath); + delete[] sourcePath; + delete[] destinationPath; return false; } @@ -106,8 +121,8 @@ // Recursively copy subdirectories if (!copyFolder(sourcePath, destinationPath)) { closedir(dir); - delete(sourcePath); - delete(destinationPath); + delete[] sourcePath; + delete[] destinationPath; return false; } } else { @@ -115,8 +130,8 @@ FILE* sourceFile = fopen(sourcePath, "r"); if (sourceFile == nullptr) { closedir(dir); - delete(sourcePath); - delete(destinationPath); + delete[] sourcePath; + delete[] destinationPath; return false; } @@ -124,8 +139,8 @@ if (destinationFile == nullptr) { fclose(sourceFile); closedir(dir); - delete(sourcePath); - delete(destinationPath); + delete[] sourcePath; + delete[] destinationPath; return false; } @@ -137,6 +152,10 @@ fclose(sourceFile); fclose(destinationFile); } + + delete[] sourcePath; + delete[] destinationPath; + } closedir(dir); From 93d9c79828535d2f57c0766f6e69e2d4a0fb3aaf Mon Sep 17 00:00:00 2001 From: Sebastian Romero Date: Mon, 5 May 2025 14:42:18 +0200 Subject: [PATCH 03/10] Add open function without path --- src/UFile.cpp | 9 +++++++++ src/UFile.h | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/src/UFile.cpp b/src/UFile.cpp index c7d759a..0ac8b10 100644 --- a/src/UFile.cpp +++ b/src/UFile.cpp @@ -51,6 +51,15 @@ bool UFile::open(String filename, FileMode mode) { return open(filename.c_str(), mode); } +bool UFile::open(FileMode mode) { + if (path.empty()) { + // Path is not set + return false; + } + + return open(path.c_str(), mode); +} + void UFile::close() { // Close the file if (filePointer != nullptr) { diff --git a/src/UFile.h b/src/UFile.h index 105147c..3f1bc8e 100644 --- a/src/UFile.h +++ b/src/UFile.h @@ -52,6 +52,12 @@ class UFile{ */ bool open(String filename, FileMode mode); + /** + * @brief Opens a file that was already initialized with a path. + * @param mode The file mode (READ, WRITE, or APPEND). The default is READ. + * @return True if the file was opened successfully, false otherwise. + */ + bool open(FileMode mode = FileMode::READ); /** * @brief Closes the file and releases any allocated resources. From 2907ec0da9bcd85742194a20111ed7e6e1f80420 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 19 Jun 2025 14:35:19 +0000 Subject: [PATCH 04/10] Update documentation --- docs/api.md | 53 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/docs/api.md b/docs/api.md index d159bbe..8a9178b 100644 --- a/docs/api.md +++ b/docs/api.md @@ -121,12 +121,12 @@ Class representing a directory. | [`rename`](#class_folder_1adcbb7766d628810f716887d1e7e8d36f) | Renames a directory. | | [`rename`](#class_folder_1a14519c2a344ebfb8161c2bee2a2b5464) | Renames a directory. | | [`exists`](#class_folder_1aa548278d3ec09fd4abcaa827a79c40f4) | Checks if the directory exists. | -| [`getPath`](#class_folder_1a731e8d84685eca8e273affba152468a6) | Returns the path of the file. | +| [`getPath`](#class_folder_1a0ef68289c526f8bf24020389c4e09e86) | Returns the path of the file. | | [`getPathAsString`](#class_folder_1ac816d0fe5674c4648e97423b6f9c51f8) | Returns the path of the file. | | [`createSubfolder`](#class_folder_1a78f2f9b297f62b67c2e0656b15a95868) | Creates a subfolder in the directory. | | [`createSubfolder`](#class_folder_1ab50743664becb7b2a1fb564b5513d69c) | Creates a subfolder in the directory. | -| [`getFiles`](#class_folder_1a3c2e01e19b48e3aa709cbdbb0acbdd78) | Returns File objects for all files in the current directory. | -| [`getFolders`](#class_folder_1a69d3df42dacbd1d64d0f527e090f1fbb) | Returns [Folder](#class_folder) objects for all files in the current directory. | +| [`getFiles`](#class_folder_1a2e7f604d19b8ad61524f86ade86ed4ad) | Returns File objects for all files in the current directory. | +| [`getFolders`](#class_folder_1a5554b8cc2fd1ca39dfccbd06bc635e10) | Returns [Folder](#class_folder) objects for all files in the current directory. | | [`copyTo`](#class_folder_1aabf0818b7ee45b2d871e82e86edb4ebd) | Copies the current directory. | | [`copyTo`](#class_folder_1a058d193f53c559eefe343b30797500eb) | Copies the current directory. | | [`copyTo`](#class_folder_1a3162979e4c679c7f5503cc4584949714) | Copies the current directory. | @@ -254,7 +254,7 @@ Checks if the directory exists. True if the directory exists, false otherwise.
-### `getPath` +### `getPath` ```cpp const char * getPath() @@ -312,7 +312,7 @@ Creates a subfolder in the directory. The created subfolder.
-### `getFiles` +### `getFiles` ```cpp std::vector< UFile > getFiles() @@ -324,7 +324,7 @@ Returns File objects for all files in the current directory. A std::vector of File objects representing the files in the directory.
-### `getFolders` +### `getFolders` ```cpp std::vector< Folder > getFolders() @@ -451,16 +451,17 @@ Represents internal storage using the Arduino Unified Storage library. --------------------------------|--------------------------------------------- | [`InternalStorage`](#class_internal_storage_1ac45948ef554bc659efed81240140192e) | Constructs an [InternalStorage](#class_internal_storage) object with default settings. If no partitions are available, it restores the default partitioning scheme (See [restoreDefaultPartitions()](#class_internal_storage_1ace77d2372832c2f9ef39d382cc443259) for more info). If partitions are available, it sets the partition number, file system type, and partition name based on the last partition available. When using the default partitioning scheme the last partition would be the user partition. | | [`InternalStorage`](#class_internal_storage_1ac13cad019a2ae66647d1c3604690eca7) | Constructs an [InternalStorage](#class_internal_storage) object with the specified partition, name, and file system. | +| [`~InternalStorage`](#class_internal_storage_1a718df11687329b437bc4e2bf420490c0) | | | [`begin`](#class_internal_storage_1a984731348dfbdade84e24250133a033e) | Initializes the internal storage. | | [`begin`](#class_internal_storage_1a90cd409874d9c578ce3add4df88875e5) | Initializes the internal storage with the specified file system. | | [`unmount`](#class_internal_storage_1a663446e2135a4e91d7fdb8ca638cc027) | Unmounts the internal storage. | | [`getRootFolder`](#class_internal_storage_1a87142ddbdad62217e33851b32572082d) | Retrieves the root folder of the internal storage. | | [`format`](#class_internal_storage_1a9ee819a55de5d411e6b10bdc9942c601) | Formats the internal storage with the selected file system. | -| [`getBlockDevice`](#class_internal_storage_1a499c1975764c56ad3770ef9c582d7dda) | Retrieves the block device associated with the internal storage. | +| [`getBlockDevice`](#class_internal_storage_1af347558e09045a5dd868f93b24286bab) | Retrieves the block device associated with the internal storage. | | [`partition`](#class_internal_storage_1acd4f9617061b962f38b20a4c6ddb8d48) | Partitions the internal storage according to the partitioning scheme given in the `partitions` parameter erasing the existing partitions | | [`partition`](#class_internal_storage_1aefb31c03b94006e75b18111f07c99331) | Creates one partition spanning over the whole size of the internal storage drive erasing the existing partitions. | | [`restoreDefaultPartitions`](#class_internal_storage_1ace77d2372832c2f9ef39d382cc443259) | Restores the default partitioning scheme (1MB FAT32 for Certificates, 5MB FAT32 for OTA, 8MB user storage) to the internal storage drive erasing the existing partitions. | -| [`readPartitions`](#class_internal_storage_1a7191c21a719e9fe8132dc3cfaed3f0ec) | Reads the partitioning scheme from the MBR sector of the internal storage drive and returns a vector of structs of type [Partition](#struct_partition) that represents the partitioning scheme | +| [`readPartitions`](#class_internal_storage_1a3d3303d7eb80a5d9471c60cb2bffc3b3) | Reads the partitioning scheme from the MBR sector of the internal storage drive and returns a vector of structs of type [Partition](#struct_partition) that represents the partitioning scheme | ## Members @@ -489,6 +490,14 @@ Constructs an [InternalStorage](#class_internal_storage) object with the specifi * `fs` The desired file system (FS_FAT or FS_LITTLEFS).
+### `~InternalStorage` + +```cpp +~InternalStorage() +``` + +
+ ### `begin` ```cpp @@ -552,7 +561,7 @@ Formats the internal storage with the selected file system. true if successful, false if failed.
-### `getBlockDevice` +### `getBlockDevice` ```cpp BlockDeviceType * getBlockDevice() @@ -600,7 +609,7 @@ Restores the default partitioning scheme (1MB FAT32 for Certificates, 5MB FAT32 true if successful, false if failed.
-### `readPartitions` +### `readPartitions` ```cpp static std::vector< Partition > readPartitions() @@ -619,7 +628,7 @@ vector of structs of type [Partition](#struct_partition) --------------------------------|--------------------------------------------- | [`eraseMBRSector`](#class_partitioning_1a662f276b27785e76cdf9f89c5356e784) | Erases the first block (4096 bytes) of the BlockDevice to delete any already existing MBR partition table | | [`partitionDrive`](#class_partitioning_1a803b6e9a67304c6551d2a90ed5473985) | Partitions the BlockDevice according to the partitioning schemme given by the vector of [Partition](#struct_partition) structs | -| [`readPartitions`](#class_partitioning_1a44886fc5c7320a07cc42171ce9581fec) | Reads and unpacks the MBR partition information and returns a list of partitions it can find on the drive | +| [`readPartitions`](#class_partitioning_1affe78fdf2a8a5f8324668de3353b402d) | Reads and unpacks the MBR partition information and returns a list of partitions it can find on the drive | ## Members @@ -653,7 +662,7 @@ Partitions the BlockDevice according to the partitioning schemme given by the ve True upon success, False on failure
-### `readPartitions` +### `readPartitions` ```cpp static std::vector< Partition > readPartitions(BlockDeviceType * blockDevice) @@ -775,6 +784,7 @@ Class representing a File | [`changeMode`](#class_u_file_1a744ad88f2037e87e3f5375c7aec28f6d) | Closes the file, and opens it again with a new file mode. | | [`open`](#class_u_file_1aa52ff2913386374e6e83ba35f595d213) | Opens a file with the specified mode. | | [`open`](#class_u_file_1a0247abf7053b47463f73ca8cb1c7c23c) | Opens a file with the specified mode. | +| [`open`](#class_u_file_1a013a90e9e0a4b44a0fde722f1e9af6bc) | Opens a file that was already initialized with a path. | | [`close`](#class_u_file_1ab5731b8e40a87a44a7322bf151597c55) | Closes the file and releases any allocated resources. | | [`seek`](#class_u_file_1aa117a19e5efe6508e5e87ab65abbb560) | Seeks to a specific position in the file. | | [`read`](#class_u_file_1a8192f041831d58ba8186798676c5ad3a) | Reads data from the file into a buffer. | @@ -792,7 +802,7 @@ Class representing a File | [`moveTo`](#class_u_file_1ae676e42f3e5ad423da3386985fc8261f) | Moves the file to the specified destination path. | | [`moveTo`](#class_u_file_1a69f6a7cccce8cc40eb6698df15f38635) | Copies the file to the specified destination folder. | | [`getParentFolder`](#class_u_file_1a087b79b6d62a3ed122d1f8b0f25b0d24) | Returns a reference to the parent folder of the current folder. | -| [`getPath`](#class_u_file_1a41592023ea53cd1b46f383097a3db1f8) | Returns the path of the directory. | +| [`getPath`](#class_u_file_1a122edcf553a8929b703d70c6aa8a6e80) | Returns the path of the directory. | | [`getPathAsString`](#class_u_file_1a5adef9f3d538f92e51e52c4b1f3ada76) | Returns the path of the directory. | | [`available`](#class_u_file_1a82ad0fb6cffaf23aea794b508ec57bbb) | Returns the number of bytes available to read. | | [`read`](#class_u_file_1a62b544ebe9c3b144268016e6427917b5) | Returns one byte from the file. | @@ -879,6 +889,21 @@ Opens a file with the specified mode. True if the file was opened successfully, false otherwise.
+### `open` + +```cpp +bool open(FileMode mode) +``` + +Opens a file that was already initialized with a path. + +#### Parameters +* `mode` The file mode (READ, WRITE, or APPEND). The default is READ. + +#### Returns +True if the file was opened successfully, false otherwise. +
+ ### `close` ```cpp @@ -1121,7 +1146,7 @@ Returns a reference to the parent folder of the current folder. A directory object representing the current folder.
-### `getPath` +### `getPath` ```cpp const char * getPath() From aefc656cff4a044c1ac8fa9d0b2d8cc698bce21c Mon Sep 17 00:00:00 2001 From: Bogdan Ivanus Date: Mon, 4 Aug 2025 13:36:53 +0300 Subject: [PATCH 05/10] AE-593: Fixes bugs introduced with previous commits. --- src/InternalStorage.cpp | 1 + src/Partitioning.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/InternalStorage.cpp b/src/InternalStorage.cpp index 3edc15d..079bc04 100644 --- a/src/InternalStorage.cpp +++ b/src/InternalStorage.cpp @@ -95,6 +95,7 @@ Folder InternalStorage::getRootFolder(){ bool InternalStorage::format(FileSystems fs){ FileSystemType * tmpFileSystem = nullptr; + this -> begin(); this -> unmount(); this -> fileSystemType = fs; diff --git a/src/Partitioning.cpp b/src/Partitioning.cpp index 8db353a..de9af76 100644 --- a/src/Partitioning.cpp +++ b/src/Partitioning.cpp @@ -180,20 +180,20 @@ std::vector Partitioning::readPartitions(BlockDeviceType * blockDevic fatProbeFileSystem -> unmount(); partition.fileSystemType = FS_FAT; partitions.push_back(partition); - + delete mbrBlocKDevice; + delete fatProbeFileSystem; } else if (littleFsProbeFilesystem -> mount(mbrBlocKDevice) == 0){ Arduino_UnifiedStorage::debugPrint("[Partitioning][readPartitions][INFO] Partition " + String(partitionIndex) + " is formatted with LittleFS file system"); littleFsProbeFilesystem -> unmount(); partition.fileSystemType = FS_LITTLEFS; partitions.push_back(partition); + delete mbrBlocKDevice; + delete littleFsProbeFilesystem; } else { Arduino_UnifiedStorage::debugPrint("[Partitioning][readPartitions][INFO] Partition " + String(partitionIndex) + " is not formatted with a recognized file system"); } } - delete mbrBlocKDevice; - delete fatProbeFileSystem; - delete littleFsProbeFilesystem; } blockDevice->deinit(); delete[] buffer; From 03e96f36c623611fb4f34e5de3fea90fd8528334 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 6 Aug 2025 10:01:59 +0000 Subject: [PATCH 06/10] Bump actions/download-artifact from 4 to 5 Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 4 to 5. - [Release notes](https://github.com/actions/download-artifact/releases) - [Commits](https://github.com/actions/download-artifact/compare/v4...v5) --- updated-dependencies: - dependency-name: actions/download-artifact dependency-version: '5' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/sync-labels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index b975c8e..e5cdb8d 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -108,7 +108,7 @@ jobs: uses: actions/checkout@v4 - name: Download configuration files artifact - uses: actions/download-artifact@v4 + uses: actions/download-artifact@v5 with: name: ${{ env.CONFIGURATIONS_ARTIFACT }} path: ${{ env.CONFIGURATIONS_FOLDER }} From f855ed89e245de76f2fc5110a0eca7834817657b Mon Sep 17 00:00:00 2001 From: Bogdan Ivanus Date: Wed, 6 Aug 2025 17:12:13 +0300 Subject: [PATCH 07/10] AE-593: Small fixes for example sketches. --- .../AdvancedUSBInternalOperations.ino | 20 +++++------ .../BackupInternalPartitions.ino | 17 +++------ examples/Callbacks/Callbacks.ino | 16 ++++++++- .../InternalStoragePartitioning.ino | 2 +- examples/Logger/Logger.ino | 28 +++++---------- .../SimpleStorageWriteRead.ino | 36 +++++++++++-------- 6 files changed, 60 insertions(+), 59 deletions(-) diff --git a/examples/AdvancedUSBInternalOperations/AdvancedUSBInternalOperations.ino b/examples/AdvancedUSBInternalOperations/AdvancedUSBInternalOperations.ino index 11f73ea..d591f51 100644 --- a/examples/AdvancedUSBInternalOperations/AdvancedUSBInternalOperations.ino +++ b/examples/AdvancedUSBInternalOperations/AdvancedUSBInternalOperations.ino @@ -4,7 +4,7 @@ Demonstrates advanced usage of the "Arduino_UnifiedStorage" library with USB & internal storage, including file operations. Creates, copies, and moves files between storage types, and prints folder contents. - In the setup function, the code initializes serial communication, mounts both USB & internal storage and + In the setup function, the code initializes Serial communication, mounts both USB & internal storage and reformats the internal storage for a clean file system. Then, it creates a root directory in the internal storage and creates a subdirectory with a file inside it containing the string "Hello World!". @@ -28,7 +28,6 @@ USBStorage usbStorage; InternalStorage internalStorage; - // Helper function to prints the contents of a folder, including subdirectories (marked as "[D]") and files (marked as "[F]"). void printFolderContents(Folder dir, int indentation = 0) { std::vector directories = dir.getFolders(); @@ -54,18 +53,17 @@ void printFolderContents(Folder dir, int indentation = 0) { } } - - void setup() { - Serial.begin(115200); - while (!Serial); +#if !defined(ARDUINO_OPTA) + Serial.begin(115200); + while(!Serial); +#else + beginRS485(115200); +#endif // toggle this to enable debugging output Arduino_UnifiedStorage::debuggingModeEnabled = false; - usbStorage = USBStorage(); - internalStorage = InternalStorage(); - // Mount the USB storage if(usbStorage.begin()){ Serial.println("USB storage mounted."); @@ -109,8 +107,8 @@ void setup() { } // Print contents of the USB storage - //Serial.println("USB storage contents:"); - //printFolderContents(usbStorage.getRootFolder()); + Serial.println("USB storage contents:"); + printFolderContents(usbStorage.getRootFolder()); // Print contents of the internal storage Serial.println("Internal storage contents:"); diff --git a/examples/BackupInternalPartitions/BackupInternalPartitions.ino b/examples/BackupInternalPartitions/BackupInternalPartitions.ino index d181d76..aff6e03 100644 --- a/examples/BackupInternalPartitions/BackupInternalPartitions.ino +++ b/examples/BackupInternalPartitions/BackupInternalPartitions.ino @@ -4,7 +4,7 @@ This code demonstrates how the "Arduino_UnifiedStorage" can be used to access multiple partitions on the internal storage, and transfer information to a USB Mass storage device. - In the setup function, the code initializes serial communication, and registers a callback for the insertion of the USB Drive. + In the setup function, the code initializes Serial communication, and registers a callback for the insertion of the USB Drive. If the device is successfully mounted, a folder for this instance of a backup will be created on the USB Drive. @@ -38,7 +38,6 @@ volatile boolean connected = false; USBStorage thumbDrive; - void addSomeFakeFiles(Folder * folder){ Serial.println("Adding some fake files to: " + String(folder -> getPathAsString())); @@ -72,20 +71,19 @@ void move(Folder * source, Folder * dest){ } - - - void setup(){ randomSeed(analogRead(A0)); +#if !defined(ARDUINO_OPTA) Serial.begin(115200); while(!Serial); +#else + beginRS485(115200); +#endif // toggle this to enable debugging output Arduino_UnifiedStorage::debuggingModeEnabled = false; - thumbDrive = USBStorage(); - bool thumbMounted = thumbDrive.begin(FS_FAT); if(thumbMounted){ Serial.println("USB Thumb Drive has been mounted"); @@ -121,14 +119,9 @@ void setup(){ thumbDrive.unmount(); - Serial.println("DONE, you can restart the board now"); } - - } - void loop(){ - } diff --git a/examples/Callbacks/Callbacks.ino b/examples/Callbacks/Callbacks.ino index 5b215d5..fc8bc20 100644 --- a/examples/Callbacks/Callbacks.ino +++ b/examples/Callbacks/Callbacks.ino @@ -13,7 +13,6 @@ - You can also customize the LED indicators for different boards according to your hardware configuration. */ - #include "Arduino_UnifiedStorage.h" #if defined(ARDUINO_PORTENTA_H7_M7) @@ -27,17 +26,32 @@ USBStorage usbStorage = USBStorage(); void connectionCallback(){ +#if defined(ARDUINO_PORTENTA_H7_M7) + digitalWrite(CALLBACK_LED, LOW); +#elif defined(ARDUINO_PORTENTA_C33) + digitalWrite(CALLBACK_LED, LOW); +#elif defined(ARDUINO_OPTA) digitalWrite(CALLBACK_LED, HIGH); +#endif } void disconnectionCallback(){ +#if defined(ARDUINO_PORTENTA_H7_M7) + digitalWrite(CALLBACK_LED, HIGH); +#elif defined(ARDUINO_PORTENTA_C33) + digitalWrite(CALLBACK_LED, HIGH); +#elif defined(ARDUINO_OPTA) digitalWrite(CALLBACK_LED, LOW); +#endif } void setup(){ pinMode(CALLBACK_LED, OUTPUT); usbStorage.onConnect(connectionCallback); usbStorage.onDisconnect(disconnectionCallback); +#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_C33) + digitalWrite(CALLBACK_LED, HIGH); +#endif } void loop(){ diff --git a/examples/InternalStoragePartitioning/InternalStoragePartitioning.ino b/examples/InternalStoragePartitioning/InternalStoragePartitioning.ino index 69b2693..1764eba 100644 --- a/examples/InternalStoragePartitioning/InternalStoragePartitioning.ino +++ b/examples/InternalStoragePartitioning/InternalStoragePartitioning.ino @@ -23,7 +23,7 @@ INSTRUCTIONS: 1. Check compatibility with your board and make sure you have "POSIXStorage" and "Arduino_UnifiedStorage" installed - 2. Connect your board to the serial monitor + 2. Connect your board to the Serial monitor 3. Wait for the sketch to run 4. Modify the partitioning scheme according to your needs diff --git a/examples/Logger/Logger.ino b/examples/Logger/Logger.ino index fcfcaab..996c3bd 100644 --- a/examples/Logger/Logger.ino +++ b/examples/Logger/Logger.ino @@ -25,7 +25,6 @@ #include "Arduino_UnifiedStorage.h" #include - #if defined(ARDUINO_PORTENTA_H7_M7) #define USB_MOUNTED_LED LED_BLUE #elif defined(ARDUINO_PORTENTA_C33) @@ -53,12 +52,13 @@ bool backingUP = false; void connectionCallback(){ usbAvailable = true; usbStorage.removeOnConnectCallback(); + Serial.println("USB drive connected."); } void disconnectionCallback(){ usbAvailable = false; usbStorage.onConnect(connectionCallback); - + Serial.println("USB drive disconnected."); } // Function to run a given method periodically void runPeriodically(void (*method)(), unsigned long interval, unsigned long* variable) { @@ -89,7 +89,6 @@ void moveDataToQSPI() { } } - void performUpdate() { UFile logFile = internalStorage.getRootFolder().createFile("log.txt", FileMode::READ); UFile backupFile = backupFolder.createFile("backup_file.txt", FileMode::APPEND); // Create or open the backup file @@ -126,7 +125,6 @@ void performUpdate() { logFile.close(); lastUpdateFile.close(); - usbStorage.unmount(); // Unmount the USB storage digitalWrite(USB_MOUNTED_LED, HIGH); @@ -166,27 +164,22 @@ void backupToUSB() { } else { Arduino_UnifiedStorage::debugPrint("USB Mass storage is not available "); } - - } void setup() { randomSeed(analogRead(A0)); - #if !defined(ARDUINO_OPTA) - Serial.begin(115200); - while(!Serial); - #else - beginRS485(115200); - #endif +#if !defined(ARDUINO_OPTA) + Serial.begin(115200); + while(!Serial); +#else + beginRS485(115200); +#endif // toggle this to enable debugging output Arduino_UnifiedStorage::debuggingModeEnabled = false; - usbStorage = USBStorage(); - internalStorage = InternalStorage(); - usbStorage.onConnect(connectionCallback); usbStorage.onDisconnect(disconnectionCallback); @@ -195,20 +188,15 @@ void setup() { int formatted = internalStorage.format(FS_LITTLEFS); Arduino_UnifiedStorage::debugPrint("QSPI Format status: " + String(formatted)); - - if (!internalStorage.begin()) { Arduino_UnifiedStorage::debugPrint("Failed to initialize internal storage "); return; } else { Arduino_UnifiedStorage::debugPrint("Initialized storage "); } - } void loop() { - - runPeriodically(logDataToRAM, 100, &lastLog); runPeriodically(moveDataToQSPI, 1000, &lastMove); runPeriodically(backupToUSB, 10000, &lastBackup); diff --git a/examples/SimpleStorageWriteRead/SimpleStorageWriteRead.ino b/examples/SimpleStorageWriteRead/SimpleStorageWriteRead.ino index 51a4a65..b74c8d0 100644 --- a/examples/SimpleStorageWriteRead/SimpleStorageWriteRead.ino +++ b/examples/SimpleStorageWriteRead/SimpleStorageWriteRead.ino @@ -29,6 +29,20 @@ #include "Arduino_UnifiedStorage.h" +// Set one of the following to "true" and the rest to "false" in order to select one storage medium +#define USE_SD_STORAGE false +#define USE_USB_STORAGE false +#define USE_INTERNAL_STORAGE true + +#if defined(USE_SD_STORAGE) && (USE_SD_STORAGE == true) +SDStorage storage; // Create an instance for interacting with SD card storage +#elif defined(USE_USB_STORAGE) && (USE_USB_STORAGE == true) +USBStorage storage; // Create an instance for interacting with USB storage +#elif defined(USE_INTERNAL_STORAGE) && (USE_INTERNAL_STORAGE == true) +InternalStorage storage; +#else +#error "No valid storage option defined! Please define one of USE_SD_STORAGE, USE_USB_STORAGE, or USE_INTERNAL_STORAGE as true." +#endif void printFolderContents(Folder dir, int indentation = 0) { std::vector directories = dir.getFolders(); @@ -54,25 +68,19 @@ void printFolderContents(Folder dir, int indentation = 0) { } } - -// Uncomment one of the three lines below to select between SD card, USB or internal storage -//SDStorage storage; // Create an instance for interacting with SD card storage -//USBStorage storage; // Create an instance for interacting with USB storage -InternalStorage storage; - - void setup() { - Serial.begin(115200); - while (!Serial); + +// if we are on the Arduino Opta, and have decided to log on an USB drive connected to the USB-C connecter, we have to output the serial data through the RJ45 channel. +#if (defined(ARDUINO_OPTA)) && (defined(USE_USB_STORAGE) && (USE_USB_STORAGE == true)) + beginRS485(115200); +#else + Serial.begin(115200); + while (!Serial); +#endif // toggle this to enable debugging output Arduino_UnifiedStorage::debuggingModeEnabled = false; - - storage = InternalStorage(); - // storage = SDStorage(); // Uncomment this line to use SD card storage - // storage = USBStorage(); // Uncomment this line to use USB storage - if(!storage.begin()){ Serial.println("Error mounting storage device."); } From 55f408c97afff2ad58fa17a68244c44600087532 Mon Sep 17 00:00:00 2001 From: Bogdan Ivanus Date: Fri, 8 Aug 2025 13:44:09 +0300 Subject: [PATCH 08/10] AE-593: Replaced all "Serial.print()" with "Arduino_UnifiedStorage::debugPrint" to allow automatic remapping of the serial output channel on all boards, including the Opta, which uses the RJ45 to print log data. --- .../AdvancedUSBInternalOperations.ino | 38 +++++++++---------- .../BackupInternalPartitions.ino | 22 +++++------ examples/Logger/Logger.ino | 6 +-- .../SimpleStorageWriteRead.ino | 30 +++++++-------- 4 files changed, 48 insertions(+), 48 deletions(-) diff --git a/examples/AdvancedUSBInternalOperations/AdvancedUSBInternalOperations.ino b/examples/AdvancedUSBInternalOperations/AdvancedUSBInternalOperations.ino index d591f51..241c579 100644 --- a/examples/AdvancedUSBInternalOperations/AdvancedUSBInternalOperations.ino +++ b/examples/AdvancedUSBInternalOperations/AdvancedUSBInternalOperations.ino @@ -36,20 +36,20 @@ void printFolderContents(Folder dir, int indentation = 0) { // Print directories for (Folder subdir : directories) { for (int i = 0; i < indentation; i++) { - Serial.print(" "); + Arduino_UnifiedStorage::debugPrint(" "); } - Serial.print("[D] "); - Serial.println(subdir.getPath()); + Arduino_UnifiedStorage::debugPrint("[D] "); + Arduino_UnifiedStorage::debugPrint(subdir.getPath()); printFolderContents(subdir, indentation + 1); } // Print files for (UFile file : files) { for (int i = 0; i < indentation; i++) { - Serial.print(" "); + Arduino_UnifiedStorage::debugPrint(" "); } - Serial.print("[F] "); - Serial.println(file.getPath()); + Arduino_UnifiedStorage::debugPrint("[F] "); + Arduino_UnifiedStorage::debugPrint(file.getPath()); } } @@ -62,19 +62,19 @@ void setup() { #endif // toggle this to enable debugging output - Arduino_UnifiedStorage::debuggingModeEnabled = false; + Arduino_UnifiedStorage::debuggingModeEnabled = true; // Mount the USB storage if(usbStorage.begin()){ - Serial.println("USB storage mounted."); + Arduino_UnifiedStorage::debugPrint("USB storage mounted."); } else { - Serial.println(errno); + Arduino_UnifiedStorage::debugPrint(String(errno)); } if(internalStorage.begin()){ - Serial.println("Internal storage mounted."); + Arduino_UnifiedStorage::debugPrint("Internal storage mounted."); } else { - Serial.println(errno); + Arduino_UnifiedStorage::debugPrint(String(errno)); } // Create a root directory in the internal storage @@ -91,27 +91,27 @@ void setup() { // Copy the file from internal storage to USB storage bool success = file.copyTo(usbStorage.getRootFolder(), true); if (success) { - Serial.println("File copied successfully from internal storage to USB storage."); + Arduino_UnifiedStorage::debugPrint("File copied successfully from internal storage to USB storage."); } else { - Serial.println("Failed to copy file from internal storage to USB storage."); - Serial.println(getErrno()); + Arduino_UnifiedStorage::debugPrint("Failed to copy file from internal storage to USB storage."); + Arduino_UnifiedStorage::debugPrint(getErrno()); } // Move the subdirectory from internal storage to USB storage success = subdir.moveTo(usbStorage.getRootFolder(), true); if (success) { - Serial.println("Subdirectory moved successfully from internal storage to USB storage."); + Arduino_UnifiedStorage::debugPrint("Subdirectory moved successfully from internal storage to USB storage."); } else { - Serial.println("Failed to move subdirectory from internal storage to USB storage."); - Serial.println(getErrno()); + Arduino_UnifiedStorage::debugPrint("Failed to move subdirectory from internal storage to USB storage."); + Arduino_UnifiedStorage::debugPrint(getErrno()); } // Print contents of the USB storage - Serial.println("USB storage contents:"); + Arduino_UnifiedStorage::debugPrint("USB storage contents:"); printFolderContents(usbStorage.getRootFolder()); // Print contents of the internal storage - Serial.println("Internal storage contents:"); + Arduino_UnifiedStorage::debugPrint("Internal storage contents:"); printFolderContents(internalStorage.getRootFolder()); } diff --git a/examples/BackupInternalPartitions/BackupInternalPartitions.ino b/examples/BackupInternalPartitions/BackupInternalPartitions.ino index aff6e03..e7702b6 100644 --- a/examples/BackupInternalPartitions/BackupInternalPartitions.ino +++ b/examples/BackupInternalPartitions/BackupInternalPartitions.ino @@ -39,11 +39,11 @@ volatile boolean connected = false; USBStorage thumbDrive; void addSomeFakeFiles(Folder * folder){ - Serial.println("Adding some fake files to: " + String(folder -> getPathAsString())); + Arduino_UnifiedStorage::debugPrint("Adding some fake files to: " + String(folder -> getPathAsString())); for (int i = 0; i < random(0, 9); i++){ UFile thisFile = folder -> createFile("File_"+ String(random(999)), FileMode::WRITE); - Serial.println("\t * " + thisFile.getPathAsString()); + Arduino_UnifiedStorage::debugPrint("\t * " + thisFile.getPathAsString()); thisFile.write("writing stuff to the file"); thisFile.close(); } @@ -52,7 +52,7 @@ void addSomeFakeFiles(Folder * folder){ Folder subfolder = folder -> createSubfolder("ChildFolder_"+ String(random(999))); for (int i = 0; i < random(0, 9); i++){ UFile thisFile = subfolder.createFile("File_"+ String(random(999)), FileMode::WRITE); - Serial.println("\t * " + thisFile.getPathAsString()); + Arduino_UnifiedStorage::debugPrint("\t * " + thisFile.getPathAsString()); thisFile.write("writing stuff to the file"); thisFile.close(); } @@ -60,12 +60,12 @@ void addSomeFakeFiles(Folder * folder){ void move(Folder * source, Folder * dest){ for(Folder f: source -> getFolders()){ - Serial.println("Copying folder :" + String(f.getPathAsString())); + Arduino_UnifiedStorage::debugPrint("Copying folder :" + String(f.getPathAsString())); f.moveTo(*dest); } for(UFile f: source -> getFiles()){ - Serial.println("Copying file :" + String(f.getPathAsString())); + Arduino_UnifiedStorage::debugPrint("Copying file :" + String(f.getPathAsString())); f.moveTo(*dest); } } @@ -82,21 +82,21 @@ void setup(){ #endif // toggle this to enable debugging output - Arduino_UnifiedStorage::debuggingModeEnabled = false; + Arduino_UnifiedStorage::debuggingModeEnabled = true; bool thumbMounted = thumbDrive.begin(FS_FAT); if(thumbMounted){ - Serial.println("USB Thumb Drive has been mounted"); + Arduino_UnifiedStorage::debugPrint("USB Thumb Drive has been mounted"); Folder thumbRoot = thumbDrive.getRootFolder(); String folderName = "InternalBackup_" + String(millis()); - Serial.println(folderName); + Arduino_UnifiedStorage::debugPrint(folderName); Folder backupFolder = thumbRoot.createSubfolder(folderName); int partitionIndex = 0; std::vector partitions = InternalStorage::readPartitions(); - Serial.println("Found " + String(partitions.size()) + " partitions on internalStorage \n"); + Arduino_UnifiedStorage::debugPrint("Found " + String(partitions.size()) + " partitions on internalStorage \n"); for (auto part: partitions){ partitionIndex++; @@ -107,7 +107,7 @@ void setup(){ thisPartition.begin(); Folder partitionRootFolder = thisPartition.getRootFolder(); - Serial.println(partitionRootFolder.getPathAsString()); + Arduino_UnifiedStorage::debugPrint(partitionRootFolder.getPathAsString()); if(createFakeFiles){ addSomeFakeFiles(&partitionRootFolder); @@ -119,7 +119,7 @@ void setup(){ thumbDrive.unmount(); - Serial.println("DONE, you can restart the board now"); + Arduino_UnifiedStorage::debugPrint("DONE, you can restart the board now"); } } diff --git a/examples/Logger/Logger.ino b/examples/Logger/Logger.ino index 996c3bd..eea0aa6 100644 --- a/examples/Logger/Logger.ino +++ b/examples/Logger/Logger.ino @@ -52,13 +52,13 @@ bool backingUP = false; void connectionCallback(){ usbAvailable = true; usbStorage.removeOnConnectCallback(); - Serial.println("USB drive connected."); + Arduino_UnifiedStorage::debugPrint("USB drive connected."); } void disconnectionCallback(){ usbAvailable = false; usbStorage.onConnect(connectionCallback); - Serial.println("USB drive disconnected."); + Arduino_UnifiedStorage::debugPrint("USB drive disconnected."); } // Function to run a given method periodically void runPeriodically(void (*method)(), unsigned long interval, unsigned long* variable) { @@ -178,7 +178,7 @@ void setup() { #endif // toggle this to enable debugging output - Arduino_UnifiedStorage::debuggingModeEnabled = false; + Arduino_UnifiedStorage::debuggingModeEnabled = true; usbStorage.onConnect(connectionCallback); usbStorage.onDisconnect(disconnectionCallback); diff --git a/examples/SimpleStorageWriteRead/SimpleStorageWriteRead.ino b/examples/SimpleStorageWriteRead/SimpleStorageWriteRead.ino index b74c8d0..fe34794 100644 --- a/examples/SimpleStorageWriteRead/SimpleStorageWriteRead.ino +++ b/examples/SimpleStorageWriteRead/SimpleStorageWriteRead.ino @@ -51,20 +51,20 @@ void printFolderContents(Folder dir, int indentation = 0) { // Print directories for (Folder subdir : directories) { for (int i = 0; i < indentation; i++) { - Serial.print(" "); + Arduino_UnifiedStorage::debugPrint(" "); } - Serial.print("[D] "); - Serial.println(subdir.getPath()); + Arduino_UnifiedStorage::debugPrint("[D] "); + Arduino_UnifiedStorage::debugPrint(subdir.getPath()); printFolderContents(subdir, indentation + 1); } // Print files for (UFile file : files) { for (int i = 0; i < indentation; i++) { - Serial.print(" "); + Arduino_UnifiedStorage::debugPrint(" "); } - Serial.print("[F] "); - Serial.println(file.getPath()); + Arduino_UnifiedStorage::debugPrint("[F] "); + Arduino_UnifiedStorage::debugPrint(file.getPath()); } } @@ -79,10 +79,10 @@ void setup() { #endif // toggle this to enable debugging output - Arduino_UnifiedStorage::debuggingModeEnabled = false; + Arduino_UnifiedStorage::debuggingModeEnabled = true; if(!storage.begin()){ - Serial.println("Error mounting storage device."); + Arduino_UnifiedStorage::debugPrint("Error mounting storage device."); } // Create a root directory in storage device @@ -104,7 +104,7 @@ void setup() { file3.write("This is file 3."); // Read data from the files using seek and available - Serial.println("Reading data from files using seek and available:"); + Arduino_UnifiedStorage::debugPrint("Reading data from files using seek and available:"); // Close and open files in reading mode file1.changeMode(FileMode::READ); @@ -116,25 +116,25 @@ void setup() { file1.seek(0); // Move the file pointer to the beginning while (file1.available()) { char data = file1.read(); - Serial.write(data); + Arduino_UnifiedStorage::debugPrint(String(data)); } - Serial.println(); + Arduino_UnifiedStorage::debugPrint("\n"); // Read data from file2 file2.seek(0); // Move the file pointer to the beginning while (file2.available()) { char data = file2.read(); - Serial.print(data); + Arduino_UnifiedStorage::debugPrint(String(data)); } - Serial.println(); + Arduino_UnifiedStorage::debugPrint("\n"); // Read data from file3 file3.seek(0); // Move the file pointer to the beginning while (file3.available()) { char data = file3.read(); - Serial.print(data); + Arduino_UnifiedStorage::debugPrint(String(data)); } - Serial.println(); + Arduino_UnifiedStorage::debugPrint("\n"); printFolderContents(storage.getRootFolder()); } From bb947a7f423d3a2d52e1fc600630ca759ba6df85 Mon Sep 17 00:00:00 2001 From: Bogdan Ivanus Date: Tue, 12 Aug 2025 15:19:03 +0300 Subject: [PATCH 09/10] AE-593: Changed call to "Arduino_UnifiedStorage::debugPrint" into "Arduino_UnifiedStorage::testPrint" which allows correct print outputs on all boards (including the Opta) without the clutter of the extra debug information. --- .../BackupInternalPartitions.ino | 22 ++++----- examples/Logger/Logger.ino | 34 +++++++------- .../SimpleStorageWriteRead.ino | 46 +++++++++++-------- 3 files changed, 56 insertions(+), 46 deletions(-) diff --git a/examples/BackupInternalPartitions/BackupInternalPartitions.ino b/examples/BackupInternalPartitions/BackupInternalPartitions.ino index e7702b6..e3f132d 100644 --- a/examples/BackupInternalPartitions/BackupInternalPartitions.ino +++ b/examples/BackupInternalPartitions/BackupInternalPartitions.ino @@ -39,11 +39,11 @@ volatile boolean connected = false; USBStorage thumbDrive; void addSomeFakeFiles(Folder * folder){ - Arduino_UnifiedStorage::debugPrint("Adding some fake files to: " + String(folder -> getPathAsString())); + Arduino_UnifiedStorage::testPrint("Adding some fake files to: " + String(folder -> getPathAsString())); for (int i = 0; i < random(0, 9); i++){ UFile thisFile = folder -> createFile("File_"+ String(random(999)), FileMode::WRITE); - Arduino_UnifiedStorage::debugPrint("\t * " + thisFile.getPathAsString()); + Arduino_UnifiedStorage::testPrint("\t * " + thisFile.getPathAsString()); thisFile.write("writing stuff to the file"); thisFile.close(); } @@ -52,7 +52,7 @@ void addSomeFakeFiles(Folder * folder){ Folder subfolder = folder -> createSubfolder("ChildFolder_"+ String(random(999))); for (int i = 0; i < random(0, 9); i++){ UFile thisFile = subfolder.createFile("File_"+ String(random(999)), FileMode::WRITE); - Arduino_UnifiedStorage::debugPrint("\t * " + thisFile.getPathAsString()); + Arduino_UnifiedStorage::testPrint("\t * " + thisFile.getPathAsString()); thisFile.write("writing stuff to the file"); thisFile.close(); } @@ -60,12 +60,12 @@ void addSomeFakeFiles(Folder * folder){ void move(Folder * source, Folder * dest){ for(Folder f: source -> getFolders()){ - Arduino_UnifiedStorage::debugPrint("Copying folder :" + String(f.getPathAsString())); + Arduino_UnifiedStorage::testPrint("Copying folder :" + String(f.getPathAsString())); f.moveTo(*dest); } for(UFile f: source -> getFiles()){ - Arduino_UnifiedStorage::debugPrint("Copying file :" + String(f.getPathAsString())); + Arduino_UnifiedStorage::testPrint("Copying file :" + String(f.getPathAsString())); f.moveTo(*dest); } } @@ -82,21 +82,21 @@ void setup(){ #endif // toggle this to enable debugging output - Arduino_UnifiedStorage::debuggingModeEnabled = true; + Arduino_UnifiedStorage::debuggingModeEnabled = false; bool thumbMounted = thumbDrive.begin(FS_FAT); if(thumbMounted){ - Arduino_UnifiedStorage::debugPrint("USB Thumb Drive has been mounted"); + Arduino_UnifiedStorage::testPrint("USB Thumb Drive has been mounted"); Folder thumbRoot = thumbDrive.getRootFolder(); String folderName = "InternalBackup_" + String(millis()); - Arduino_UnifiedStorage::debugPrint(folderName); + Arduino_UnifiedStorage::testPrint(folderName); Folder backupFolder = thumbRoot.createSubfolder(folderName); int partitionIndex = 0; std::vector partitions = InternalStorage::readPartitions(); - Arduino_UnifiedStorage::debugPrint("Found " + String(partitions.size()) + " partitions on internalStorage \n"); + Arduino_UnifiedStorage::testPrint("Found " + String(partitions.size()) + " partitions on internalStorage \n"); for (auto part: partitions){ partitionIndex++; @@ -107,7 +107,7 @@ void setup(){ thisPartition.begin(); Folder partitionRootFolder = thisPartition.getRootFolder(); - Arduino_UnifiedStorage::debugPrint(partitionRootFolder.getPathAsString()); + Arduino_UnifiedStorage::testPrint(partitionRootFolder.getPathAsString()); if(createFakeFiles){ addSomeFakeFiles(&partitionRootFolder); @@ -119,7 +119,7 @@ void setup(){ thumbDrive.unmount(); - Arduino_UnifiedStorage::debugPrint("DONE, you can restart the board now"); + Arduino_UnifiedStorage::testPrint("DONE, you can restart the board now"); } } diff --git a/examples/Logger/Logger.ino b/examples/Logger/Logger.ino index eea0aa6..39d17fd 100644 --- a/examples/Logger/Logger.ino +++ b/examples/Logger/Logger.ino @@ -52,13 +52,13 @@ bool backingUP = false; void connectionCallback(){ usbAvailable = true; usbStorage.removeOnConnectCallback(); - Arduino_UnifiedStorage::debugPrint("USB drive connected."); + Arduino_UnifiedStorage::testPrint("USB drive connected."); } void disconnectionCallback(){ usbAvailable = false; usbStorage.onConnect(connectionCallback); - Arduino_UnifiedStorage::debugPrint("USB drive disconnected."); + Arduino_UnifiedStorage::testPrint("USB drive disconnected."); } // Function to run a given method periodically void runPeriodically(void (*method)(), unsigned long interval, unsigned long* variable) { @@ -97,10 +97,10 @@ void performUpdate() { backingUP = true; unsigned lastUpdateBytes = lastUpdateFile.readAsString().toInt(); // Read the last update size from the file - Arduino_UnifiedStorage::debugPrint("Last update bytes: " + String(lastUpdateBytes)); + Arduino_UnifiedStorage::testPrint("Last update bytes: " + String(lastUpdateBytes)); if (lastUpdateBytes >= bytesWritten) { - Arduino_UnifiedStorage::debugPrint("No new data to copy. "); + Arduino_UnifiedStorage::testPrint("No new data to copy. "); backupFile.close(); lastUpdateFile.close(); backingUP = false; @@ -109,14 +109,14 @@ void performUpdate() { logFile.seek(lastUpdateBytes); // Move the file pointer to the last update position unsigned long totalBytesToMove = bytesWritten - lastUpdateBytes; - Arduino_UnifiedStorage::debugPrint("New update bytes: " + String(totalBytesToMove)); + Arduino_UnifiedStorage::testPrint("New update bytes: " + String(totalBytesToMove)); uint8_t* buffer = new uint8_t[totalBytesToMove]; size_t bytesRead = logFile.read(buffer, totalBytesToMove); size_t bytesMoved = backupFile.write(buffer, bytesRead); // Only write the bytes that haven't been backed up yet - Arduino_UnifiedStorage::debugPrint("Successfully copied " + String(bytesMoved) + " new bytes. "); + Arduino_UnifiedStorage::testPrint("Successfully copied " + String(bytesMoved) + " new bytes. "); lastUpdateFile.changeMode(FileMode::WRITE); // Open the last update file in write mode lastUpdateFile.write(String(lastUpdateBytes + bytesMoved)); // Update the last update size @@ -137,32 +137,32 @@ void performUpdate() { void backupToUSB() { if(usbAvailable && !usbIntialized){ usbStorage.begin(); - Arduino_UnifiedStorage::debugPrint("First drive insertion, creating folders... "); + Arduino_UnifiedStorage::testPrint("First drive insertion, creating folders... "); Folder usbRoot = usbStorage.getRootFolder(); String folderName = "LoggerBackup" + String(random(9999)); backupFolder = usbRoot.createSubfolder(folderName); - Arduino_UnifiedStorage::debugPrint("Successfully created backup folder: " + backupFolder.getPathAsString()); + Arduino_UnifiedStorage::testPrint("Successfully created backup folder: " + backupFolder.getPathAsString()); usbStorage.unmount(); usbIntialized = true; } else if(usbAvailable && usbIntialized) { - Arduino_UnifiedStorage::debugPrint("USB Mass storage is available "); + Arduino_UnifiedStorage::testPrint("USB Mass storage is available "); delay(100); if (!usbStorage.isMounted()) { - Arduino_UnifiedStorage::debugPrint("Mounting USB Mass Storage "); + Arduino_UnifiedStorage::testPrint("Mounting USB Mass Storage "); digitalWrite(USB_MOUNTED_LED, LOW); if(usbStorage.begin()){ performUpdate(); } } else if (usbStorage.isMounted()) { - Arduino_UnifiedStorage::debugPrint("USB Mass storage is connected, performing update "); + Arduino_UnifiedStorage::testPrint("USB Mass storage is connected, performing update "); performUpdate(); } } else { - Arduino_UnifiedStorage::debugPrint("USB Mass storage is not available "); + Arduino_UnifiedStorage::testPrint("USB Mass storage is not available "); } } @@ -178,21 +178,21 @@ void setup() { #endif // toggle this to enable debugging output - Arduino_UnifiedStorage::debuggingModeEnabled = true; + Arduino_UnifiedStorage::debuggingModeEnabled = false; usbStorage.onConnect(connectionCallback); usbStorage.onDisconnect(disconnectionCallback); pinMode(USB_MOUNTED_LED, OUTPUT); - Arduino_UnifiedStorage::debugPrint("Formatting internal storage... "); + Arduino_UnifiedStorage::testPrint("Formatting internal storage... "); int formatted = internalStorage.format(FS_LITTLEFS); - Arduino_UnifiedStorage::debugPrint("QSPI Format status: " + String(formatted)); + Arduino_UnifiedStorage::testPrint("QSPI Format status: " + String(formatted)); if (!internalStorage.begin()) { - Arduino_UnifiedStorage::debugPrint("Failed to initialize internal storage "); + Arduino_UnifiedStorage::testPrint("Failed to initialize internal storage "); return; } else { - Arduino_UnifiedStorage::debugPrint("Initialized storage "); + Arduino_UnifiedStorage::testPrint("Initialized storage "); } } diff --git a/examples/SimpleStorageWriteRead/SimpleStorageWriteRead.ino b/examples/SimpleStorageWriteRead/SimpleStorageWriteRead.ino index fe34794..a885b8c 100644 --- a/examples/SimpleStorageWriteRead/SimpleStorageWriteRead.ino +++ b/examples/SimpleStorageWriteRead/SimpleStorageWriteRead.ino @@ -51,25 +51,28 @@ void printFolderContents(Folder dir, int indentation = 0) { // Print directories for (Folder subdir : directories) { for (int i = 0; i < indentation; i++) { - Arduino_UnifiedStorage::debugPrint(" "); + Arduino_UnifiedStorage::testPrint(" "); } - Arduino_UnifiedStorage::debugPrint("[D] "); - Arduino_UnifiedStorage::debugPrint(subdir.getPath()); + Arduino_UnifiedStorage::testPrint("[D] "); + Arduino_UnifiedStorage::testPrint(subdir.getPath()); printFolderContents(subdir, indentation + 1); } // Print files for (UFile file : files) { for (int i = 0; i < indentation; i++) { - Arduino_UnifiedStorage::debugPrint(" "); + Arduino_UnifiedStorage::testPrint(" "); } - Arduino_UnifiedStorage::debugPrint("[F] "); - Arduino_UnifiedStorage::debugPrint(file.getPath()); + Arduino_UnifiedStorage::testPrint("[F] "); + Arduino_UnifiedStorage::testPrint(file.getPath()); } } void setup() { + uint8_t index = 0u; + char data[20]; + // if we are on the Arduino Opta, and have decided to log on an USB drive connected to the USB-C connecter, we have to output the serial data through the RJ45 channel. #if (defined(ARDUINO_OPTA)) && (defined(USE_USB_STORAGE) && (USE_USB_STORAGE == true)) beginRS485(115200); @@ -79,10 +82,10 @@ void setup() { #endif // toggle this to enable debugging output - Arduino_UnifiedStorage::debuggingModeEnabled = true; + Arduino_UnifiedStorage::debuggingModeEnabled = false; if(!storage.begin()){ - Arduino_UnifiedStorage::debugPrint("Error mounting storage device."); + Arduino_UnifiedStorage::testPrint("Error mounting storage device."); } // Create a root directory in storage device @@ -104,7 +107,8 @@ void setup() { file3.write("This is file 3."); // Read data from the files using seek and available - Arduino_UnifiedStorage::debugPrint("Reading data from files using seek and available:"); + Arduino_UnifiedStorage::testPrint("Reading data from files using seek and available:"); + Arduino_UnifiedStorage::testPrint("\n\r"); // Close and open files in reading mode file1.changeMode(FileMode::READ); @@ -114,27 +118,33 @@ void setup() { // Read data from file1 file1.seek(0); // Move the file pointer to the beginning + //memset(data, 0u, sizeof(data)); + std::fill(std::begin(data), std::end(data), 0u); while (file1.available()) { - char data = file1.read(); - Arduino_UnifiedStorage::debugPrint(String(data)); + data[index++] = file1.read(); } - Arduino_UnifiedStorage::debugPrint("\n"); + Arduino_UnifiedStorage::testPrint(data); // Read data from file2 file2.seek(0); // Move the file pointer to the beginning + index = 0u; + //memset(data, 0u, sizeof(data)); + std::fill(std::begin(data), std::end(data), 0u); while (file2.available()) { - char data = file2.read(); - Arduino_UnifiedStorage::debugPrint(String(data)); + data[index++] = file2.read(); } - Arduino_UnifiedStorage::debugPrint("\n"); + Arduino_UnifiedStorage::testPrint(data); // Read data from file3 file3.seek(0); // Move the file pointer to the beginning + index = 0u; + //memset(data, 0u, sizeof(data)); + std::fill(std::begin(data), std::end(data), 0u); while (file3.available()) { - char data = file3.read(); - Arduino_UnifiedStorage::debugPrint(String(data)); + data[index++] = file3.read(); } - Arduino_UnifiedStorage::debugPrint("\n"); + Arduino_UnifiedStorage::testPrint(data); + Arduino_UnifiedStorage::testPrint("\n\r"); printFolderContents(storage.getRootFolder()); } From 0b87b292e273548aee1e2e056c7023b1c238cea9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Aug 2025 14:56:53 +0000 Subject: [PATCH 10/10] Bump actions/checkout from 4 to 5 Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 5. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v4...v5) --- updated-dependencies: - dependency-name: actions/checkout dependency-version: '5' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/check-arduino.yml | 2 +- .github/workflows/compile-examples-profiles.yml | 2 +- .github/workflows/spell-check.yml | 2 +- .github/workflows/sync-labels.yml | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/check-arduino.yml b/.github/workflows/check-arduino.yml index e818685..e13b990 100644 --- a/.github/workflows/check-arduino.yml +++ b/.github/workflows/check-arduino.yml @@ -16,7 +16,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Arduino Lint uses: arduino/arduino-lint-action@v2 diff --git a/.github/workflows/compile-examples-profiles.yml b/.github/workflows/compile-examples-profiles.yml index ab9bf31..1d63730 100644 --- a/.github/workflows/compile-examples-profiles.yml +++ b/.github/workflows/compile-examples-profiles.yml @@ -61,7 +61,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Compile examples uses: arduino/compile-sketches@v1 diff --git a/.github/workflows/spell-check.yml b/.github/workflows/spell-check.yml index 2c32c71..cfa5b14 100644 --- a/.github/workflows/spell-check.yml +++ b/.github/workflows/spell-check.yml @@ -19,7 +19,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Spell check uses: codespell-project/actions-codespell@v2 \ No newline at end of file diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index e5cdb8d..aac676e 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -27,7 +27,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Download JSON schema for labels configuration file id: download-schema @@ -105,7 +105,7 @@ jobs: echo "flag=--dry-run" >> $GITHUB_OUTPUT - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Download configuration files artifact uses: actions/download-artifact@v5