8000
We read every piece of feedback, and take your input very seriously.
1 parent 0f9595e commit 7aa7c3fCopy full SHA for 7aa7c3f
libraries/SPIFFS/examples/SPIFFS_Test/SPIFFS_Test.ino
@@ -2,15 +2,15 @@
2
#include "SPIFFS.h"
3
4
void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
5
- Serial.printf("Listing directory: %s\n", dirname);
+ Serial.printf("Listing directory: %s\r\n", dirname);
6
7
File root = fs.open(dirname);
8
if(!root){
9
- Serial.println("Failed to open directory");
+ Serial.println("- failed to open directory");
10
return;
11
}
12
if(!root.isDirectory()){
13
- Serial.println("Not a directory");
+ Serial.println(" - not a directory");
14
15
16
@@ -25,116 +25,128 @@ void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
25
} else {
26
Serial.print(" FILE: ");
27
Serial.print(file.name());
28
- Serial.print(" SIZE: ");
+ Serial.print("\tSIZE: ");
29
Serial.println(file.size());
30
31
file = root.openNextFile();
32
33
34
35
void readFile(fs::FS &fs, const char * path){
36
- Serial.printf("Reading file: %s\n", path);
+ Serial.printf("Reading file: %s\r\n", path);
37
38
File file = fs.open(path);
39
if(!file || file.isDirectory()){
40
- Serial.println("Failed to open file for reading");
+ Serial.println("- failed to open file for reading");
41
42
43
44
- Serial.print("Read from file: ");
+ Serial.println("- read from file:");
45
while(file.available()){
46
Serial.write(file.read());
47
48
49
50
void writeFile(fs::FS &fs, const char * path, const char * message){
51
- Serial.printf("Writing file: %s\n", path);
+ Serial.printf("Writing file: %s\r\n", path);
52
53
File file = fs.open(path, FILE_WRITE);
54
if(!file){
55
- Serial.println("Failed to open file for writing");
+ Serial.println("- failed to open file for writing");
56
57
58
if(file.print(message)){
59
- Serial.println("File written");
+ Serial.println("- file written");
60
61
- Serial.println("Write failed");
+ Serial.println("- frite failed");
62
63
64
65
void appendFile(fs::FS &fs, const char * path, const char * message){
66
- Serial.printf("Appending to file: %s\n", path);
+ Serial.printf("Appending to file: %s\r\n", path);
67
68
File file = fs.open(path, FILE_APPEND);
69
70
- Serial.println("Failed to open file for appending");
+ Serial.println("- failed to open file for appending");
71
72
73
74
- Serial.println("Message appended");
+ Serial.println("- message appended");
75
76
- Serial.println("Append failed");
+ Serial.println("- append failed");
77
78
79
80
void renameFile(fs::FS &fs, const char * path1, const char * path2){
81
- Serial.printf("Renaming file %s to %s\n", path1, path2);
+ Serial.printf("Renaming file %s to %s\r\n", path1, path2);
82
if (fs.rename(path1, path2)) {
83
- Serial.println("File renamed");
+ Serial.println("- file renamed");
84
85
- Serial.println("Rename failed");
+ Serial.println("- rename failed");
86
87
88
89
void deleteFile(fs::FS &fs, const char * path){
90
- Serial.printf("Deleting file: %s\n", path);
+ Serial.printf("Deleting file: %s\r\n", path);
91
if(fs.remove(path)){
92
- Serial.println("File deleted");
+ Serial.println("- file deleted");
93
94
- Serial.println("Delete failed");
+ Serial.println("- delete failed");
95
96
97
98
void testFileIO(fs::FS &fs, const char * path){
99
- File file = fs.open(path);
+ Serial.printf("Testing file I/O with %s\r\n", path);
100
+
101
static uint8_t buf[512];
102
size_t len = 0;
103
+ File file = fs.open(path, FILE_WRITE);
104
+ if(!file){
105
106
+ return;
107
+ }
108
109
+ size_t i;
110
+ Serial.print("- writing" );
111
uint32_t start = millis();
- uint32_t end = start;
112
+ for(i=0; i<2048; i++){
113
+ if ((i & 0x001F) == 0x001F){
114
+ Serial.print(".");
115
116
+ file.write(buf, 512);
117
118
+ Serial.println("");
119
+ uint32_t end = millis() - start;
120
+ Serial.printf(" - %u bytes written in %u ms\r\n", 2048 * 512, end);
121
+ file.close();
122
123
+ file = fs.open(path);
124
+ start = millis();
125
+ end = start;
126
+ i = 0;
127
if(file && !file.isDirectory()){
128
len = file.size();
129
size_t flen = len;
130
start = millis();
131
+ Serial.print("- reading" );
132
while(len){
133
size_t toRead = len;
134
if(toRead > 512){
135
toRead = 512;
136
137
file.read(buf, toRead);
138
+ if ((i++ & 0x001F) == 0x001F){
139
140
141
len -= toRead;
142
143
144
end = millis() - start;
- Serial.printf("%u bytes read for %u ms\n", flen, end);
145
+ Serial.printf("- %u bytes read in %u ms\r\n", flen, end);
146
file.close();
147
- }
-
- file = fs.open(path, FILE_WRITE);
- if(!file){
- return;
148
149
- size_t i;
- start = millis();
- for(i=0; i<2048; i++){
- file.write(buf, 512);
- end = millis() - start;
- Serial.printf("%u bytes written for %u ms\n", 2048 * 512, end);
- file.close();
150
151
152
void setup(){
@@ -146,12 +158,14 @@ void setup(){
158
159
listDir(SPIFFS, "/", 0);
160
writeFile(SPIFFS, "/hello.txt", "Hello ");
- appendFile(SPIFFS, "/hello.txt", "World!\n");
161
+ appendFile(SPIFFS, "/hello.txt", "World!\r\n");
162
readFile(SPIFFS, "/hello.txt");
- deleteFile(SPIFFS, "/foo.txt");
163
renameFile(SPIFFS, "/hello.txt", "/foo.txt");
153
164
readFile(SPIFFS, "/foo.txt");
165
+ deleteFile(SPIFFS, "/foo.txt");
154
166
testFileIO(SPIFFS, "/test.txt");
167
+ deleteFile(SPIFFS, "/test.txt");
168
+ Serial.println( "Test complete" );
155
169
156
170
157
171
void loop(){