This program is for Star Board Orange. Wave file into SD card is read, and its DAC signal output.

Dependencies:   EthernetNetIf mbed HTTPServer

Committer:
y_notsu
Date:
Thu Nov 25 14:59:16 2010 +0000
Revision:
0:383bff20e783

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
y_notsu 0:383bff20e783 1 #include "mbed.h"
y_notsu 0:383bff20e783 2 //#define USE_TextLCD_20x4
y_notsu 0:383bff20e783 3 #define USE_FIXED_IP
y_notsu 0:383bff20e783 4
y_notsu 0:383bff20e783 5 ////////////////////////////////////////
y_notsu 0:383bff20e783 6 //////// For Waveplayer ////////
y_notsu 0:383bff20e783 7 ////////////////////////////////////////
y_notsu 0:383bff20e783 8 //Place suitable uncompressed wav files with 8 or 16 bit sample sizes on the SD card and ensure the
y_notsu 0:383bff20e783 9 //file names are 8.3 format. Then change the main method below to the relevant file paths.
y_notsu 0:383bff20e783 10 #include "wavplayer.h"
y_notsu 0:383bff20e783 11
y_notsu 0:383bff20e783 12
y_notsu 0:383bff20e783 13 ////////////////////////////////////////
y_notsu 0:383bff20e783 14 //////// general setting ////////
y_notsu 0:383bff20e783 15 ////////////////////////////////////////
y_notsu 0:383bff20e783 16 //#define USE_TextLCD_20x4
y_notsu 0:383bff20e783 17 #define USE_FIXED_IP
y_notsu 0:383bff20e783 18
y_notsu 0:383bff20e783 19 ////////////////////////////////////////
y_notsu 0:383bff20e783 20 //////// For TextLCD ////////
y_notsu 0:383bff20e783 21 ////////////////////////////////////////
y_notsu 0:383bff20e783 22 #include "TextLCD.h"
y_notsu 0:383bff20e783 23 #ifdef USE_TextLCD_20x4
y_notsu 0:383bff20e783 24 //TextLCD lcd( p24, p26, p27, p28, p29, p30, TextLCD::LCD20x4 ); // rs, e, d0-d3
y_notsu 0:383bff20e783 25 #else
y_notsu 0:383bff20e783 26 TextLCD lcd( p24, p26, p27, p28, p29, p30 ); // rs, e, d0-d3
y_notsu 0:383bff20e783 27 #endif
y_notsu 0:383bff20e783 28
y_notsu 0:383bff20e783 29 ////////////////////////////////////////
y_notsu 0:383bff20e783 30 //////// For SD_card ////////
y_notsu 0:383bff20e783 31 ////////////////////////////////////////
y_notsu 0:383bff20e783 32 #include "SDHCFileSystem.h"
y_notsu 0:383bff20e783 33 //SDFileSystem sd(p5, p6, p7, p13, "sd"); // mosi, miso, sclk, cs, name
y_notsu 0:383bff20e783 34 SDFileSystem sd(p5, p6, p7, p8, "sd"); // mosi, miso, sclk, cs, name (HW modification candidate)
y_notsu 0:383bff20e783 35
y_notsu 0:383bff20e783 36 ////////////////////////////////////////
y_notsu 0:383bff20e783 37 //////// For USB storage ////////
y_notsu 0:383bff20e783 38 ////////////////////////////////////////
y_notsu 0:383bff20e783 39 //#include "MSCFileSystem.h"
y_notsu 0:383bff20e783 40 //MSCFileSystem usb("usb");
y_notsu 0:383bff20e783 41
y_notsu 0:383bff20e783 42 ////////////////////////////////////////
y_notsu 0:383bff20e783 43 //////// For Ethernet test ////////
y_notsu 0:383bff20e783 44 ////////////////////////////////////////
y_notsu 0:383bff20e783 45 #include "EthernetNetIf.h"
y_notsu 0:383bff20e783 46 #include "HTTPServer.h"
y_notsu 0:383bff20e783 47 #ifdef USE_FIXED_IP
y_notsu 0:383bff20e783 48 EthernetNetIf eth(
y_notsu 0:383bff20e783 49 IpAddr(192,168,0,20), //IP Address
y_notsu 0:383bff20e783 50 IpAddr(255,255,255,0), //Network Mask
y_notsu 0:383bff20e783 51 IpAddr(192,168,0,1), //Gateway
y_notsu 0:383bff20e783 52 IpAddr(192,168,0,1) //DNS
y_notsu 0:383bff20e783 53 );
y_notsu 0:383bff20e783 54 #else
y_notsu 0:383bff20e783 55 EthernetNetIf eth;
y_notsu 0:383bff20e783 56 #endif
y_notsu 0:383bff20e783 57 HTTPServer svr;
y_notsu 0:383bff20e783 58 LocalFileSystem web("local");
y_notsu 0:383bff20e783 59
y_notsu 0:383bff20e783 60
y_notsu 0:383bff20e783 61 void test_TextLCD( void );
y_notsu 0:383bff20e783 62 void test_file_write( char *title, char *path );
y_notsu 0:383bff20e783 63 void test_httpserver( void );
y_notsu 0:383bff20e783 64 int position( void );
y_notsu 0:383bff20e783 65
y_notsu 0:383bff20e783 66 DigitalOut led1(LED1);
y_notsu 0:383bff20e783 67 DigitalOut led4(LED4);
y_notsu 0:383bff20e783 68
y_notsu 0:383bff20e783 69
y_notsu 0:383bff20e783 70 int main() {
y_notsu 0:383bff20e783 71 WavPlayer myWavPlayer;
y_notsu 0:383bff20e783 72 led1 = 1 ;
y_notsu 0:383bff20e783 73 printf("\r\n--------------- Starting -----------------\r\n");
y_notsu 0:383bff20e783 74
y_notsu 0:383bff20e783 75 test_TextLCD();
y_notsu 0:383bff20e783 76 wait( 1 );
y_notsu 0:383bff20e783 77 test_file_write( "SD card", "/sd/star_bd.txt" );
y_notsu 0:383bff20e783 78 wait( 1 );
y_notsu 0:383bff20e783 79 //test_file_write( "USB storage", "/usb/star_bd.txt" );
y_notsu 0:383bff20e783 80 wait( 1 );
y_notsu 0:383bff20e783 81 //test_httpserver();
y_notsu 0:383bff20e783 82 myWavPlayer.play_wave("/sd/startup.wav"); // 8 bit sample size
y_notsu 0:383bff20e783 83 printf("<<<<<<<<<<<<<<<< All done >>>>>>>>>>>>>>>>\r\n");
y_notsu 0:383bff20e783 84 led1 = 0;
y_notsu 0:383bff20e783 85 led4 = 1;
y_notsu 0:383bff20e783 86
y_notsu 0:383bff20e783 87 }
y_notsu 0:383bff20e783 88
y_notsu 0:383bff20e783 89
y_notsu 0:383bff20e783 90 void test_TextLCD( void ) {
y_notsu 0:383bff20e783 91 // TextLCD test
y_notsu 0:383bff20e783 92
y_notsu 0:383bff20e783 93 #ifdef USE_TextLCD_20x4
y_notsu 0:383bff20e783 94 lcd.locate( 0, 0 );
y_notsu 0:383bff20e783 95 for ( int i = 0, c = '0'; i < 20; i++, c++ )
y_notsu 0:383bff20e783 96 lcd.putc( c );
y_notsu 0:383bff20e783 97
y_notsu 0:383bff20e783 98 for ( int i = 0, c = 'A'; i < 20; i++, c++ )
y_notsu 0:383bff20e783 99 lcd.putc( c );
y_notsu 0:383bff20e783 100
y_notsu 0:383bff20e783 101 for ( int i = 0, c = 'a'; i < 20; i++, c++ )
y_notsu 0:383bff20e783 102 lcd.putc( c );
y_notsu 0:383bff20e783 103 for ( int i = 0, c = '0' - 10; i < 20; i++, c++ )
y_notsu 0:383bff20e783 104 lcd.putc( c );
y_notsu 0:383bff20e783 105 exit( 0 );
y_notsu 0:383bff20e783 106 wait( 300 );
y_notsu 0:383bff20e783 107 lcd.cls();
y_notsu 0:383bff20e783 108 #endif // USE_TextLCD_20x4
y_notsu 0:383bff20e783 109
y_notsu 0:383bff20e783 110 lcd.locate( 0, 0 );
y_notsu 0:383bff20e783 111 lcd.printf( "TextLCD: OK?" );
y_notsu 0:383bff20e783 112 lcd.locate( 0, 1 );
y_notsu 0:383bff20e783 113 lcd.printf( "" );
y_notsu 0:383bff20e783 114
y_notsu 0:383bff20e783 115 }
y_notsu 0:383bff20e783 116
y_notsu 0:383bff20e783 117 void test_file_write( char *title, char *path ) {
y_notsu 0:383bff20e783 118 // SD card test
y_notsu 0:383bff20e783 119 lcd.locate( 0, position() );
y_notsu 0:383bff20e783 120 lcd.printf( "%s: ", title );
y_notsu 0:383bff20e783 121
y_notsu 0:383bff20e783 122 FILE *fp = fopen( path, "w" );
y_notsu 0:383bff20e783 123 if ( fp == NULL ) {
y_notsu 0:383bff20e783 124 lcd.printf( "error" );
y_notsu 0:383bff20e783 125 error( "Could not open file for write\n" );
y_notsu 0:383bff20e783 126 }
y_notsu 0:383bff20e783 127 fprintf( fp, "The mbed writing a file through the star board orange (%s)!", title );
y_notsu 0:383bff20e783 128 fclose( fp );
y_notsu 0:383bff20e783 129
y_notsu 0:383bff20e783 130 lcd.printf( "OK." );
y_notsu 0:383bff20e783 131 }
y_notsu 0:383bff20e783 132
y_notsu 0:383bff20e783 133
y_notsu 0:383bff20e783 134 void test_httpserver( void ) {
y_notsu 0:383bff20e783 135 DigitalOut led1( LED1 );
y_notsu 0:383bff20e783 136 lcd.locate( 0, position() );
y_notsu 0:383bff20e783 137 lcd.printf( "HTTP srv: " );
y_notsu 0:383bff20e783 138
y_notsu 0:383bff20e783 139 Base::add_rpc_class<DigitalOut>();
y_notsu 0:383bff20e783 140
y_notsu 0:383bff20e783 141 printf("Setting up...n");
y_notsu 0:383bff20e783 142 EthernetErr ethErr = eth.setup();
y_notsu 0:383bff20e783 143 if ( ethErr ) {
y_notsu 0:383bff20e783 144 lcd.printf( "error" );
y_notsu 0:383bff20e783 145 error( "error @ eth.setup()\n" );
y_notsu 0:383bff20e783 146 }
y_notsu 0:383bff20e783 147 lcd.printf("OK ");
y_notsu 0:383bff20e783 148
y_notsu 0:383bff20e783 149 FSHandler::mount("/local", "/"); //Mount /webfs path on web root path
y_notsu 0:383bff20e783 150 FSHandler::mount("/sd", "/sd"); //Mount /webfs path on web sd path
y_notsu 0:383bff20e783 151 //FSHandler::mount("/usb", "/usb"); //Mount /webfs path on web usb path
y_notsu 0:383bff20e783 152
y_notsu 0:383bff20e783 153 svr.addHandler<FSHandler>("/"); //Default handler
y_notsu 0:383bff20e783 154 svr.addHandler<FSHandler>("/sd");
y_notsu 0:383bff20e783 155 //svr.addHandler<FSHandler>("/usb");
y_notsu 0:383bff20e783 156 //Example : Access to mbed.htm : http://a.b.c.d/mbed.htm or http://a.b.c.d/files/mbed.htm
y_notsu 0:383bff20e783 157
y_notsu 0:383bff20e783 158 svr.bind(80);
y_notsu 0:383bff20e783 159
y_notsu 0:383bff20e783 160 lcd.locate( 5, position() -1 );
y_notsu 0:383bff20e783 161 lcd.printf("Listening");
y_notsu 0:383bff20e783 162
y_notsu 0:383bff20e783 163 Timer tm;
y_notsu 0:383bff20e783 164 tm.start();
y_notsu 0:383bff20e783 165 //Listen indefinitely
y_notsu 0:383bff20e783 166 while (true) {
y_notsu 0:383bff20e783 167 Net::poll();
y_notsu 0:383bff20e783 168 if (tm.read()>.5) {
y_notsu 0:383bff20e783 169 led1=!led1; //Show that we are alive
y_notsu 0:383bff20e783 170 tm.start();
y_notsu 0:383bff20e783 171 }
y_notsu 0:383bff20e783 172 }
y_notsu 0:383bff20e783 173 }
y_notsu 0:383bff20e783 174
y_notsu 0:383bff20e783 175
y_notsu 0:383bff20e783 176 int position( void ) {
y_notsu 0:383bff20e783 177 static int p = 0;
y_notsu 0:383bff20e783 178
y_notsu 0:383bff20e783 179 #ifdef USE_TextLCD_20x4
y_notsu 0:383bff20e783 180 return( ++p % 4 );
y_notsu 0:383bff20e783 181 #else
y_notsu 0:383bff20e783 182 return( ++p % 2 );
y_notsu 0:383bff20e783 183 #endif
y_notsu 0:383bff20e783 184 }
y_notsu 0:383bff20e783 185