@@ -39,18 +39,26 @@ void setup()
39
39
Serial.println (" Creating 'ARDUINO/SD' directory" );
40
40
SD.mkdir (" ARDUINO/SD" );
41
41
42
+ /* Test bool operator method */
43
+ Serial.print (" Test bool operator..." );
44
+ if (!MyFile) {
45
+ Serial.println (" OK" );
46
+ } else {
47
+ Serial.println (" Error MyFile should not be initialized!" );
48
+ }
49
+
42
50
/* Test open() method */
43
51
Serial.println (" Opening 'STM32/Toremove.txt' file" );
44
52
MyFile = SD.open (" STM32/Toremove.txt" , FILE_WRITE);
45
- if (MyFile) {
53
+ if (MyFile) {
46
54
Serial.println (" Closing 'STM32/Toremove.txt' file" );
47
55
MyFile.close ();
48
56
} else {
49
57
Serial.println (" Error to open 'STM32/Toremove.txt' file" );
50
58
}
51
59
Serial.println (" Opening 'ARDUINO/SD/ARDUINO_SD_TEXT.txt' file" );
52
60
MyFile = SD.open (" ARDUINO/SD/ARDUINO_SD_TEXT.txt" , FILE_WRITE);
53
- if (MyFile) {
61
+ if (MyFile) {
54
62
/* Test print() method */
55
63
Serial.print (" writing \" " );
56
64
Serial.print ((const char *)wtext);
@@ -67,7 +75,7 @@ void setup()
67
75
68
76
Serial.println (" Opening 'ARDUINO/SD/ARDUINO_SD_TEXT.txt' file" );
69
77
MyFile = SD.open (" ARDUINO/SD/ARDUINO_SD_TEXT.txt" );
70
- if (MyFile) {
78
+ if (MyFile) {
71
79
bytesread = MyFile.read (rtext, MyFile.size ());
72
80
Serial.println (" Closing 'ARDUINO/SD/ARDUINO_SD_TEXT.txt' file" );
73
81
MyFile.close ();
@@ -77,7 +85,7 @@ void setup()
77
85
78
86
Serial.println (" Opening 'ARDUINO/SD/TEXT.txt' file" );
79
87
MyFile = SD.open (" ARDUINO/SD/TEXT.txt" , FILE_WRITE);
80
- if (MyFile) {
88
+ if (MyFile) {
81
89
byteswritten = MyFile.print ((const char *)rtext);
82
90
MyFile.flush ();
83
91
Serial.println (" Closing 'ARDUINO/SD/TEXT.txt' file" );
@@ -88,7 +96,7 @@ void setup()
88
96
89
97
Serial.println (" Opening 'ARDUINO/SD/TEXT.txt' file" );
90
98
MyFile = SD.open (" ARDUINO/SD/TEXT.txt" );
91
- if (MyFile) {
99
+ if (MyFile) {
92
100
/* Test size() method */
93
101
file_size = MyFile.size ();
94
102
Serial.print (" TEXT.txt size: " );
@@ -97,20 +105,20 @@ void setup()
97
105
/* Test position and seek method */
98
106
Serial.print (" TEXT.txt position value: " );
99
107
Serial.println (MyFile.position ());
100
- if (!MyFile.seek (MyFile.size ()+ 1 )) {
108
+ if (!MyFile.seek (MyFile.size () + 1 )) {
101
109
Serial.println (" TEXT.txt seek value over size: OK" );
102
110
} else {
103
111
Serial.println (" TEXT.txt seek value over size: KO" );
104
112
}
105
- if (MyFile.seek (MyFile.size ())) {
113
+ if (MyFile.seek (MyFile.size ())) {
106
114
Serial.println (" TEXT.txt seek value to size: OK" );
107
115
} else {
108
116
Serial.println (" TEXT.txt seek value to size: KO" );
109
117
}
110
118
Serial.print (" TEXT.txt position value: " );
111
119
Serial.println (MyFile.position ());
112
120
113
- if (MyFile.seek (0 )) {
121
+ if (MyFile.seek (0 )) {
114
122
Serial.println (" TEXT.txt seek value to 0: OK" );
115
123
} else {
116
124
Serial.println (" TEXT.txt seek value to 0: KO" );
@@ -120,7 +128,7 @@ void setup()
120
128
121
129
/* Test peek() method */
122
130
Serial.println (" TEXT.txt peek (10 times): " );
123
- for (i = 0 ; i< 10 ; i++)
131
+ for (i = 0 ; i < 10 ; i++)
124
132
{
125
133
peek_val = MyFile.peek ();
126
134
Serial.print (peek_val);
@@ -132,7 +140,7 @@ void setup()
132
140
133
141
/* Test available() and read() methods */
134
142
Serial.println (" TEXT.txt content read byte per byte: " );
135
- while (MyFile.available ())
143
+ while (MyFile.available ())
136
144
{
137
145
rtext[i] = (uint8_t )MyFile.read ();
138
146
Serial.print (rtext[i]);
@@ -150,7 +158,7 @@ void setup()
150
158
151
159
/* Test isDirectory() method */
152
160
MyFile = File (" STM32" );
153
- if (MyFile) {
161
+ if (MyFile) {
154
162
Serial.print (" Is 'STM32' is a dir: " );
155
163
if (MyFile.isDirectory ())
156
164
Serial.println (" OK" );
@@ -162,7 +170,7 @@ void setup()
162
170
163
171
Serial.println (" Opening 'STM32/Toremove.txt' file" );
164
172
MyFile = SD.open (" STM32/Toremove.txt" );
165
- if (MyFile) {
173
+ if (MyFile) {
166
174
Serial.print (" Is 'STM32/Toremove.txt' is a file: " );
167
175
if (MyFile.isDirectory ())
168
176
Serial.println (" KO" );
@@ -175,23 +183,23 @@ void setup()
175
183
}
176
184
/* Test exists(), remove() and rmdir() methods */
177
185
Serial.print (" Removing 'STM32/Toremove.txt' file..." );
178
- while (SD.exists (" STM32/Toremove.txt" ) == TRUE )
186
+ while (SD.exists (" STM32/Toremove.txt" ) == TRUE )
179
187
{
180
188
SD.remove (" STM32/Toremove.txt" );
181
- }
189
+ }
182
190
Serial.println (" done" );
183
191
184
192
Serial.print (" Removing 'STM32' dir..." );
185
- while (SD.exists (" STM32" ) == TRUE )
193
+ while (SD.exists (" STM32" ) == TRUE )
186
194
{
187
195
SD.rmdir (" STM32" );
188
- }
196
+ }
189
197
Serial.println (" done" );
190
198
191
199
/* Test println(), println(data) methods */
192
200
Serial.println (" Opening 'ARDUINO/SD/PRINT.txt' file" );
193
201
MyFile = SD.open (" ARDUINO/SD/PRINT.txt" , FILE_WRITE);
194
- if (MyFile) {
202
+ if (MyFile) {
195
203
String str = String (" This is a String object on line 7" );
196
204
Serial.print (" Printing to 'ARDUINO/SD/PRINT.txt' file..." );
197
205
MyFile.println (" This should be line 1" );
@@ -211,7 +219,7 @@ void setup()
211
219
/* Test write(buf, len) method */
212
220
Serial.println (" Opening 'ARDUINO/SD/WRITE.txt' file" );
213
221
MyFile = SD.open (" ARDUINO/SD/WRITE.txt" , FILE_WRITE);
214
- if (MyFile) {
222
+ if (MyFile) {
215
223
Serial.print (" Writing 'ARDUINO/SD/WRITE.txt' file: " );
216
224
byteswritten = MyFile.write (wtext, BUFFERSIZE);
217
225
Serial.print (byteswritten);
@@ -225,19 +233,19 @@ void setup()
225
233
/* Test read(buf, len) method */
226
234
Serial.println (" Opening 'ARDUINO/SD/WRITE.txt' file" );
227
235
MyFile = SD.open (" ARDUINO/SD/WRITE.txt" );
228
- if (MyFile) {
236
+ if (MyFile) {
229
237
Serial.println (" Reading 'ARDUINO/SD/WRITE.txt' file:" );
230
238
bytesread = MyFile.read (rtext, MyFile.size ());
231
239
Serial.println ((const char *)rtext);
232
240
Serial.println (" Closing 'ARDUINO/SD/WRITE.txt' file" );
233
241
MyFile.close ();
234
- } else {
242
+ } else {
235
243
Serial.println (" Error to open 'ARDUINO/SD/WRITE.txt' file" );
236
244
}
237
245
Serial.println (" ###### End of the SD tests ######" );
238
246
}
239
247
240
248
void loop ()
241
249
{
242
- // do nothing
250
+ // do nothing
243
251
}
0 commit comments