Skip to content

Commit 5017bea

Browse files
committed
Advanced.ino -> AdvancedUSBInternalOperations.ino
1 parent db1e57f commit 5017bea

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

examples/advanced/advanced.ino renamed to examples/AdvancedUSBInternalOperations/AdvancedUSBInternalOperations.ino

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,35 @@
11
/*
2-
This example demonstrates the usage of the "Arduino_UnifiedStorage" library with USB storage and internal storage.
3-
The code includes the necessary library and defines instances of the "USBStorage" and "InternalStorage" classes.
2+
AdvancedUSBInternalOperations
43
5-
In the setup function, the code initializes the serial communication and mounts the USB storage and internal storage.
6-
It also reformats the internal storage to ensure a clean file system.
7-
Then, it creates a root directory in the internal storage and creates a subdirectory and a file inside it
4+
Demonstrates advanced usage of the "Arduino_UnifiedStorage" library with USB & internal storage, including file operations.
5+
Creates, copies, and moves files between storage types, and prints folder contents.
86
9-
The code writes some data to the file and demonstrates file operations.
10-
It copies the file from internal storage to USB storage and moves the subdirectory from internal storage to USB storage.
7+
In the setup function, the code initializes serial communication, mounts both USB & internal storage and
8+
reformats the internal storage for a clean file system. Then, it creates a root directory in the internal storage
9+
and creates a subdirectory with a file inside it containing the string "Hello World!".
10+
11+
Then, it copies the file from internal storage to USB storage and moves the subdirectory from internal storage to USB storage.
12+
13+
After the file operations, the code prints the contents of both the USB storage and the internal storage.
14+
It recursively prints the directories (marked as "[D]") and files (marked as "[F]") using the "printFolderContents" function.
15+
16+
Created 28th July 2023
17+
By Cristian Dragomir
18+
19+
Modified 24th August 2023
20+
By Ali Jahangiri
21+
22+
https://github.com/arduino-libraries/Arduino_UnifiedStorage/blob/main/examples/SimpleStorageWriteRead/SimpleStorageWriteRead.ino
1123
12-
After the file operations, the code prints the contents of both the USB storage and the internal storage.
13-
It recursively prints the directories (marked as "[D]") and files (marked as "[F]") using the "printFolderContents" function.
1424
*/
1525

1626
#include "Arduino_UnifiedStorage.h"
1727

18-
28+
// Two instances are made for the USB and internal storage respectively
1929
USBStorage usbStorage = USBStorage();
2030
InternalStorage internalStorage = InternalStorage();
2131

22-
32+
// Helper function to prints the contents of a folder, including subdirectories (marked as "[D]") and files (marked as "[F]").
2333
void printFolderContents(Folder dir, int indentation = 0) {
2434
std::vector<Folder> directories = dir.getFolders();
2535
std::vector<UFile> files = dir.getFiles();
@@ -64,11 +74,11 @@ void setup() {
6474
// Create a root directory in the internal storage
6575
Folder root = internalStorage.getRootFolder();
6676

67-
// Create a subdirectory and a file inside the root directory
77+
// Create a subdirectory and a file (file.txt) inside the root directory
6878
Folder subdir = root.createSubfolder("subdir");
6979
UFile file = root.createFile("file.txt", FileMode::WRITE);
7080

71-
// Write some data to the file
81+
// Write "Hello World!" inside file.txt
7282
file.write("Hello, world!");
7383

7484
// Copy the file from internal storage to USB storage
@@ -89,11 +99,11 @@ void setup() {
8999
Serial.println(getErrno());
90100
}
91101

92-
// Print the content of the USB storage
102+
// Print contents of the USB storage
93103
Serial.println("USB storage contents:");
94104
printFolderContents(usbStorage.getRootFolder());
95105

96-
// Print the content of the internal storage
106+
// Print contents of the internal storage
97107
Serial.println("Internal storage contents:");
98108
printFolderContents(internalStorage.getRootFolder());
99109
}

0 commit comments

Comments
 (0)