BoardOrange TestProgram 2013/08/13 SD => SDHC 対応
Dependencies: EthernetNetIf FATFileSystem HTTPServer MSCFileSystem_Lib TextLCD mbed
Fork of SDHCFileSystem by
Revision 1:ddba0c9b886a, committed 2013-08-13
- Comitter:
- MasudaToshio
- Date:
- Tue Aug 13 02:42:45 2013 +0000
- Parent:
- 0:90601632692f
- Commit message:
- BoardOrange TestProgram; SD -> SDHC???
Changed in this revision
diff -r 90601632692f -r ddba0c9b886a EthernetNetIf.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EthernetNetIf.lib Tue Aug 13 02:42:45 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/donatien/code/EthernetNetIf/#bc7df6da7589
diff -r 90601632692f -r ddba0c9b886a FATFileSystem.lib --- a/FATFileSystem.lib Sat Jul 24 19:45:29 2010 +0000 +++ b/FATFileSystem.lib Tue Aug 13 02:42:45 2013 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_unsupported/code/fatfilesystem/ \ No newline at end of file +http://mbed.org/users/MasudaToshio/code/FATFileSystem/#333d6e93e58f
diff -r 90601632692f -r ddba0c9b886a HTTPServer.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HTTPServer.lib Tue Aug 13 02:42:45 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/donatien/code/HTTPServer/#d753966e4d97
diff -r 90601632692f -r ddba0c9b886a MSCFileSystem_Lib.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MSCFileSystem_Lib.lib Tue Aug 13 02:42:45 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/MasudaToshio/code/MSCFileSystem_Lib/#f1883e3e0ed5
diff -r 90601632692f -r ddba0c9b886a TextLCD.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TextLCD.lib Tue Aug 13 02:42:45 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/simon/code/TextLCD/#44f34c09bd37
diff -r 90601632692f -r ddba0c9b886a main.cpp --- a/main.cpp Sat Jul 24 19:45:29 2010 +0000 +++ b/main.cpp Tue Aug 13 02:42:45 2013 +0000 @@ -1,12 +1,162 @@ - #include "mbed.h" - #include "string" - #include "SDHCFileSystem.h" +#include "mbed.h" +#include "string" + +//////////////////////////////////////// +//////// general setting //////// +//////////////////////////////////////// +//#define USE_TextLCD_20x4 +#define USE_FIXED_IP + +//////////////////////////////////////// +//////// For TextLCD //////// +//////////////////////////////////////// +#include "TextLCD.h" +#ifdef USE_TextLCD_20x4 +//TextLCD lcd( p24, p26, p27, p28, p29, p30, TextLCD::LCD20x4 ); // rs, e, d0-d3 +#else +TextLCD lcd( p24, p26, p27, p28, p29, p30 ); // rs, e, d0-d3 +#endif + +//////////////////////////////////////// +//////// For SD_card //////// +//////////////////////////////////////// +#include "SDHCFileSystem.h" SDFileSystem sd(p5, p6, p7, p8, "sd"); // mosi, miso, sclk, cs - - int main() { - - FILE *fp = fopen("/sd/myfile.txt", "w"); - fprintf(fp, "\n\rHello World!\n\r"); - fclose(fp); - } \ No newline at end of file + +//////////////////////////////////////// +//////// For USB storage //////// +//////////////////////////////////////// +#include "MSCFileSystem.h" +MSCFileSystem usb("usb"); + +//////////////////////////////////////// +//////// For Ethernet test //////// +//////////////////////////////////////// +#include "EthernetNetIf.h" +#include "HTTPServer.h" +#ifdef USE_FIXED_IP +EthernetNetIf eth( + IpAddr(192,168,0,7), //IP Address + IpAddr(255,255,255,0), //Network Mask + IpAddr(192,168,0,1), //Gateway + IpAddr(192,168,0,1) //DNS +); +#else +EthernetNetIf eth; +#endif +HTTPServer svr; +LocalFileSystem web("local"); + + +void test_TextLCD( void ); +void test_file_write( char *title, char *path ); +void test_httpserver( void ); +int position( void ); + +int main() { + test_TextLCD(); + wait( 1 ); + test_file_write( "SD card", "/sd/star_bd.txt" ); + wait( 1 ); + test_file_write( "USB storage", "/usb/star_bd.txt" ); + wait( 1 ); + test_httpserver(); +} + + +void test_TextLCD( void ) { + // TextLCD test + +#ifdef USE_TextLCD_20x4 + lcd.locate( 0, 0 ); + for ( int i = 0, c = '0'; i < 20; i++, c++ ) + lcd.putc( c ); + + for ( int i = 0, c = 'A'; i < 20; i++, c++ ) + lcd.putc( c ); + + for ( int i = 0, c = 'a'; i < 20; i++, c++ ) + lcd.putc( c ); + for ( int i = 0, c = '0' - 10; i < 20; i++, c++ ) + lcd.putc( c ); + exit( 0 ); + wait( 300 ); + lcd.cls(); +#endif // USE_TextLCD_20x4 + + lcd.locate( 0, 0 ); + lcd.printf( "TextLCD: OK?" ); + lcd.locate( 0, 1 ); + lcd.printf( "" ); + +} + +void test_file_write( char *title, char *path ) { + // SD card test + lcd.locate( 0, position() ); + lcd.printf( "%s: ", title ); + + FILE *fp = fopen( path, "w" ); + if ( fp == NULL ) { + lcd.printf( "error" ); + error( "Could not open file for write\n" ); + } + fprintf( fp, "The mbed writing a file through the star board orange (%s)!", title ); + fclose( fp ); + + lcd.printf( "OK." ); +} + + +void test_httpserver( void ) { + DigitalOut led1( LED1 ); + + lcd.locate( 0, position() ); + lcd.printf( "HTTP srv: " ); + + Base::add_rpc_class<DigitalOut>(); + + printf("Setting up...n"); + EthernetErr ethErr = eth.setup(); + if ( ethErr ) { + lcd.printf( "error" ); + error( "error @ eth.setup()\n" ); + } + lcd.printf("OK "); + + FSHandler::mount("/local", "/"); //Mount /webfs path on web root path + FSHandler::mount("/sd", "/sd"); //Mount /webfs path on web sd path + FSHandler::mount("/usb", "/usb"); //Mount /webfs path on web usb path + + svr.addHandler<FSHandler>("/"); //Default handler + svr.addHandler<FSHandler>("/sd"); + svr.addHandler<FSHandler>("/usb"); + //Example : Access to mbed.htm : http://a.b.c.d/mbed.htm or http://a.b.c.d/files/mbed.htm + + svr.bind(80); + + lcd.locate( 5, position() -1 ); + lcd.printf("Listening"); + + Timer tm; + tm.start(); + //Listen indefinitely + while (true) { + Net::poll(); + if (tm.read()>.5) { + led1=!led1; //Show that we are alive + tm.start(); + } + } +} + +int position( void ) { + static int p = 0; + +#ifdef USE_TextLCD_20x4 + return( ++p % 4 ); +#else + return( ++p % 2 ); +#endif +}