@@ -29,7 +29,7 @@ void test(String opperation, Arduino_UnifiedStorage* sourceStorage, Arduino_Unif
29
29
30
30
if (mountSource && mountDest){
31
31
32
- String fileName = " / test_" + String (millis ()) + " .txt" ;
32
+ String fileName = " test_" + String (millis ()) + " .txt" ;
33
33
// Create a file in the source storage
34
34
UFile fileToMove = sourceStorage->getRootFolder ().createFile (fileName, FileMode::WRITE);
35
35
fileToMove.write (reinterpret_cast <const uint8_t *>(" Test data" ), 9 );
@@ -38,109 +38,114 @@ void test(String opperation, Arduino_UnifiedStorage* sourceStorage, Arduino_Unif
38
38
int opperationResult = -1 ;
39
39
if (opperation == " move" ) {
40
40
opperationResult = fileToMove.moveTo (destinationStorage->getRootFolder (), true );
41
+ fileToMove.close ();
42
+ fileToMove.remove ();
41
43
} else if (opperation == " copy" ){
42
44
opperationResult = fileToMove.copyTo (destinationStorage->getRootFolder (), true );
45
+ fileToMove.close ();
46
+ fileToMove.remove ();
43
47
}
44
48
45
49
if (opperationResult) {
46
50
Serial.println (opperation + " from " + String (storageTypeA) + " to " + String (storageTypeB) + " successful" );
47
-
48
- // Delete the moved file from the destination storage
49
- UFile movedFile;
50
- movedFile.open (destinationStorage->getRootFolder ().getPathString () + fileName, FileMode::READ);
51
- if (movedFile.remove ()) {
52
- Serial.println (" File deletion from " + String (storageTypeB) + " successful" );
53
- } else {
54
- Serial.println (" File deletion from " + String (storageTypeB) + " failed" );
55
- Serial.println (getErrno ());
56
- }
57
- } else {
58
- Serial.println (opperation + " from " + String (storageTypeA) + " to " + String (storageTypeB) + " failed" );
59
- Serial.println (getErrno ());
60
51
}
61
52
53
+
62
54
Serial.println ();
63
55
int unmountSource = sourceStorage->unmount ();
64
- Serial.println (" Unmount " + String (storageTypeA) + " : " + unmountSource);
65
-
66
56
int unmountDest = destinationStorage->unmount ();
67
- Serial.println (" Unmount " + String (storageTypeB) + " : " + unmountDest);
68
57
69
58
delay (1000 );
59
+
70
60
} else {
71
61
Serial.println (" cannot execute test, fs not mounted" );
72
62
}
73
63
}
74
64
75
65
66
+
76
67
void sd_and_usb (){
77
- Serial.println (" Formatting both USB and SD to FAT" );
78
- usb->formatFAT ();
79
- sd->formatFAT ();
68
+ Serial.println (" TESTING SD AND USB \n\n\n\n " );
69
+
70
+ Serial.println (" -----------------------------" );
71
+ Serial.println (" Formatting USB to FAT: " + String (usb->formatFAT ()));
72
+ Serial.println (" Formatting SD to FAT: " + String (sd->formatFAT ()));
73
+ Serial.println (" -----------------------------" );
74
+
80
75
81
76
test (" move" , usb, sd, " USB FAT" , " SD FAT" );
82
77
test (" copy" , usb, sd, " USB FAT" , " SD FAT" );
83
78
84
79
test (" move" , sd, usb, " SD FAT" , " USB FAT" );
85
80
test (" copy" , sd, usb, " SD FAT" , " USB FAT" );
86
81
87
- Serial.println (" Formatting USB to LittleFS" );
88
- usb->formatLittleFS ();
82
+ Serial.println (" -----------------------------" );
83
+ Serial.println (" Formatting USB to LittleFS:" + String (usb->formatLittleFS ()));
84
+ Serial.println (" -----------------------------" );
85
+
89
86
test (" move" , usb, sd, " USB LittleFS" , " SD FAT " );
90
87
test (" copy" , usb, sd, " USB LittleFS" , " SD FAT " );
91
88
92
89
test (" move" , sd, usb, " SD FAT" , " USB LittleFS" );
93
90
test (" copy" , sd, usb, " SD FAT" , " USB LittleFS" );
94
91
95
- Serial.println (" Formatting SD to LittleFS" );
96
- sd->formatLittleFS ();
92
+ Serial.println (" -----------------------------" );
93
+ Serial.println (" Formatting SD to LittleFS: " + String (sd->formatLittleFS ()));
94
+ Serial.println (" -----------------------------" );
95
+
97
96
test (" move" , sd, usb, " SD LittleFS" , " USB LittleFS" );
98
97
test (" copy" , sd, usb, " SD LittleFS" , " USB LittleFS" );
99
98
100
99
test (" move" , usb, sd, " USB LittleFS" , " SD LittleFS" );
101
100
test (" copy" , usb, sd, " USB LittleFS" , " SD LittleFS" );
102
101
103
- Serial.println (" Formatting USB to FAT" );
104
- usb->formatFAT ();
102
+ Serial.println (" -----------------------------" );
103
+ Serial.println (" Formatting USB to FAT: " + String (usb->formatFAT ()));
104
+ Serial.println (" -----------------------------" );
105
+
105
106
test (" move" , usb, sd, " USB FAT" , " SD LittleFS" );
106
107
test (" copy" , usb, sd, " USB FAT" , " SD LittleFS" );
107
108
108
109
test (" move" , sd, usb, " SD LittleFS" , " USB FAT" );
109
110
test (" copy" , sd, usb, " SD LittleFS" , " USB FAT" );
110
-
111
-
112
-
113
111
}
114
112
115
113
void qspi_and_sd () {
116
- Serial.println (" Formatting both QSPI and SD to FAT" );
117
- qspi->formatFAT ();
118
- sd->formatFAT ();
114
+ Serial.println (" TESTING QSPI AND SD \n\n\n\n " );
115
+ Serial.println (" -----------------------------" );
116
+ Serial.println (" Formatting QSPI to FAT: " + String (qspi->formatFAT ()));
117
+ Serial.println (" Formatting SD to FAT: " + String (sd->formatFAT ()));
118
+ Serial.println (" -----------------------------" );
119
119
120
120
test (" move" , qspi, sd, " QSPI FAT" , " SD FAT" );
121
121
test (" copy" , qspi, sd, " QSPI FAT" , " SD FAT" );
122
122
123
123
test (" move" , sd, qspi, " SD FAT" , " QSPI FAT" );
124
124
test (" copy" , sd, qspi, " SD FAT" , " QSPI FAT" );
125
125
126
- Serial.println (" Formatting QSPI to LittleFS" );
127
- qspi->formatLittleFS ();
126
+ Serial.println (" -----------------------------" );
127
+ Serial.println (" Formatting QSPI to LittleFS:" + String (qspi->formatLittleFS ()));
128
+ Serial.println (" -----------------------------" );
129
+
128
130
test (" move" , qspi, sd, " QSPI LittleFS" , " SD FAT" );
129
131
test (" copy" , qspi, sd, " QSPI LittleFS" , " SD FAT" );
130
132
131
133
test (" move" , sd, qspi, " SD FAT" , " QSPI LittleFS" );
132
134
test (" copy" , sd, qspi, " SD FAT" , " QSPI LittleFS" );
133
135
134
- Serial.println (" Formatting SD to LittleFS" );
135
- sd->formatLittleFS ();
136
+ Serial.println (" -----------------------------" );
137
+ Serial.println (" Formatting SD to LittleFS: " + String (sd->formatLittleFS ()));
138
+ Serial.println (" -----------------------------" );
139
+
136
140
test (" move" , qspi, sd, " QSPI LittleFS" , " SD LittleFS" );
137
141
test (" copy" , qspi, sd, " QSPI LittleFS" , " SD LittleFS" );
138
142
139
143
test (" move" , sd, qspi, " SD LittleFS" , " QSPI LittleFS" );
140
144
test (" copy" , sd, qspi, " SD LittleFS" , " QSPI LittleFS" );
141
145
142
- Serial.println (" Formatting QSPI to FAT" );
143
- qspi->formatFAT ();
146
+ Serial.println (" -----------------------------" );
147
+ Serial.println (" Formatting QSPI to FAT: " + String (qspi->formatFAT ()));
148
+ Serial.println (" -----------------------------" );
144
149
145
150
test (" move" , sd, qspi, " SD LittleFS" , " QSPI FAT" );
146
151
test (" copy" , sd, qspi, " SD LittleFS" , " QSPI FAT" );
@@ -151,26 +156,32 @@ void qspi_and_sd() {
151
156
152
157
153
158
void qspi_and_usb () {
154
- Serial.println (" Formatting both QSPI and USB to FAT" );
155
- qspi->formatFAT ();
156
- usb->formatFAT ();
159
+
160
+ Serial.println (" TESTING QSPI AND USB \n\n\n\n " );
161
+ Serial.println (" -----------------------------" );
162
+ Serial.println (" Formatting QSPI to FAT: " + String (qspi->formatFAT ()));
163
+ Serial.println (" Formatting USB to FAT: " + String (usb->formatFAT ()));
164
+ Serial.println (" -----------------------------" );
157
165
158
166
test (" move" , qspi, usb, " QSPI FAT" , " USB FAT" );
159
167
test (" copy" , qspi, usb, " QSPI FAT" , " USB FAT" );
160
168
161
169
test (" move" , usb, qspi, " USB FAT" , " QSPI FAT" );
162
170
test (" copy" , usb, qspi, " USB FAT" , " QSPI FAT" );
163
171
164
- Serial.println (" Formatting QSPI to LittleFS" );
165
- qspi->formatLittleFS ();
172
+ Serial.println (" -----------------------------" );
173
+ Serial.println (" Formatting QSPI to LittleFS:" + String (qspi->formatLittleFS ()));
174
+ Serial.println (" -----------------------------" );
175
+
166
176
test (" move" , qspi, usb, " QSPI LittleFS" , " USB FAT" );
167
177
test (" copy" , qspi, usb, " QSPI LittleFS" , " USB FAT" );
168
178
169
179
test (" move" , usb, qspi, " USB FAT" , " QSPI LittleFS" );
170
180
test (" copy" , usb, qspi, " USB FAT" , " QSPI LittleFS" );
171
181
172
- Serial.println (" Formatting USB to LittleFS" );
173
- usb->formatLittleFS ();
182
+ Serial.println (" -----------------------------" );
183
+ Serial.println (" Formatting USB to LittleFS: " + String (usb->formatLittleFS ()));
184
+ Serial.println (" -----------------------------" );
174
185
175
186
test (" move" , qspi, usb, " QSPI LittleFS" , " USB LittleFS" );
176
187
test (" copy" , qspi, usb, " QSPI LittleFS" , " USB LittleFS" );
@@ -179,7 +190,10 @@ void qspi_and_usb() {
179
190
test (" move" , usb, qspi, " USB LittleFS" , " QSPI LittleFS" );
180
191
test (" copy" , usb, qspi, " USB LittleFS" , " QSPI LittleFS" );
181
192
182
- qspi->formatFAT ();
193
+ Serial.println (" -----------------------------" );
194
+ Serial.println (" Formatting QSPI to FAT:" + String (qspi->formatFAT ()));
195
+ Serial.println (" -----------------------------" );
196
+
183
197
test (" move" , usb, qspi, " USB LittleFS" , " QSPI FAT" );
184
198
test (" copy" , usb, qspi, " USB LittleFS" , " QSPI FAT" );
185
199
@@ -195,8 +209,9 @@ void setup(){
195
209
196
210
#if defined(HAS_USB) && defined(HAS_SD) && defined(HAS_QSPI)
197
211
qspi_and_usb ();
198
- qspi_and_sd ();
199
212
sd_and_usb ();
213
+ qspi_and_sd ();
214
+ Serial.println (" Tests finished" );
200
215
#elif defined(HAS_USB) && defined(HAS_SD)
201
216
sd_and_usb ();
202
217
#elif defined(HAS_USB) && defined(HAS_QSPI)
0 commit comments