@@ -39,18 +39,26 @@ void setup()
3939 Serial.println (" Creating 'ARDUINO/SD' directory" );
4040 SD.mkdir (" ARDUINO/SD" );
4141
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+
4250 /* Test open() method */
4351 Serial.println (" Opening 'STM32/Toremove.txt' file" );
4452 MyFile = SD.open (" STM32/Toremove.txt" , FILE_WRITE);
45- if (MyFile) {
53+ if (MyFile) {
4654 Serial.println (" Closing 'STM32/Toremove.txt' file" );
4755 MyFile.close ();
4856 } else {
4957 Serial.println (" Error to open 'STM32/Toremove.txt' file" );
5058 }
5159 Serial.println (" Opening 'ARDUINO/SD/ARDUINO_SD_TEXT.txt' file" );
5260 MyFile = SD.open (" ARDUINO/SD/ARDUINO_SD_TEXT.txt" , FILE_WRITE);
53- if (MyFile) {
61+ if (MyFile) {
5462 /* Test print() method */
5563 Serial.print (" writing \" " );
5664 Serial.print ((const char *)wtext);
@@ -67,7 +75,7 @@ void setup()
6775
6876 Serial.println (" Opening 'ARDUINO/SD/ARDUINO_SD_TEXT.txt' file" );
6977 MyFile = SD.open (" ARDUINO/SD/ARDUINO_SD_TEXT.txt" );
70- if (MyFile) {
78+ if (MyFile) {
7179 bytesread = MyFile.read (rtext, MyFile.size ());
7280 Serial.println (" Closing 'ARDUINO/SD/ARDUINO_SD_TEXT.txt' file" );
7381 MyFile.close ();
@@ -77,7 +85,7 @@ void setup()
7785
7886 Serial.println (" Opening 'ARDUINO/SD/TEXT.txt' file" );
7987 MyFile = SD.open (" ARDUINO/SD/TEXT.txt" , FILE_WRITE);
80- if (MyFile) {
88+ if (MyFile) {
8189 byteswritten = MyFile.print ((const char *)rtext);
8290 MyFile.flush ();
8391 Serial.println (" Closing 'ARDUINO/SD/TEXT.txt' file" );
@@ -88,7 +96,7 @@ void setup()
8896
8997 Serial.println (" Opening 'ARDUINO/SD/TEXT.txt' file" );
9098 MyFile = SD.open (" ARDUINO/SD/TEXT.txt" );
91- if (MyFile) {
99+ if (MyFile) {
92100 /* Test size() method */
93101 file_size = MyFile.size ();
94102 Serial.print (" TEXT.txt size: " );
@@ -97,20 +105,20 @@ void setup()
97105 /* Test position and seek method */
98106 Serial.print (" TEXT.txt position value: " );
99107 Serial.println (MyFile.position ());
100- if (!MyFile.seek (MyFile.size ()+ 1 )) {
108+ if (!MyFile.seek (MyFile.size () + 1 )) {
101109 Serial.println (" TEXT.txt seek value over size: OK" );
102110 } else {
103111 Serial.println (" TEXT.txt seek value over size: KO" );
104112 }
105- if (MyFile.seek (MyFile.size ())) {
113+ if (MyFile.seek (MyFile.size ())) {
106114 Serial.println (" TEXT.txt seek value to size: OK" );
107115 } else {
108116 Serial.println (" TEXT.txt seek value to size: KO" );
109117 }
110118 Serial.print (" TEXT.txt position value: " );
111119 Serial.println (MyFile.position ());
112120
113- if (MyFile.seek (0 )) {
121+ if (MyFile.seek (0 )) {
114122 Serial.println (" TEXT.txt seek value to 0: OK" );
115123 } else {
116124 Serial.println (" TEXT.txt seek value to 0: KO" );
@@ -120,7 +128,7 @@ void setup()
120128
121129 /* Test peek() method */
122130 Serial.println (" TEXT.txt peek (10 times): " );
123- for (i = 0 ; i< 10 ; i++)
131+ for (i = 0 ; i < 10 ; i++)
124132 {
125133 peek_val = MyFile.peek ();
126134 Serial.print (peek_val);
@@ -132,7 +140,7 @@ void setup()
132140
133141 /* Test available() and read() methods */
134142 Serial.println (" TEXT.txt content read byte per byte: " );
135- while (MyFile.available ())
143+ while (MyFile.available ())
136144 {
137145 rtext[i] = (uint8_t )MyFile.read ();
138146 Serial.print (rtext[i]);
@@ -150,7 +158,7 @@ void setup()
150158
151159 /* Test isDirectory() method */
152160 MyFile = File (" STM32" );
153- if (MyFile) {
161+ if (MyFile) {
154162 Serial.print (" Is 'STM32' is a dir: " );
155163 if (MyFile.isDirectory ())
156164 Serial.println (" OK" );
@@ -162,7 +170,7 @@ void setup()
162170
163171 Serial.println (" Opening 'STM32/Toremove.txt' file" );
164172 MyFile = SD.open (" STM32/Toremove.txt" );
165- if (MyFile) {
173+ if (MyFile) {
166174 Serial.print (" Is 'STM32/Toremove.txt' is a file: " );
167175 if (MyFile.isDirectory ())
168176 Serial.println (" KO" );
@@ -175,23 +183,23 @@ void setup()
175183 }
176184 /* Test exists(), remove() and rmdir() methods */
177185 Serial.print (" Removing 'STM32/Toremove.txt' file..." );
178- while (SD.exists (" STM32/Toremove.txt" ) == TRUE )
186+ while (SD.exists (" STM32/Toremove.txt" ) == TRUE )
179187 {
180188 SD.remove (" STM32/Toremove.txt" );
181- }
189+ }
182190 Serial.println (" done" );
183191
184192 Serial.print (" Removing 'STM32' dir..." );
185- while (SD.exists (" STM32" ) == TRUE )
193+ while (SD.exists (" STM32" ) == TRUE )
186194 {
187195 SD.rmdir (" STM32" );
188- }
196+ }
189197 Serial.println (" done" );
190198
191199 /* Test println(), println(data) methods */
192200 Serial.println (" Opening 'ARDUINO/SD/PRINT.txt' file" );
193201 MyFile = SD.open (" ARDUINO/SD/PRINT.txt" , FILE_WRITE);
194- if (MyFile) {
202+ if (MyFile) {
195203 String str = String (" This is a String object on line 7" );
196204 Serial.print (" Printing to 'ARDUINO/SD/PRINT.txt' file..." );
197205 MyFile.println (" This should be line 1" );
@@ -211,7 +219,7 @@ void setup()
211219 /* Test write(buf, len) method */
212220 Serial.println (" Opening 'ARDUINO/SD/WRITE.txt' file" );
213221 MyFile = SD.open (" ARDUINO/SD/WRITE.txt" , FILE_WRITE);
214- if (MyFile) {
222+ if (MyFile) {
215223 Serial.print (" Writing 'ARDUINO/SD/WRITE.txt' file: " );
216224 byteswritten = MyFile.write (wtext, BUFFERSIZE);
217225 Serial.print (byteswritten);
@@ -225,19 +233,19 @@ void setup()
225233 /* Test read(buf, len) method */
226234 Serial.println (" Opening 'ARDUINO/SD/WRITE.txt' file" );
227235 MyFile = SD.open (" ARDUINO/SD/WRITE.txt" );
228- if (MyFile) {
236+ if (MyFile) {
229237 Serial.println (" Reading 'ARDUINO/SD/WRITE.txt' file:" );
230238 bytesread = MyFile.read (rtext, MyFile.size ());
231239 Serial.println ((const char *)rtext);
232240 Serial.println (" Closing 'ARDUINO/SD/WRITE.txt' file" );
233241 MyFile.close ();
234- } else {
242+ } else {
235243 Serial.println (" Error to open 'ARDUINO/SD/WRITE.txt' file" );
236244 }
237245 Serial.println (" ###### End of the SD tests ######" );
238246}
239247
240248void loop ()
241249{
242- // do nothing
250+ // do nothing
243251}
0 commit comments