Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * This app shows the possibilities of the Simple|Silly File System.
- * The filesystem uses the external flash memory of the Spark-core to store files. it can store 16 files of max 64kB each.
- * I use it in a small webserver app I made; it works stable and is pretty fast.
- * This is the beta version, please informa me about hints and bugs: @marcus
- * enjoy!
- *
- *
- */
- #include "sfs.h"
- sfs fs = sfs(); //simple|silly file system
- //proto's
- String get_file_content(String name,String output); //<< does not work in the online compiler, so code is commented out
- void setup() {
- Serial1.begin(57600); // used to show the results
- char buffer[65];
- char filename[] = "Myfile";
- char filename1[] = "Football";
- int len;
- Serial1.println("SFS Demo");
- // fs.erase_all_files();
- fs.create(filename);
- fs.append("Hello World!!\r\n");
- fs.append("A sparking new world!");
- fs.close();
- fs.create(filename1);
- fs.append("World Cup Football:\r\n");
- fs.append("The Netherlands will win it!!");
- fs.close();
- //read a file in chunks: handy when you have to send a large file to a stream.
- fs.open(filename);
- while (fs.read(buffer, 64)) {
- Serial1.print(buffer); // or choose another output method, or store the data in a variable.
- }
- fs.close();
- Serial1.println("\r\n");
- //Get a file PHP style. WARNING: I compile locally, than it works, but in the online environment online it does not...
- String content = get_file_content(filename1,content);
- Serial1.println(content);
- //Get de directory of files:
- fs.dir(NULL); //initialize directory functions.
- char name[44];
- while ((len = fs.dir(name)) > 0) {
- Serial1.print(name);
- Serial1.print("\tfilesize:");
- Serial1.println(len, DEC);
- }
- }
- void loop() {
- }
- /**
- * Dumps a file in a HEX editor like style
- * @param name
- */
- void dump_file(char*name) {
- int handle = fs.get_handle(name);
- fs.dump(handle, 256);
- }
- String get_file_content(String name,String output){
- /* This piece works on my local compile, but not in the online editor... have to sort that out.
- unsigned char fn[33];
- char buffer[65];
- name.getBytes(fn,32,0);
- fs.open((char*)fn);
- while (fs.read(buffer, 64)) {
- output+=buffer;
- }
- fs.close();
- return output;
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement