sample config file
Dependencies: SDFileSystem3 mbed ConfigFile
Fork of ConfigFile_TestProgram by
Revision 5:f30d74147daf, committed 2015-06-29
- Comitter:
- ftagius
- Date:
- Mon Jun 29 17:42:47 2015 +0000
- Parent:
- 4:72e5ea7cacde
- Commit message:
- sample program with config file support;
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDFileSystem.lib Mon Jun 29 17:42:47 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/CaryCoders/code/SDFileSystem3/#6f25adda7fde
--- a/main.cpp Wed Oct 13 10:48:24 2010 +0000 +++ b/main.cpp Mon Jun 29 17:42:47 2015 +0000 @@ -5,12 +5,13 @@ * http://shinta.main.jp/ */ #include "mbed.h" - #include "ConfigFile.h" - +#include "SDFileSystem.h" + +SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd"); // the pinout on the mbed Cool Components workshop board +Serial pc(USBTX,USBRX); ConfigFile cfg; -LocalFileSystem local("local"); - + /** * View the list. */ @@ -79,39 +80,55 @@ char *key4 = " Message2 "; char *key5 = " Message3 "; char value[BUFSIZ]; - + + pc.baud(9600); + + printf("config file test!\r\n"); + + sd.mount(); + int rc=mkdir("/sd/config", 0777); + printf("rc from mkdir is %d\r\n",rc); + wait(1); + FILE *fp = fopen("/sd/config/input.cfg", "r"); + if(fp == NULL) { + error("Could not open file for write\r\n"); + } + else + printf("file opened for writing\r\n"); /* * Read a configuration file from a mbed. */ - cfg.read("/local/input.cfg"); + + cfg.read("/sd/config/input.cfg"); /* * Read a configuration value. */ if (cfg.getValue(key1, &value[0], sizeof(value))) { - printf("'%s'='%s'\n", key1, value); + printf("'%s'='%s'\r\n", key1, value); } if (cfg.getValue(key2, &value[0], sizeof(value))) { - printf("'%s'='%s'\n", key2, value); + printf("'%s'='%s'\r\n", key2, value); } if (cfg.getValue(key3, &value[0], sizeof(value))) { - printf("'%s'='%s'\n", key3, value); + printf("'%s'='%s'\r\n", key3, value); } if (cfg.getValue(key4, &value[0], sizeof(value))) { - printf("'%s'='%s'\n", key4, value); + printf("'%s'='%s'\r\n", key4, value); } if (cfg.getValue(key5, &value[0], sizeof(value))) { - printf("'%s'='%s'\n", key5, value); + printf("'%s'='%s'\r\n", key5, value); } /* - * Write a configuration file to a mbed. + * Write a configuration file. */ - cfg.write("/local/output1.cfg"); + cfg.write("/sd/config/output1.cfg"); + pc.printf("wrote config file 1\r\n"); /* * Remove all configurations. @@ -125,10 +142,13 @@ cfg.setValue("DEF", "456"); /* - * Write a configuration file to a mbed. + * Write a configuration file. */ - cfg.write("/local/output2.cfg", "# This is a configuration file for my application."); + cfg.write("/sd/config/output2.cfg", "# This is a configuration file for my application."); + pc.printf("wrote config file 2\r\n"); + fclose(fp); + sd.unmount(); while (1) { } }
--- a/mbed.bld Wed Oct 13 10:48:24 2010 +0000 +++ b/mbed.bld Mon Jun 29 17:42:47 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e +http://mbed.org/users/mbed_official/code/mbed/builds/7cff1c4259d7 \ No newline at end of file