This program is for Star Board Orange. Wave file into SD card is read, and its DAC signal output.
Dependencies: EthernetNetIf mbed HTTPServer
main.cpp
00001 #include "mbed.h" 00002 //#define USE_TextLCD_20x4 00003 #define USE_FIXED_IP 00004 00005 //////////////////////////////////////// 00006 //////// For Waveplayer //////// 00007 //////////////////////////////////////// 00008 //Place suitable uncompressed wav files with 8 or 16 bit sample sizes on the SD card and ensure the 00009 //file names are 8.3 format. Then change the main method below to the relevant file paths. 00010 #include "wavplayer.h" 00011 00012 00013 //////////////////////////////////////// 00014 //////// general setting //////// 00015 //////////////////////////////////////// 00016 //#define USE_TextLCD_20x4 00017 #define USE_FIXED_IP 00018 00019 //////////////////////////////////////// 00020 //////// For TextLCD //////// 00021 //////////////////////////////////////// 00022 #include "TextLCD.h" 00023 #ifdef USE_TextLCD_20x4 00024 //TextLCD lcd( p24, p26, p27, p28, p29, p30, TextLCD::LCD20x4 ); // rs, e, d0-d3 00025 #else 00026 TextLCD lcd( p24, p26, p27, p28, p29, p30 ); // rs, e, d0-d3 00027 #endif 00028 00029 //////////////////////////////////////// 00030 //////// For SD_card //////// 00031 //////////////////////////////////////// 00032 #include "SDHCFileSystem.h" 00033 //SDFileSystem sd(p5, p6, p7, p13, "sd"); // mosi, miso, sclk, cs, name 00034 SDFileSystem sd(p5, p6, p7, p8, "sd"); // mosi, miso, sclk, cs, name (HW modification candidate) 00035 00036 //////////////////////////////////////// 00037 //////// For USB storage //////// 00038 //////////////////////////////////////// 00039 //#include "MSCFileSystem.h" 00040 //MSCFileSystem usb("usb"); 00041 00042 //////////////////////////////////////// 00043 //////// For Ethernet test //////// 00044 //////////////////////////////////////// 00045 #include "EthernetNetIf.h" 00046 #include "HTTPServer.h" 00047 #ifdef USE_FIXED_IP 00048 EthernetNetIf eth( 00049 IpAddr(192,168,0,20), //IP Address 00050 IpAddr(255,255,255,0), //Network Mask 00051 IpAddr(192,168,0,1), //Gateway 00052 IpAddr(192,168,0,1) //DNS 00053 ); 00054 #else 00055 EthernetNetIf eth; 00056 #endif 00057 HTTPServer svr; 00058 LocalFileSystem web("local"); 00059 00060 00061 void test_TextLCD( void ); 00062 void test_file_write( char *title, char *path ); 00063 void test_httpserver( void ); 00064 int position( void ); 00065 00066 DigitalOut led1(LED1); 00067 DigitalOut led4(LED4); 00068 00069 00070 int main() { 00071 WavPlayer myWavPlayer; 00072 led1 = 1 ; 00073 printf("\r\n--------------- Starting -----------------\r\n"); 00074 00075 test_TextLCD(); 00076 wait( 1 ); 00077 test_file_write( "SD card", "/sd/star_bd.txt" ); 00078 wait( 1 ); 00079 //test_file_write( "USB storage", "/usb/star_bd.txt" ); 00080 wait( 1 ); 00081 //test_httpserver(); 00082 myWavPlayer.play_wave("/sd/startup.wav"); // 8 bit sample size 00083 printf("<<<<<<<<<<<<<<<< All done >>>>>>>>>>>>>>>>\r\n"); 00084 led1 = 0; 00085 led4 = 1; 00086 00087 } 00088 00089 00090 void test_TextLCD( void ) { 00091 // TextLCD test 00092 00093 #ifdef USE_TextLCD_20x4 00094 lcd.locate( 0, 0 ); 00095 for ( int i = 0, c = '0'; i < 20; i++, c++ ) 00096 lcd.putc( c ); 00097 00098 for ( int i = 0, c = 'A'; i < 20; i++, c++ ) 00099 lcd.putc( c ); 00100 00101 for ( int i = 0, c = 'a'; i < 20; i++, c++ ) 00102 lcd.putc( c ); 00103 for ( int i = 0, c = '0' - 10; i < 20; i++, c++ ) 00104 lcd.putc( c ); 00105 exit( 0 ); 00106 wait( 300 ); 00107 lcd.cls(); 00108 #endif // USE_TextLCD_20x4 00109 00110 lcd.locate( 0, 0 ); 00111 lcd.printf( "TextLCD: OK?" ); 00112 lcd.locate( 0, 1 ); 00113 lcd.printf( "" ); 00114 00115 } 00116 00117 void test_file_write( char *title, char *path ) { 00118 // SD card test 00119 lcd.locate( 0, position() ); 00120 lcd.printf( "%s: ", title ); 00121 00122 FILE *fp = fopen( path, "w" ); 00123 if ( fp == NULL ) { 00124 lcd.printf( "error" ); 00125 error( "Could not open file for write\n" ); 00126 } 00127 fprintf( fp, "The mbed writing a file through the star board orange (%s)!", title ); 00128 fclose( fp ); 00129 00130 lcd.printf( "OK." ); 00131 } 00132 00133 00134 void test_httpserver( void ) { 00135 DigitalOut led1( LED1 ); 00136 lcd.locate( 0, position() ); 00137 lcd.printf( "HTTP srv: " ); 00138 00139 Base::add_rpc_class<DigitalOut>(); 00140 00141 printf("Setting up...n"); 00142 EthernetErr ethErr = eth.setup(); 00143 if ( ethErr ) { 00144 lcd.printf( "error" ); 00145 error( "error @ eth.setup()\n" ); 00146 } 00147 lcd.printf("OK "); 00148 00149 FSHandler::mount("/local", "/"); //Mount /webfs path on web root path 00150 FSHandler::mount("/sd", "/sd"); //Mount /webfs path on web sd path 00151 //FSHandler::mount("/usb", "/usb"); //Mount /webfs path on web usb path 00152 00153 svr.addHandler<FSHandler>("/"); //Default handler 00154 svr.addHandler<FSHandler>("/sd"); 00155 //svr.addHandler<FSHandler>("/usb"); 00156 //Example : Access to mbed.htm : http://a.b.c.d/mbed.htm or http://a.b.c.d/files/mbed.htm 00157 00158 svr.bind(80); 00159 00160 lcd.locate( 5, position() -1 ); 00161 lcd.printf("Listening"); 00162 00163 Timer tm; 00164 tm.start(); 00165 //Listen indefinitely 00166 while (true) { 00167 Net::poll(); 00168 if (tm.read()>.5) { 00169 led1=!led1; //Show that we are alive 00170 tm.start(); 00171 } 00172 } 00173 } 00174 00175 00176 int position( void ) { 00177 static int p = 0; 00178 00179 #ifdef USE_TextLCD_20x4 00180 return( ++p % 4 ); 00181 #else 00182 return( ++p % 2 ); 00183 #endif 00184 } 00185
Generated on Wed Jul 13 2022 05:13:56 by 1.7.2