Skip to content

Commit 55f408c

Browse files
committed
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.
1 parent f855ed8 commit 55f408c

File tree

4 files changed

+48
-48
lines changed

4 files changed

+48
-48
lines changed

examples/AdvancedUSBInternalOperations/AdvancedUSBInternalOperations.ino

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@ void printFolderContents(Folder dir, int indentation = 0) {
3636
// Print directories
3737
for (Folder subdir : directories) {
3838
for (int i = 0; i < indentation; i++) {
39-
Serial.print(" ");
39+
Arduino_UnifiedStorage::debugPrint(" ");
4040
}
41-
Serial.print("[D] ");
42-
Serial.println(subdir.getPath());
41+
Arduino_UnifiedStorage::debugPrint("[D] ");
42+
Arduino_UnifiedStorage::debugPrint(subdir.getPath());
4343
printFolderContents(subdir, indentation + 1);
4444
}
4545

4646
// Print files
4747
for (UFile file : files) {
4848
for (int i = 0; i < indentation; i++) {
49-
Serial.print(" ");
49+
Arduino_UnifiedStorage::debugPrint(" ");
5050
}
51-
Serial.print("[F] ");
52-
Serial.println(file.getPath());
51+
Arduino_UnifiedStorage::debugPrint("[F] ");
52+
Arduino_UnifiedStorage::debugPrint(file.getPath());
5353
}
5454
}
5555

@@ -62,19 +62,19 @@ void setup() {
6262
#endif
6363

6464
// toggle this to enable debugging output
65-
Arduino_UnifiedStorage::debuggingModeEnabled = false;
65+
Arduino_UnifiedStorage::debuggingModeEnabled = true;
6666

6767
// Mount the USB storage
6868
if(usbStorage.begin()){
69-
Serial.println("USB storage mounted.");
69+
Arduino_UnifiedStorage::debugPrint("USB storage mounted.");
7070
} else {
71-
Serial.println(errno);
71+
Arduino_UnifiedStorage::debugPrint(String(errno));
7272
}
7373

7474
if(internalStorage.begin()){
75-
Serial.println("Internal storage mounted.");
75+
Arduino_UnifiedStorage::debugPrint("Internal storage mounted.");
7676
} else {
77-
Serial.println(errno);
77+
Arduino_UnifiedStorage::debugPrint(String(errno));
7878
}
7979

8080
// Create a root directory in the internal storage
@@ -91,27 +91,27 @@ void setup() {
9191
// Copy the file from internal storage to USB storage
9292
bool success = file.copyTo(usbStorage.getRootFolder(), true);
9393
if (success) {
94-
Serial.println("File copied successfully from internal storage to USB storage.");
94+
Arduino_UnifiedStorage::debugPrint("File copied successfully from internal storage to USB storage.");
9595
} else {
96-
Serial.println("Failed to copy file from internal storage to USB storage.");
97-
Serial.println(getErrno());
96+
Arduino_UnifiedStorage::debugPrint("Failed to copy file from internal storage to USB storage.");
97+
Arduino_UnifiedStorage::debugPrint(getErrno());
9898
}
9999

100100
// Move the subdirectory from internal storage to USB storage
101101
success = subdir.moveTo(usbStorage.getRootFolder(), true);
102102
if (success) {
103-
Serial.println("Subdirectory moved successfully from internal storage to USB storage.");
103+
Arduino_UnifiedStorage::debugPrint("Subdirectory moved successfully from internal storage to USB storage.");
104104
} else {
105-
Serial.println("Failed to move subdirectory from internal storage to USB storage.");
106-
Serial.println(getErrno());
105+
Arduino_UnifiedStorage::debugPrint("Failed to move subdirectory from internal storage to USB storage.");
106+
Arduino_UnifiedStorage::debugPrint(getErrno());
107107
}
108108

109109
// Print contents of the USB storage
110-
Serial.println("USB storage contents:");
110+
Arduino_UnifiedStorage::debugPrint("USB storage contents:");
111111
printFolderContents(usbStorage.getRootFolder());
112112

113113
// Print contents of the internal storage
114-
Serial.println("Internal storage contents:");
114+
Arduino_UnifiedStorage::debugPrint("Internal storage contents:");
115115
printFolderContents(internalStorage.getRootFolder());
116116
}
117117

examples/BackupInternalPartitions/BackupInternalPartitions.ino

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ volatile boolean connected = false;
3939
USBStorage thumbDrive;
4040

4141
void addSomeFakeFiles(Folder * folder){
42-
Serial.println("Adding some fake files to: " + String(folder -> getPathAsString()));
42+
Arduino_UnifiedStorage::debugPrint("Adding some fake files to: " + String(folder -> getPathAsString()));
4343

4444
for (int i = 0; i < random(0, 9); i++){
4545
UFile thisFile = folder -> createFile("File_"+ String(random(999)), FileMode::WRITE);
46-
Serial.println("\t * " + thisFile.getPathAsString());
46+
Arduino_UnifiedStorage::debugPrint("\t * " + thisFile.getPathAsString());
4747
thisFile.write("writing stuff to the file");
4848
thisFile.close();
4949
}
@@ -52,20 +52,20 @@ void addSomeFakeFiles(Folder * folder){
5252
Folder subfolder = folder -> createSubfolder("ChildFolder_"+ String(random(999)));
5353
for (int i = 0; i < random(0, 9); i++){
5454
UFile thisFile = subfolder.createFile("File_"+ String(random(999)), FileMode::WRITE);
55-
Serial.println("\t * " + thisFile.getPathAsString());
55+
Arduino_UnifiedStorage::debugPrint("\t * " + thisFile.getPathAsString());
5656
thisFile.write("writing stuff to the file");
5757
thisFile.close();
5858
}
5959
}
6060

6161
void move(Folder * source, Folder * dest){
6262
for(Folder f: source -> getFolders()){
63-
Serial.println("Copying folder :" + String(f.getPathAsString()));
63+
Arduino_UnifiedStorage::debugPrint("Copying folder :" + String(f.getPathAsString()));
6464
f.moveTo(*dest);
6565
}
6666

6767
for(UFile f: source -> getFiles()){
68-
Serial.println("Copying file :" + String(f.getPathAsString()));
68+
Arduino_UnifiedStorage::debugPrint("Copying file :" + String(f.getPathAsString()));
6969
f.moveTo(*dest);
7070
}
7171
}
@@ -82,21 +82,21 @@ void setup(){
8282
#endif
8383

8484
// toggle this to enable debugging output
85-
Arduino_UnifiedStorage::debuggingModeEnabled = false;
85+
Arduino_UnifiedStorage::debuggingModeEnabled = true;
8686

8787
bool thumbMounted = thumbDrive.begin(FS_FAT);
8888
if(thumbMounted){
89-
Serial.println("USB Thumb Drive has been mounted");
89+
Arduino_UnifiedStorage::debugPrint("USB Thumb Drive has been mounted");
9090

9191
Folder thumbRoot = thumbDrive.getRootFolder();
9292
String folderName = "InternalBackup_" + String(millis());
93-
Serial.println(folderName);
93+
Arduino_UnifiedStorage::debugPrint(folderName);
9494
Folder backupFolder = thumbRoot.createSubfolder(folderName);
9595

9696
int partitionIndex = 0;
9797

9898
std::vector<Partition> partitions = InternalStorage::readPartitions();
99-
Serial.println("Found " + String(partitions.size()) + " partitions on internalStorage \n");
99+
Arduino_UnifiedStorage::debugPrint("Found " + String(partitions.size()) + " partitions on internalStorage \n");
100100

101101
for (auto part: partitions){
102102
partitionIndex++;
@@ -107,7 +107,7 @@ void setup(){
107107
thisPartition.begin();
108108

109109
Folder partitionRootFolder = thisPartition.getRootFolder();
110-
Serial.println(partitionRootFolder.getPathAsString());
110+
Arduino_UnifiedStorage::debugPrint(partitionRootFolder.getPathAsString());
111111

112112
if(createFakeFiles){
113113
addSomeFakeFiles(&partitionRootFolder);
@@ -119,7 +119,7 @@ void setup(){
119119

120120
thumbDrive.unmount();
121121

122-
Serial.println("DONE, you can restart the board now");
122+
Arduino_UnifiedStorage::debugPrint("DONE, you can restart the board now");
123123
}
124124
}
125125

examples/Logger/Logger.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ bool backingUP = false;
5252
void connectionCallback(){
5353
usbAvailable = true;
5454
usbStorage.removeOnConnectCallback();
55-
Serial.println("USB drive connected.");
55+
Arduino_UnifiedStorage::debugPrint("USB drive connected.");
5656
}
5757

5858
void disconnectionCallback(){
5959
usbAvailable = false;
6060
usbStorage.onConnect(connectionCallback);
61-
Serial.println("USB drive disconnected.");
61+
Arduino_UnifiedStorage::debugPrint("USB drive disconnected.");
6262
}
6363
// Function to run a given method periodically
6464
void runPeriodically(void (*method)(), unsigned long interval, unsigned long* variable) {
@@ -178,7 +178,7 @@ void setup() {
178178
#endif
179179

180180
// toggle this to enable debugging output
181-
Arduino_UnifiedStorage::debuggingModeEnabled = false;
181+
Arduino_UnifiedStorage::debuggingModeEnabled = true;
182182

183183
usbStorage.onConnect(connectionCallback);
184184
usbStorage.onDisconnect(disconnectionCallback);

examples/SimpleStorageWriteRead/SimpleStorageWriteRead.ino

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,20 @@ void printFolderContents(Folder dir, int indentation = 0) {
5151
// Print directories
5252
for (Folder subdir : directories) {
5353
for (int i = 0; i < indentation; i++) {
54-
Serial.print(" ");
54+
Arduino_UnifiedStorage::debugPrint(" ");
5555
}
56-
Serial.print("[D] ");
57-
Serial.println(subdir.getPath());
56+
Arduino_UnifiedStorage::debugPrint("[D] ");
57+
Arduino_UnifiedStorage::debugPrint(subdir.getPath());
5858
printFolderContents(subdir, indentation + 1);
5959
}
6060

6161
// Print files
6262
for (UFile file : files) {
6363
for (int i = 0; i < indentation; i++) {
64-
Serial.print(" ");
64+
Arduino_UnifiedStorage::debugPrint(" ");
6565
}
66-
Serial.print("[F] ");
67-
Serial.println(file.getPath());
66+
Arduino_UnifiedStorage::debugPrint("[F] ");
67+
Arduino_UnifiedStorage::debugPrint(file.getPath());
6868
}
6969
}
7070

@@ -79,10 +79,10 @@ void setup() {
7979
#endif
8080

8181
// toggle this to enable debugging output
82-
Arduino_UnifiedStorage::debuggingModeEnabled = false;
82+
Arduino_UnifiedStorage::debuggingModeEnabled = true;
8383

8484
if(!storage.begin()){
85-
Serial.println("Error mounting storage device.");
85+
Arduino_UnifiedStorage::debugPrint("Error mounting storage device.");
8686
}
8787

8888
// Create a root directory in storage device
@@ -104,7 +104,7 @@ void setup() {
104104
file3.write("This is file 3.");
105105

106106
// Read data from the files using seek and available
107-
Serial.println("Reading data from files using seek and available:");
107+
Arduino_UnifiedStorage::debugPrint("Reading data from files using seek and available:");
108108

109109
// Close and open files in reading mode
110110
file1.changeMode(FileMode::READ);
@@ -116,25 +116,25 @@ void setup() {
116116
file1.seek(0); // Move the file pointer to the beginning
117117
while (file1.available()) {
118118
char data = file1.read();
119-
Serial.write(data);
119+
Arduino_UnifiedStorage::debugPrint(String(data));
120120
}
121-
Serial.println();
121+
Arduino_UnifiedStorage::debugPrint("\n");
122122

123123
// Read data from file2
124124
file2.seek(0); // Move the file pointer to the beginning
125125
while (file2.available()) {
126126
char data = file2.read();
127-
Serial.print(data);
127+
Arduino_UnifiedStorage::debugPrint(String(data));
128128
}
129-
Serial.println();
129+
Arduino_UnifiedStorage::debugPrint("\n");
130130

131131
// Read data from file3
132132
file3.seek(0); // Move the file pointer to the beginning
133133
while (file3.available()) {
134134
char data = file3.read();
135-
Serial.print(data);
135+
Arduino_UnifiedStorage::debugPrint(String(data));
136136
}
137-
Serial.println();
137+
Arduino_UnifiedStorage::debugPrint("\n");
138138

139139
printFolderContents(storage.getRootFolder());
140140
}

0 commit comments

Comments
 (0)