![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
BoardOrange TestProgram 2013/08/13 SD => SDHC 対応
Dependencies: EthernetNetIf FATFileSystem HTTPServer MSCFileSystem_Lib TextLCD mbed
Fork of SDHCFileSystem by
main.cpp@1:ddba0c9b886a, 2013-08-13 (annotated)
- Committer:
- MasudaToshio
- Date:
- Tue Aug 13 02:42:45 2013 +0000
- Revision:
- 1:ddba0c9b886a
- Parent:
- 0:90601632692f
BoardOrange TestProgram; SD -> SDHC???
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MasudaToshio | 1:ddba0c9b886a | 1 | #include "mbed.h" |
MasudaToshio | 1:ddba0c9b886a | 2 | #include "string" |
MasudaToshio | 1:ddba0c9b886a | 3 | |
MasudaToshio | 1:ddba0c9b886a | 4 | //////////////////////////////////////// |
MasudaToshio | 1:ddba0c9b886a | 5 | //////// general setting //////// |
MasudaToshio | 1:ddba0c9b886a | 6 | //////////////////////////////////////// |
MasudaToshio | 1:ddba0c9b886a | 7 | //#define USE_TextLCD_20x4 |
MasudaToshio | 1:ddba0c9b886a | 8 | #define USE_FIXED_IP |
MasudaToshio | 1:ddba0c9b886a | 9 | |
MasudaToshio | 1:ddba0c9b886a | 10 | //////////////////////////////////////// |
MasudaToshio | 1:ddba0c9b886a | 11 | //////// For TextLCD //////// |
MasudaToshio | 1:ddba0c9b886a | 12 | //////////////////////////////////////// |
MasudaToshio | 1:ddba0c9b886a | 13 | #include "TextLCD.h" |
MasudaToshio | 1:ddba0c9b886a | 14 | #ifdef USE_TextLCD_20x4 |
MasudaToshio | 1:ddba0c9b886a | 15 | //TextLCD lcd( p24, p26, p27, p28, p29, p30, TextLCD::LCD20x4 ); // rs, e, d0-d3 |
MasudaToshio | 1:ddba0c9b886a | 16 | #else |
MasudaToshio | 1:ddba0c9b886a | 17 | TextLCD lcd( p24, p26, p27, p28, p29, p30 ); // rs, e, d0-d3 |
MasudaToshio | 1:ddba0c9b886a | 18 | #endif |
MasudaToshio | 1:ddba0c9b886a | 19 | |
MasudaToshio | 1:ddba0c9b886a | 20 | //////////////////////////////////////// |
MasudaToshio | 1:ddba0c9b886a | 21 | //////// For SD_card //////// |
MasudaToshio | 1:ddba0c9b886a | 22 | //////////////////////////////////////// |
MasudaToshio | 1:ddba0c9b886a | 23 | #include "SDHCFileSystem.h" |
xxll | 0:90601632692f | 24 | |
xxll | 0:90601632692f | 25 | SDFileSystem sd(p5, p6, p7, p8, "sd"); // mosi, miso, sclk, cs |
MasudaToshio | 1:ddba0c9b886a | 26 | |
MasudaToshio | 1:ddba0c9b886a | 27 | //////////////////////////////////////// |
MasudaToshio | 1:ddba0c9b886a | 28 | //////// For USB storage //////// |
MasudaToshio | 1:ddba0c9b886a | 29 | //////////////////////////////////////// |
MasudaToshio | 1:ddba0c9b886a | 30 | #include "MSCFileSystem.h" |
MasudaToshio | 1:ddba0c9b886a | 31 | MSCFileSystem usb("usb"); |
MasudaToshio | 1:ddba0c9b886a | 32 | |
MasudaToshio | 1:ddba0c9b886a | 33 | //////////////////////////////////////// |
MasudaToshio | 1:ddba0c9b886a | 34 | //////// For Ethernet test //////// |
MasudaToshio | 1:ddba0c9b886a | 35 | //////////////////////////////////////// |
MasudaToshio | 1:ddba0c9b886a | 36 | #include "EthernetNetIf.h" |
MasudaToshio | 1:ddba0c9b886a | 37 | #include "HTTPServer.h" |
MasudaToshio | 1:ddba0c9b886a | 38 | #ifdef USE_FIXED_IP |
MasudaToshio | 1:ddba0c9b886a | 39 | EthernetNetIf eth( |
MasudaToshio | 1:ddba0c9b886a | 40 | IpAddr(192,168,0,7), //IP Address |
MasudaToshio | 1:ddba0c9b886a | 41 | IpAddr(255,255,255,0), //Network Mask |
MasudaToshio | 1:ddba0c9b886a | 42 | IpAddr(192,168,0,1), //Gateway |
MasudaToshio | 1:ddba0c9b886a | 43 | IpAddr(192,168,0,1) //DNS |
MasudaToshio | 1:ddba0c9b886a | 44 | ); |
MasudaToshio | 1:ddba0c9b886a | 45 | #else |
MasudaToshio | 1:ddba0c9b886a | 46 | EthernetNetIf eth; |
MasudaToshio | 1:ddba0c9b886a | 47 | #endif |
MasudaToshio | 1:ddba0c9b886a | 48 | HTTPServer svr; |
MasudaToshio | 1:ddba0c9b886a | 49 | LocalFileSystem web("local"); |
MasudaToshio | 1:ddba0c9b886a | 50 | |
MasudaToshio | 1:ddba0c9b886a | 51 | |
MasudaToshio | 1:ddba0c9b886a | 52 | void test_TextLCD( void ); |
MasudaToshio | 1:ddba0c9b886a | 53 | void test_file_write( char *title, char *path ); |
MasudaToshio | 1:ddba0c9b886a | 54 | void test_httpserver( void ); |
MasudaToshio | 1:ddba0c9b886a | 55 | int position( void ); |
MasudaToshio | 1:ddba0c9b886a | 56 | |
MasudaToshio | 1:ddba0c9b886a | 57 | int main() { |
MasudaToshio | 1:ddba0c9b886a | 58 | test_TextLCD(); |
MasudaToshio | 1:ddba0c9b886a | 59 | wait( 1 ); |
MasudaToshio | 1:ddba0c9b886a | 60 | test_file_write( "SD card", "/sd/star_bd.txt" ); |
MasudaToshio | 1:ddba0c9b886a | 61 | wait( 1 ); |
MasudaToshio | 1:ddba0c9b886a | 62 | test_file_write( "USB storage", "/usb/star_bd.txt" ); |
MasudaToshio | 1:ddba0c9b886a | 63 | wait( 1 ); |
MasudaToshio | 1:ddba0c9b886a | 64 | test_httpserver(); |
MasudaToshio | 1:ddba0c9b886a | 65 | } |
MasudaToshio | 1:ddba0c9b886a | 66 | |
MasudaToshio | 1:ddba0c9b886a | 67 | |
MasudaToshio | 1:ddba0c9b886a | 68 | void test_TextLCD( void ) { |
MasudaToshio | 1:ddba0c9b886a | 69 | // TextLCD test |
MasudaToshio | 1:ddba0c9b886a | 70 | |
MasudaToshio | 1:ddba0c9b886a | 71 | #ifdef USE_TextLCD_20x4 |
MasudaToshio | 1:ddba0c9b886a | 72 | lcd.locate( 0, 0 ); |
MasudaToshio | 1:ddba0c9b886a | 73 | for ( int i = 0, c = '0'; i < 20; i++, c++ ) |
MasudaToshio | 1:ddba0c9b886a | 74 | lcd.putc( c ); |
MasudaToshio | 1:ddba0c9b886a | 75 | |
MasudaToshio | 1:ddba0c9b886a | 76 | for ( int i = 0, c = 'A'; i < 20; i++, c++ ) |
MasudaToshio | 1:ddba0c9b886a | 77 | lcd.putc( c ); |
MasudaToshio | 1:ddba0c9b886a | 78 | |
MasudaToshio | 1:ddba0c9b886a | 79 | for ( int i = 0, c = 'a'; i < 20; i++, c++ ) |
MasudaToshio | 1:ddba0c9b886a | 80 | lcd.putc( c ); |
MasudaToshio | 1:ddba0c9b886a | 81 | for ( int i = 0, c = '0' - 10; i < 20; i++, c++ ) |
MasudaToshio | 1:ddba0c9b886a | 82 | lcd.putc( c ); |
MasudaToshio | 1:ddba0c9b886a | 83 | exit( 0 ); |
MasudaToshio | 1:ddba0c9b886a | 84 | wait( 300 ); |
MasudaToshio | 1:ddba0c9b886a | 85 | lcd.cls(); |
MasudaToshio | 1:ddba0c9b886a | 86 | #endif // USE_TextLCD_20x4 |
MasudaToshio | 1:ddba0c9b886a | 87 | |
MasudaToshio | 1:ddba0c9b886a | 88 | lcd.locate( 0, 0 ); |
MasudaToshio | 1:ddba0c9b886a | 89 | lcd.printf( "TextLCD: OK?" ); |
MasudaToshio | 1:ddba0c9b886a | 90 | lcd.locate( 0, 1 ); |
MasudaToshio | 1:ddba0c9b886a | 91 | lcd.printf( "" ); |
MasudaToshio | 1:ddba0c9b886a | 92 | |
MasudaToshio | 1:ddba0c9b886a | 93 | } |
MasudaToshio | 1:ddba0c9b886a | 94 | |
MasudaToshio | 1:ddba0c9b886a | 95 | void test_file_write( char *title, char *path ) { |
MasudaToshio | 1:ddba0c9b886a | 96 | // SD card test |
MasudaToshio | 1:ddba0c9b886a | 97 | lcd.locate( 0, position() ); |
MasudaToshio | 1:ddba0c9b886a | 98 | lcd.printf( "%s: ", title ); |
MasudaToshio | 1:ddba0c9b886a | 99 | |
MasudaToshio | 1:ddba0c9b886a | 100 | FILE *fp = fopen( path, "w" ); |
MasudaToshio | 1:ddba0c9b886a | 101 | if ( fp == NULL ) { |
MasudaToshio | 1:ddba0c9b886a | 102 | lcd.printf( "error" ); |
MasudaToshio | 1:ddba0c9b886a | 103 | error( "Could not open file for write\n" ); |
MasudaToshio | 1:ddba0c9b886a | 104 | } |
MasudaToshio | 1:ddba0c9b886a | 105 | fprintf( fp, "The mbed writing a file through the star board orange (%s)!", title ); |
MasudaToshio | 1:ddba0c9b886a | 106 | fclose( fp ); |
MasudaToshio | 1:ddba0c9b886a | 107 | |
MasudaToshio | 1:ddba0c9b886a | 108 | lcd.printf( "OK." ); |
MasudaToshio | 1:ddba0c9b886a | 109 | } |
MasudaToshio | 1:ddba0c9b886a | 110 | |
MasudaToshio | 1:ddba0c9b886a | 111 | |
MasudaToshio | 1:ddba0c9b886a | 112 | void test_httpserver( void ) { |
MasudaToshio | 1:ddba0c9b886a | 113 | DigitalOut led1( LED1 ); |
MasudaToshio | 1:ddba0c9b886a | 114 | |
MasudaToshio | 1:ddba0c9b886a | 115 | lcd.locate( 0, position() ); |
MasudaToshio | 1:ddba0c9b886a | 116 | lcd.printf( "HTTP srv: " ); |
MasudaToshio | 1:ddba0c9b886a | 117 | |
MasudaToshio | 1:ddba0c9b886a | 118 | Base::add_rpc_class<DigitalOut>(); |
MasudaToshio | 1:ddba0c9b886a | 119 | |
MasudaToshio | 1:ddba0c9b886a | 120 | printf("Setting up...n"); |
MasudaToshio | 1:ddba0c9b886a | 121 | EthernetErr ethErr = eth.setup(); |
MasudaToshio | 1:ddba0c9b886a | 122 | if ( ethErr ) { |
MasudaToshio | 1:ddba0c9b886a | 123 | lcd.printf( "error" ); |
MasudaToshio | 1:ddba0c9b886a | 124 | error( "error @ eth.setup()\n" ); |
MasudaToshio | 1:ddba0c9b886a | 125 | } |
MasudaToshio | 1:ddba0c9b886a | 126 | lcd.printf("OK "); |
MasudaToshio | 1:ddba0c9b886a | 127 | |
MasudaToshio | 1:ddba0c9b886a | 128 | FSHandler::mount("/local", "/"); //Mount /webfs path on web root path |
MasudaToshio | 1:ddba0c9b886a | 129 | FSHandler::mount("/sd", "/sd"); //Mount /webfs path on web sd path |
MasudaToshio | 1:ddba0c9b886a | 130 | FSHandler::mount("/usb", "/usb"); //Mount /webfs path on web usb path |
MasudaToshio | 1:ddba0c9b886a | 131 | |
MasudaToshio | 1:ddba0c9b886a | 132 | svr.addHandler<FSHandler>("/"); //Default handler |
MasudaToshio | 1:ddba0c9b886a | 133 | svr.addHandler<FSHandler>("/sd"); |
MasudaToshio | 1:ddba0c9b886a | 134 | svr.addHandler<FSHandler>("/usb"); |
MasudaToshio | 1:ddba0c9b886a | 135 | //Example : Access to mbed.htm : http://a.b.c.d/mbed.htm or http://a.b.c.d/files/mbed.htm |
MasudaToshio | 1:ddba0c9b886a | 136 | |
MasudaToshio | 1:ddba0c9b886a | 137 | svr.bind(80); |
MasudaToshio | 1:ddba0c9b886a | 138 | |
MasudaToshio | 1:ddba0c9b886a | 139 | lcd.locate( 5, position() -1 ); |
MasudaToshio | 1:ddba0c9b886a | 140 | lcd.printf("Listening"); |
MasudaToshio | 1:ddba0c9b886a | 141 | |
MasudaToshio | 1:ddba0c9b886a | 142 | Timer tm; |
MasudaToshio | 1:ddba0c9b886a | 143 | tm.start(); |
MasudaToshio | 1:ddba0c9b886a | 144 | //Listen indefinitely |
MasudaToshio | 1:ddba0c9b886a | 145 | while (true) { |
MasudaToshio | 1:ddba0c9b886a | 146 | Net::poll(); |
MasudaToshio | 1:ddba0c9b886a | 147 | if (tm.read()>.5) { |
MasudaToshio | 1:ddba0c9b886a | 148 | led1=!led1; //Show that we are alive |
MasudaToshio | 1:ddba0c9b886a | 149 | tm.start(); |
MasudaToshio | 1:ddba0c9b886a | 150 | } |
MasudaToshio | 1:ddba0c9b886a | 151 | } |
MasudaToshio | 1:ddba0c9b886a | 152 | } |
MasudaToshio | 1:ddba0c9b886a | 153 | |
MasudaToshio | 1:ddba0c9b886a | 154 | int position( void ) { |
MasudaToshio | 1:ddba0c9b886a | 155 | static int p = 0; |
MasudaToshio | 1:ddba0c9b886a | 156 | |
MasudaToshio | 1:ddba0c9b886a | 157 | #ifdef USE_TextLCD_20x4 |
MasudaToshio | 1:ddba0c9b886a | 158 | return( ++p % 4 ); |
MasudaToshio | 1:ddba0c9b886a | 159 | #else |
MasudaToshio | 1:ddba0c9b886a | 160 | return( ++p % 2 ); |
MasudaToshio | 1:ddba0c9b886a | 161 | #endif |
MasudaToshio | 1:ddba0c9b886a | 162 | } |