Skip to content

Commit bb947a7

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

File tree

3 files changed

+56
-46
lines changed

3 files changed

+56
-46
lines changed

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-
Arduino_UnifiedStorage::debugPrint("Adding some fake files to: " + String(folder -> getPathAsString()));
42+
Arduino_UnifiedStorage::testPrint("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-
Arduino_UnifiedStorage::debugPrint("\t * " + thisFile.getPathAsString());
46+
Arduino_UnifiedStorage::testPrint("\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-
Arduino_UnifiedStorage::debugPrint("\t * " + thisFile.getPathAsString());
55+
Arduino_UnifiedStorage::testPrint("\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-
Arduino_UnifiedStorage::debugPrint("Copying folder :" + String(f.getPathAsString()));
63+
Arduino_UnifiedStorage::testPrint("Copying folder :" + String(f.getPathAsString()));
6464
f.moveTo(*dest);
6565
}
6666

6767
for(UFile f: source -> getFiles()){
68-
Arduino_UnifiedStorage::debugPrint("Copying file :" + String(f.getPathAsString()));
68+
Arduino_UnifiedStorage::testPrint("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 = true;
85+
Arduino_UnifiedStorage::debuggingModeEnabled = false;
8686

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

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

9696
int partitionIndex = 0;
9797

9898
std::vector<Partition> partitions = InternalStorage::readPartitions();
99-
Arduino_UnifiedStorage::debugPrint("Found " + String(partitions.size()) + " partitions on internalStorage \n");
99+
Arduino_UnifiedStorage::testPrint("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-
Arduino_UnifiedStorage::debugPrint(partitionRootFolder.getPathAsString());
110+
Arduino_UnifiedStorage::testPrint(partitionRootFolder.getPathAsString());
111111

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

120120
thumbDrive.unmount();
121121

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

examples/Logger/Logger.ino

Lines changed: 17 additions & 17 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-
Arduino_UnifiedStorage::debugPrint("USB drive connected.");
55+
Arduino_UnifiedStorage::testPrint("USB drive connected.");
5656
}
5757

5858
void disconnectionCallback(){
5959
usbAvailable = false;
6060
usbStorage.onConnect(connectionCallback);
61-
Arduino_UnifiedStorage::debugPrint("USB drive disconnected.");
61+
Arduino_UnifiedStorage::testPrint("USB drive disconnected.");
6262
}
6363
// Function to run a given method periodically
6464
void runPeriodically(void (*method)(), unsigned long interval, unsigned long* variable) {
@@ -97,10 +97,10 @@ void performUpdate() {
9797
backingUP = true;
9898
unsigned lastUpdateBytes = lastUpdateFile.readAsString().toInt(); // Read the last update size from the file
9999

100-
Arduino_UnifiedStorage::debugPrint("Last update bytes: " + String(lastUpdateBytes));
100+
Arduino_UnifiedStorage::testPrint("Last update bytes: " + String(lastUpdateBytes));
101101

102102
if (lastUpdateBytes >= bytesWritten) {
103-
Arduino_UnifiedStorage::debugPrint("No new data to copy. ");
103+
Arduino_UnifiedStorage::testPrint("No new data to copy. ");
104104
backupFile.close();
105105
lastUpdateFile.close();
106106
backingUP = false;
@@ -109,14 +109,14 @@ void performUpdate() {
109109

110110
logFile.seek(lastUpdateBytes); // Move the file pointer to the last update position
111111
unsigned long totalBytesToMove = bytesWritten - lastUpdateBytes;
112-
Arduino_UnifiedStorage::debugPrint("New update bytes: " + String(totalBytesToMove));
112+
Arduino_UnifiedStorage::testPrint("New update bytes: " + String(totalBytesToMove));
113113

114114
uint8_t* buffer = new uint8_t[totalBytesToMove];
115115

116116
size_t bytesRead = logFile.read(buffer, totalBytesToMove);
117117
size_t bytesMoved = backupFile.write(buffer, bytesRead); // Only write the bytes that haven't been backed up yet
118118

119-
Arduino_UnifiedStorage::debugPrint("Successfully copied " + String(bytesMoved) + " new bytes. ");
119+
Arduino_UnifiedStorage::testPrint("Successfully copied " + String(bytesMoved) + " new bytes. ");
120120

121121
lastUpdateFile.changeMode(FileMode::WRITE); // Open the last update file in write mode
122122
lastUpdateFile.write(String(lastUpdateBytes + bytesMoved)); // Update the last update size
@@ -137,32 +137,32 @@ void performUpdate() {
137137
void backupToUSB() {
138138
if(usbAvailable && !usbIntialized){
139139
usbStorage.begin();
140-
Arduino_UnifiedStorage::debugPrint("First drive insertion, creating folders... ");
140+
Arduino_UnifiedStorage::testPrint("First drive insertion, creating folders... ");
141141
Folder usbRoot = usbStorage.getRootFolder();
142142
String folderName = "LoggerBackup" + String(random(9999));
143143
backupFolder = usbRoot.createSubfolder(folderName);
144-
Arduino_UnifiedStorage::debugPrint("Successfully created backup folder: " + backupFolder.getPathAsString());
144+
Arduino_UnifiedStorage::testPrint("Successfully created backup folder: " + backupFolder.getPathAsString());
145145
usbStorage.unmount();
146146
usbIntialized = true;
147147
}
148148
else if(usbAvailable && usbIntialized) {
149-
Arduino_UnifiedStorage::debugPrint("USB Mass storage is available ");
149+
Arduino_UnifiedStorage::testPrint("USB Mass storage is available ");
150150
delay(100);
151151
if (!usbStorage.isMounted()) {
152152

153-
Arduino_UnifiedStorage::debugPrint("Mounting USB Mass Storage ");
153+
Arduino_UnifiedStorage::testPrint("Mounting USB Mass Storage ");
154154
digitalWrite(USB_MOUNTED_LED, LOW);
155155
if(usbStorage.begin()){
156156
performUpdate();
157157
}
158158

159159
} else if (usbStorage.isMounted()) {
160-
Arduino_UnifiedStorage::debugPrint("USB Mass storage is connected, performing update ");
160+
Arduino_UnifiedStorage::testPrint("USB Mass storage is connected, performing update ");
161161
performUpdate();
162162

163163
}
164164
} else {
165-
Arduino_UnifiedStorage::debugPrint("USB Mass storage is not available ");
165+
Arduino_UnifiedStorage::testPrint("USB Mass storage is not available ");
166166
}
167167
}
168168

@@ -178,21 +178,21 @@ void setup() {
178178
#endif
179179

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

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

186186
pinMode(USB_MOUNTED_LED, OUTPUT);
187-
Arduino_UnifiedStorage::debugPrint("Formatting internal storage... ");
187+
Arduino_UnifiedStorage::testPrint("Formatting internal storage... ");
188188
int formatted = internalStorage.format(FS_LITTLEFS);
189-
Arduino_UnifiedStorage::debugPrint("QSPI Format status: " + String(formatted));
189+
Arduino_UnifiedStorage::testPrint("QSPI Format status: " + String(formatted));
190190

191191
if (!internalStorage.begin()) {
192-
Arduino_UnifiedStorage::debugPrint("Failed to initialize internal storage ");
192+
Arduino_UnifiedStorage::testPrint("Failed to initialize internal storage ");
193193
return;
194194
} else {
195-
Arduino_UnifiedStorage::debugPrint("Initialized storage ");
195+
Arduino_UnifiedStorage::testPrint("Initialized storage ");
196196
}
197197
}
198198

examples/SimpleStorageWriteRead/SimpleStorageWriteRead.ino

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,28 @@ void printFolderContents(Folder dir, int indentation = 0) {
5151
// Print directories
5252
for (Folder subdir : directories) {
5353
for (int i = 0; i < indentation; i++) {
54-
Arduino_UnifiedStorage::debugPrint(" ");
54+
Arduino_UnifiedStorage::testPrint(" ");
5555
}
56-
Arduino_UnifiedStorage::debugPrint("[D] ");
57-
Arduino_UnifiedStorage::debugPrint(subdir.getPath());
56+
Arduino_UnifiedStorage::testPrint("[D] ");
57+
Arduino_UnifiedStorage::testPrint(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-
Arduino_UnifiedStorage::debugPrint(" ");
64+
Arduino_UnifiedStorage::testPrint(" ");
6565
}
66-
Arduino_UnifiedStorage::debugPrint("[F] ");
67-
Arduino_UnifiedStorage::debugPrint(file.getPath());
66+
Arduino_UnifiedStorage::testPrint("[F] ");
67+
Arduino_UnifiedStorage::testPrint(file.getPath());
6868
}
6969
}
7070

7171
void setup() {
7272

73+
uint8_t index = 0u;
74+
char data[20];
75+
7376
// 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.
7477
#if (defined(ARDUINO_OPTA)) && (defined(USE_USB_STORAGE) && (USE_USB_STORAGE == true))
7578
beginRS485(115200);
@@ -79,10 +82,10 @@ void setup() {
7982
#endif
8083

8184
// toggle this to enable debugging output
82-
Arduino_UnifiedStorage::debuggingModeEnabled = true;
85+
Arduino_UnifiedStorage::debuggingModeEnabled = false;
8386

8487
if(!storage.begin()){
85-
Arduino_UnifiedStorage::debugPrint("Error mounting storage device.");
88+
Arduino_UnifiedStorage::testPrint("Error mounting storage device.");
8689
}
8790

8891
// Create a root directory in storage device
@@ -104,7 +107,8 @@ void setup() {
104107
file3.write("This is file 3.");
105108

106109
// Read data from the files using seek and available
107-
Arduino_UnifiedStorage::debugPrint("Reading data from files using seek and available:");
110+
Arduino_UnifiedStorage::testPrint("Reading data from files using seek and available:");
111+
Arduino_UnifiedStorage::testPrint("\n\r");
108112

109113
// Close and open files in reading mode
110114
file1.changeMode(FileMode::READ);
@@ -114,27 +118,33 @@ void setup() {
114118

115119
// Read data from file1
116120
file1.seek(0); // Move the file pointer to the beginning
121+
//memset(data, 0u, sizeof(data));
122+
std::fill(std::begin(data), std::end(data), 0u);
117123
while (file1.available()) {
118-
char data = file1.read();
119-
Arduino_UnifiedStorage::debugPrint(String(data));
124+
data[index++] = file1.read();
120125
}
121-
Arduino_UnifiedStorage::debugPrint("\n");
126+
Arduino_UnifiedStorage::testPrint(data);
122127

123128
// Read data from file2
124129
file2.seek(0); // Move the file pointer to the beginning
130+
index = 0u;
131+
//memset(data, 0u, sizeof(data));
132+
std::fill(std::begin(data), std::end(data), 0u);
125133
while (file2.available()) {
126-
char data = file2.read();
127-
Arduino_UnifiedStorage::debugPrint(String(data));
134+
data[index++] = file2.read();
128135
}
129-
Arduino_UnifiedStorage::debugPrint("\n");
136+
Arduino_UnifiedStorage::testPrint(data);
130137

131138
// Read data from file3
132139
file3.seek(0); // Move the file pointer to the beginning
140+
index = 0u;
141+
//memset(data, 0u, sizeof(data));
142+
std::fill(std::begin(data), std::end(data), 0u);
133143
while (file3.available()) {
134-
char data = file3.read();
135-
Arduino_UnifiedStorage::debugPrint(String(data));
144+
data[index++] = file3.read();
136145
}
137-
Arduino_UnifiedStorage::debugPrint("\n");
146+
Arduino_UnifiedStorage::testPrint(data);
147+
Arduino_UnifiedStorage::testPrint("\n\r");
138148

139149
printFolderContents(storage.getRootFolder());
140150
}

0 commit comments

Comments
 (0)