Talk Watch system using NTP timer for JBB.
Dependencies: EthernetNetIf FatFileSystem HTTPClient_ToBeRemoved HTTPServer NTPClient_NetServices TextLCD mbed
Fork of StarBoardOrangeTest3 by
main.cpp@1:8816ea8be54b, 2014-06-22 (annotated)
- Committer:
- y_notsu
- Date:
- Sun Jun 22 05:12:34 2014 +0000
- Revision:
- 1:8816ea8be54b
- Parent:
- 0:ae31fe6f181c
Talk Watch using NTP client for JBB
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
y_notsu | 0:ae31fe6f181c | 1 | #include "mbed.h" |
y_notsu | 0:ae31fe6f181c | 2 | //#define USE_TextLCD_20x4 |
y_notsu | 0:ae31fe6f181c | 3 | #define USE_FIXED_IP |
y_notsu | 0:ae31fe6f181c | 4 | |
y_notsu | 0:ae31fe6f181c | 5 | //////////////////////////////////////// |
y_notsu | 0:ae31fe6f181c | 6 | //////// For Waveplayer //////// |
y_notsu | 0:ae31fe6f181c | 7 | //////////////////////////////////////// |
y_notsu | 0:ae31fe6f181c | 8 | //Place suitable uncompressed wav files with 8 or 16 bit sample sizes on the SD card and ensure the |
y_notsu | 0:ae31fe6f181c | 9 | //file names are 8.3 format. Then change the main method below to the relevant file paths. |
y_notsu | 0:ae31fe6f181c | 10 | #include "wavplayer.h" |
y_notsu | 0:ae31fe6f181c | 11 | |
y_notsu | 0:ae31fe6f181c | 12 | |
y_notsu | 0:ae31fe6f181c | 13 | //////////////////////////////////////// |
y_notsu | 0:ae31fe6f181c | 14 | //////// general setting //////// |
y_notsu | 0:ae31fe6f181c | 15 | //////////////////////////////////////// |
y_notsu | 0:ae31fe6f181c | 16 | //#define USE_TextLCD_20x4 |
y_notsu | 0:ae31fe6f181c | 17 | #define USE_FIXED_IP |
y_notsu | 0:ae31fe6f181c | 18 | |
y_notsu | 0:ae31fe6f181c | 19 | //////////////////////////////////////// |
y_notsu | 0:ae31fe6f181c | 20 | //////// For TextLCD //////// |
y_notsu | 0:ae31fe6f181c | 21 | //////////////////////////////////////// |
y_notsu | 0:ae31fe6f181c | 22 | #include "TextLCD.h" |
y_notsu | 0:ae31fe6f181c | 23 | #ifdef USE_TextLCD_20x4 |
y_notsu | 0:ae31fe6f181c | 24 | //TextLCD lcd( p24, p26, p27, p28, p29, p30, TextLCD::LCD20x4 ); // rs, e, d0-d3 |
y_notsu | 0:ae31fe6f181c | 25 | #else |
y_notsu | 0:ae31fe6f181c | 26 | TextLCD lcd( p24, p26, p27, p28, p29, p30 ); // rs, e, d0-d3 |
y_notsu | 0:ae31fe6f181c | 27 | #endif |
y_notsu | 0:ae31fe6f181c | 28 | |
y_notsu | 0:ae31fe6f181c | 29 | //////////////////////////////////////// |
y_notsu | 0:ae31fe6f181c | 30 | //////// For SD_card //////// |
y_notsu | 0:ae31fe6f181c | 31 | //////////////////////////////////////// |
y_notsu | 0:ae31fe6f181c | 32 | #include "SDHCFileSystem.h" |
y_notsu | 0:ae31fe6f181c | 33 | //SDFileSystem sd(p5, p6, p7, p13, "sd"); // mosi, miso, sclk, cs, name |
y_notsu | 0:ae31fe6f181c | 34 | SDFileSystem sd(p5, p6, p7, p8, "sd"); // mosi, miso, sclk, cs, name (HW modification candidate) |
y_notsu | 0:ae31fe6f181c | 35 | |
y_notsu | 0:ae31fe6f181c | 36 | //////////////////////////////////////// |
y_notsu | 0:ae31fe6f181c | 37 | //////// For USB storage //////// |
y_notsu | 0:ae31fe6f181c | 38 | //////////////////////////////////////// |
y_notsu | 0:ae31fe6f181c | 39 | //#include "MSCFileSystem.h" |
y_notsu | 0:ae31fe6f181c | 40 | //MSCFileSystem usb("usb"); |
y_notsu | 0:ae31fe6f181c | 41 | |
y_notsu | 0:ae31fe6f181c | 42 | //////////////////////////////////////// |
y_notsu | 0:ae31fe6f181c | 43 | //////// For Ethernet test //////// |
y_notsu | 0:ae31fe6f181c | 44 | //////////////////////////////////////// |
y_notsu | 0:ae31fe6f181c | 45 | #include "EthernetNetIf.h" |
y_notsu | 0:ae31fe6f181c | 46 | //#include "HTTPServer.h" |
y_notsu | 0:ae31fe6f181c | 47 | //#ifdef USE_FIXED_IP |
y_notsu | 0:ae31fe6f181c | 48 | //EthernetNetIf eth( |
y_notsu | 0:ae31fe6f181c | 49 | // IpAddr(192,168,0,20), //IP Address |
y_notsu | 0:ae31fe6f181c | 50 | // IpAddr(255,255,255,0), //Network Mask |
y_notsu | 0:ae31fe6f181c | 51 | // IpAddr(192,168,0,1), //Gateway |
y_notsu | 0:ae31fe6f181c | 52 | // IpAddr(192,168,0,1) //DNS |
y_notsu | 0:ae31fe6f181c | 53 | //); |
y_notsu | 0:ae31fe6f181c | 54 | //#else |
y_notsu | 0:ae31fe6f181c | 55 | EthernetNetIf eth; |
y_notsu | 0:ae31fe6f181c | 56 | //#endif |
y_notsu | 0:ae31fe6f181c | 57 | //HTTPServer svr; |
y_notsu | 0:ae31fe6f181c | 58 | //#include "HTTPClient.h" |
y_notsu | 0:ae31fe6f181c | 59 | #include "NTPClient.h" |
y_notsu | 0:ae31fe6f181c | 60 | NTPClient ntp; |
y_notsu | 0:ae31fe6f181c | 61 | const char ntp_server[] = "0.uk.pool.ntp.org"; |
y_notsu | 0:ae31fe6f181c | 62 | |
y_notsu | 0:ae31fe6f181c | 63 | LocalFileSystem web("local"); |
y_notsu | 0:ae31fe6f181c | 64 | |
y_notsu | 0:ae31fe6f181c | 65 | |
y_notsu | 0:ae31fe6f181c | 66 | |
y_notsu | 0:ae31fe6f181c | 67 | |
y_notsu | 0:ae31fe6f181c | 68 | void test_file_write( char *title, char *path ); |
y_notsu | 0:ae31fe6f181c | 69 | //void test_httpserver( void ); |
y_notsu | 0:ae31fe6f181c | 70 | int position( void ); |
y_notsu | 0:ae31fe6f181c | 71 | |
y_notsu | 0:ae31fe6f181c | 72 | DigitalOut led1(LED1); |
y_notsu | 0:ae31fe6f181c | 73 | DigitalOut led4(LED4); |
y_notsu | 0:ae31fe6f181c | 74 | |
y_notsu | 1:8816ea8be54b | 75 | DigitalIn SW1(p25); |
y_notsu | 1:8816ea8be54b | 76 | DigitalIn SW2(p26); |
y_notsu | 1:8816ea8be54b | 77 | int TGSW=1; |
y_notsu | 0:ae31fe6f181c | 78 | DigitalIn SW3(p14); |
y_notsu | 1:8816ea8be54b | 79 | DigitalOut AMPEnable(p12); //0:Off, 1:On |
y_notsu | 1:8816ea8be54b | 80 | Serial pc(USBTX, USBRX); // tx, rx |
y_notsu | 0:ae31fe6f181c | 81 | |
y_notsu | 0:ae31fe6f181c | 82 | int playflg; |
y_notsu | 0:ae31fe6f181c | 83 | int playflg2; |
y_notsu | 0:ae31fe6f181c | 84 | int timest; |
y_notsu | 0:ae31fe6f181c | 85 | |
y_notsu | 0:ae31fe6f181c | 86 | char *wavefilename1; |
y_notsu | 0:ae31fe6f181c | 87 | char *wavefilename2; |
y_notsu | 0:ae31fe6f181c | 88 | char *wavefilename3; |
y_notsu | 0:ae31fe6f181c | 89 | char *wavefilename4; |
y_notsu | 0:ae31fe6f181c | 90 | |
y_notsu | 0:ae31fe6f181c | 91 | Ticker rt; |
y_notsu | 0:ae31fe6f181c | 92 | char buf[40]; |
y_notsu | 0:ae31fe6f181c | 93 | time_t ctTime; |
y_notsu | 0:ae31fe6f181c | 94 | |
y_notsu | 0:ae31fe6f181c | 95 | void timecall() |
y_notsu | 0:ae31fe6f181c | 96 | { |
y_notsu | 0:ae31fe6f181c | 97 | if(TGSW==1)ctTime = time(NULL)+32400;//JST time |
y_notsu | 0:ae31fe6f181c | 98 | else ctTime = time(NULL); |
y_notsu | 0:ae31fe6f181c | 99 | strftime(buf,sizeof(buf), " (%Y/%m/%d %a %p %I:%M:%S)", localtime(&ctTime)); |
y_notsu | 0:ae31fe6f181c | 100 | lcd.cls(); |
y_notsu | 0:ae31fe6f181c | 101 | lcd.printf("%s",buf); |
y_notsu | 0:ae31fe6f181c | 102 | } |
y_notsu | 0:ae31fe6f181c | 103 | |
y_notsu | 0:ae31fe6f181c | 104 | |
y_notsu | 0:ae31fe6f181c | 105 | int main() { |
y_notsu | 0:ae31fe6f181c | 106 | WavPlayer myWavPlayer; |
y_notsu | 1:8816ea8be54b | 107 | SW1.mode(PullUp); |
y_notsu | 1:8816ea8be54b | 108 | SW2.mode(PullUp); |
y_notsu | 0:ae31fe6f181c | 109 | led1 = 1 ; |
y_notsu | 0:ae31fe6f181c | 110 | playflg = 0; |
y_notsu | 0:ae31fe6f181c | 111 | playflg2 = 0; |
y_notsu | 1:8816ea8be54b | 112 | pc.printf("\r\n--------------- Starting -----------------\r\n"); |
y_notsu | 0:ae31fe6f181c | 113 | lcd.printf("----Starting----"); |
y_notsu | 0:ae31fe6f181c | 114 | lcd.locate(0,1); |
y_notsu | 0:ae31fe6f181c | 115 | wait(3); |
y_notsu | 0:ae31fe6f181c | 116 | test_file_write( "SD card", "/sd/star_bd.txt" ); |
y_notsu | 0:ae31fe6f181c | 117 | wait(2); |
y_notsu | 0:ae31fe6f181c | 118 | //test_file_write( "USB storage", "/usb/star_bd.txt" ); |
y_notsu | 0:ae31fe6f181c | 119 | //wait( 2 ); |
y_notsu | 1:8816ea8be54b | 120 | AMPEnable=0; |
y_notsu | 0:ae31fe6f181c | 121 | myWavPlayer.play_wave("/sd/startup.wav"); |
y_notsu | 0:ae31fe6f181c | 122 | wait(0.5); |
y_notsu | 0:ae31fe6f181c | 123 | myWavPlayer.play_wave("/sd/startup2.wav"); |
y_notsu | 0:ae31fe6f181c | 124 | lcd.cls(); |
y_notsu | 1:8816ea8be54b | 125 | AMPEnable=0; |
y_notsu | 1:8816ea8be54b | 126 | pc.printf("\r\nSetting up...\r\n"); |
y_notsu | 0:ae31fe6f181c | 127 | |
y_notsu | 0:ae31fe6f181c | 128 | lcd.printf("Setting up...\n"); |
y_notsu | 0:ae31fe6f181c | 129 | if(TGSW==1) |
y_notsu | 0:ae31fe6f181c | 130 | { |
y_notsu | 0:ae31fe6f181c | 131 | EthernetErr ethErr = eth.setup(); |
y_notsu | 0:ae31fe6f181c | 132 | if (ethErr) { |
y_notsu | 1:8816ea8be54b | 133 | pc.printf("Error %d in setup.\n", ethErr); |
y_notsu | 0:ae31fe6f181c | 134 | lcd.printf("Error %d in setup.\n", ethErr); |
y_notsu | 0:ae31fe6f181c | 135 | return -1; |
y_notsu | 0:ae31fe6f181c | 136 | } |
y_notsu | 0:ae31fe6f181c | 137 | } |
y_notsu | 0:ae31fe6f181c | 138 | lcd.locate(0,1); |
y_notsu | 1:8816ea8be54b | 139 | pc.printf("\r\nSetup OK\r\n"); |
y_notsu | 0:ae31fe6f181c | 140 | wait(1); |
y_notsu | 0:ae31fe6f181c | 141 | //test_httpserver(); |
y_notsu | 0:ae31fe6f181c | 142 | |
y_notsu | 0:ae31fe6f181c | 143 | //RTC setup |
y_notsu | 0:ae31fe6f181c | 144 | Host server(IpAddr(), 123, ntp_server); |
y_notsu | 0:ae31fe6f181c | 145 | ntp.setTime(server); |
y_notsu | 0:ae31fe6f181c | 146 | timest=1; |
y_notsu | 1:8816ea8be54b | 147 | |
y_notsu | 0:ae31fe6f181c | 148 | lcd.cls(); |
y_notsu | 0:ae31fe6f181c | 149 | lcd.printf("Time Set End"); |
y_notsu | 0:ae31fe6f181c | 150 | wait(1); |
y_notsu | 0:ae31fe6f181c | 151 | |
y_notsu | 0:ae31fe6f181c | 152 | // rt.attach_us(&timecall,300.0); |
y_notsu | 0:ae31fe6f181c | 153 | |
y_notsu | 0:ae31fe6f181c | 154 | while(1) |
y_notsu | 0:ae31fe6f181c | 155 | { |
y_notsu | 0:ae31fe6f181c | 156 | lcd.cls(); |
y_notsu | 1:8816ea8be54b | 157 | ctTime = time(NULL)+32400;//JST time |
y_notsu | 0:ae31fe6f181c | 158 | strftime(buf,sizeof(buf), " (%Y/%m/%d %a %p %I:%M:%S)", localtime(&ctTime)); |
y_notsu | 0:ae31fe6f181c | 159 | lcd.printf("%s",buf); |
y_notsu | 0:ae31fe6f181c | 160 | |
y_notsu | 0:ae31fe6f181c | 161 | //wait(0.5); |
y_notsu | 0:ae31fe6f181c | 162 | |
y_notsu | 1:8816ea8be54b | 163 | if(SW1==0) |
y_notsu | 0:ae31fe6f181c | 164 | { |
y_notsu | 0:ae31fe6f181c | 165 | if(buf[20]=='1') |
y_notsu | 0:ae31fe6f181c | 166 | { |
y_notsu | 0:ae31fe6f181c | 167 | if(buf[21]=='0') wavefilename1 = "/sd/10ji.wav"; |
y_notsu | 0:ae31fe6f181c | 168 | else if(buf[21]=='1') wavefilename1 = "/sd/11ji.wav"; |
y_notsu | 0:ae31fe6f181c | 169 | else if(buf[21]=='2') wavefilename1 = "/sd/12ji.wav"; |
y_notsu | 0:ae31fe6f181c | 170 | else wavefilename1 = "/sd/jikanga.wav"; |
y_notsu | 0:ae31fe6f181c | 171 | } |
y_notsu | 0:ae31fe6f181c | 172 | else |
y_notsu | 0:ae31fe6f181c | 173 | { |
y_notsu | 0:ae31fe6f181c | 174 | if(buf[20]=='0') |
y_notsu | 0:ae31fe6f181c | 175 | { |
y_notsu | 0:ae31fe6f181c | 176 | if(buf[21]=='1') wavefilename1 = "/sd/1ji.wav"; |
y_notsu | 0:ae31fe6f181c | 177 | if(buf[21]=='2') wavefilename1 = "/sd/2ji.wav"; |
y_notsu | 0:ae31fe6f181c | 178 | if(buf[21]=='3') wavefilename1 = "/sd/3ji.wav"; |
y_notsu | 0:ae31fe6f181c | 179 | if(buf[21]=='4') wavefilename1 = "/sd/4ji.wav"; |
y_notsu | 0:ae31fe6f181c | 180 | if(buf[21]=='5') wavefilename1 = "/sd/5ji.wav"; |
y_notsu | 0:ae31fe6f181c | 181 | if(buf[21]=='6') wavefilename1 = "/sd/6ji.wav"; |
y_notsu | 0:ae31fe6f181c | 182 | if(buf[21]=='7') wavefilename1 = "/sd/7ji.wav"; |
y_notsu | 0:ae31fe6f181c | 183 | if(buf[21]=='8') wavefilename1 = "/sd/8ji.wav"; |
y_notsu | 0:ae31fe6f181c | 184 | if(buf[21]=='9') wavefilename1 = "/sd/9ji.wav"; |
y_notsu | 0:ae31fe6f181c | 185 | } |
y_notsu | 0:ae31fe6f181c | 186 | else |
y_notsu | 0:ae31fe6f181c | 187 | { |
y_notsu | 0:ae31fe6f181c | 188 | wavefilename1 = "/sd/jikanga.wav"; |
y_notsu | 0:ae31fe6f181c | 189 | } |
y_notsu | 0:ae31fe6f181c | 190 | } |
y_notsu | 0:ae31fe6f181c | 191 | |
y_notsu | 0:ae31fe6f181c | 192 | if(buf[23]=='0') |
y_notsu | 0:ae31fe6f181c | 193 | { |
y_notsu | 0:ae31fe6f181c | 194 | wavefilename3 = "/sd/desu.wav"; |
y_notsu | 0:ae31fe6f181c | 195 | if(buf[24]=='0') wavefilename2 = "/sd/just.wav"; |
y_notsu | 0:ae31fe6f181c | 196 | else if(buf[24]=='1') wavefilename2 = "/sd/1min.wav"; |
y_notsu | 0:ae31fe6f181c | 197 | else if(buf[24]=='2') wavefilename2 = "/sd/2min.wav"; |
y_notsu | 0:ae31fe6f181c | 198 | else if(buf[24]=='3') wavefilename2 = "/sd/3min.wav"; |
y_notsu | 0:ae31fe6f181c | 199 | else if(buf[24]=='4') wavefilename2 = "/sd/4min.wav"; |
y_notsu | 0:ae31fe6f181c | 200 | else if(buf[24]=='5') wavefilename2 = "/sd/5min.wav"; |
y_notsu | 0:ae31fe6f181c | 201 | else if(buf[24]=='6') wavefilename2 = "/sd/6min.wav"; |
y_notsu | 0:ae31fe6f181c | 202 | else if(buf[24]=='7') wavefilename2 = "/sd/7min.wav"; |
y_notsu | 0:ae31fe6f181c | 203 | else if(buf[24]=='8') wavefilename2 = "/sd/8min.wav"; |
y_notsu | 0:ae31fe6f181c | 204 | else if(buf[24]=='9') wavefilename2 = "/sd/9min.wav"; |
y_notsu | 0:ae31fe6f181c | 205 | else wavefilename2 = "/sd/oksi.wav"; |
y_notsu | 0:ae31fe6f181c | 206 | } |
y_notsu | 0:ae31fe6f181c | 207 | else if(buf[23]=='1') |
y_notsu | 0:ae31fe6f181c | 208 | { |
y_notsu | 0:ae31fe6f181c | 209 | if(buf[24]=='0'){ |
y_notsu | 0:ae31fe6f181c | 210 | wavefilename2 = "/sd/10min.wav"; |
y_notsu | 0:ae31fe6f181c | 211 | wavefilename3 = "/sd/desu.wav"; |
y_notsu | 0:ae31fe6f181c | 212 | } |
y_notsu | 0:ae31fe6f181c | 213 | else{ |
y_notsu | 0:ae31fe6f181c | 214 | wavefilename2 = "/sd/10.wav"; |
y_notsu | 0:ae31fe6f181c | 215 | playflg2=1; |
y_notsu | 0:ae31fe6f181c | 216 | wavefilename4 = "/sd/desu.wav"; |
y_notsu | 0:ae31fe6f181c | 217 | } |
y_notsu | 0:ae31fe6f181c | 218 | } |
y_notsu | 0:ae31fe6f181c | 219 | else if(buf[23]=='2') |
y_notsu | 0:ae31fe6f181c | 220 | { |
y_notsu | 0:ae31fe6f181c | 221 | if(buf[24]=='0'){ |
y_notsu | 0:ae31fe6f181c | 222 | wavefilename2 = "/sd/20min.wav"; |
y_notsu | 0:ae31fe6f181c | 223 | wavefilename3 = "/sd/desu.wav"; |
y_notsu | 0:ae31fe6f181c | 224 | } |
y_notsu | 0:ae31fe6f181c | 225 | else{ |
y_notsu | 0:ae31fe6f181c | 226 | wavefilename2 = "/sd/20.wav"; |
y_notsu | 0:ae31fe6f181c | 227 | playflg2=1; |
y_notsu | 0:ae31fe6f181c | 228 | wavefilename4 = "/sd/desu.wav"; |
y_notsu | 0:ae31fe6f181c | 229 | } |
y_notsu | 0:ae31fe6f181c | 230 | } |
y_notsu | 0:ae31fe6f181c | 231 | else if(buf[23]=='3') |
y_notsu | 0:ae31fe6f181c | 232 | { |
y_notsu | 0:ae31fe6f181c | 233 | if(buf[24]=='0'){ |
y_notsu | 0:ae31fe6f181c | 234 | wavefilename2 = "/sd/30min.wav"; |
y_notsu | 0:ae31fe6f181c | 235 | wavefilename3 = "/sd/desu.wav"; |
y_notsu | 0:ae31fe6f181c | 236 | } |
y_notsu | 0:ae31fe6f181c | 237 | else{ |
y_notsu | 0:ae31fe6f181c | 238 | wavefilename2 = "/sd/30.wav"; |
y_notsu | 0:ae31fe6f181c | 239 | playflg2=1; |
y_notsu | 0:ae31fe6f181c | 240 | wavefilename4 = "/sd/desu.wav"; |
y_notsu | 0:ae31fe6f181c | 241 | } |
y_notsu | 0:ae31fe6f181c | 242 | } |
y_notsu | 0:ae31fe6f181c | 243 | else if(buf[23]=='4') |
y_notsu | 0:ae31fe6f181c | 244 | { |
y_notsu | 0:ae31fe6f181c | 245 | if(buf[24]=='0'){ |
y_notsu | 0:ae31fe6f181c | 246 | wavefilename2 = "/sd/40min.wav"; |
y_notsu | 0:ae31fe6f181c | 247 | wavefilename3 = "/sd/desu.wav"; |
y_notsu | 0:ae31fe6f181c | 248 | } |
y_notsu | 0:ae31fe6f181c | 249 | else{ |
y_notsu | 0:ae31fe6f181c | 250 | wavefilename2 = "/sd/40.wav"; |
y_notsu | 0:ae31fe6f181c | 251 | playflg2=1; |
y_notsu | 0:ae31fe6f181c | 252 | wavefilename4 = "/sd/desu.wav"; |
y_notsu | 0:ae31fe6f181c | 253 | } |
y_notsu | 0:ae31fe6f181c | 254 | } |
y_notsu | 0:ae31fe6f181c | 255 | else if(buf[23]=='5') |
y_notsu | 0:ae31fe6f181c | 256 | { |
y_notsu | 0:ae31fe6f181c | 257 | if(buf[24]=='0'){ |
y_notsu | 0:ae31fe6f181c | 258 | wavefilename2 = "/sd/50min.wav"; |
y_notsu | 0:ae31fe6f181c | 259 | wavefilename3 = "/sd/desu.wav"; |
y_notsu | 0:ae31fe6f181c | 260 | } |
y_notsu | 0:ae31fe6f181c | 261 | else{ |
y_notsu | 0:ae31fe6f181c | 262 | wavefilename2 = "/sd/50.wav"; |
y_notsu | 0:ae31fe6f181c | 263 | playflg2=1; |
y_notsu | 0:ae31fe6f181c | 264 | wavefilename4 = "/sd/desu.wav"; |
y_notsu | 0:ae31fe6f181c | 265 | } |
y_notsu | 0:ae31fe6f181c | 266 | } |
y_notsu | 0:ae31fe6f181c | 267 | else |
y_notsu | 0:ae31fe6f181c | 268 | { |
y_notsu | 0:ae31fe6f181c | 269 | wavefilename2 = "/sd/okasi.wav"; |
y_notsu | 0:ae31fe6f181c | 270 | wavefilename3 = "/sd/desu.wav"; |
y_notsu | 0:ae31fe6f181c | 271 | } |
y_notsu | 0:ae31fe6f181c | 272 | |
y_notsu | 0:ae31fe6f181c | 273 | if(playflg2==1) |
y_notsu | 0:ae31fe6f181c | 274 | { |
y_notsu | 0:ae31fe6f181c | 275 | if(buf[24]=='1') wavefilename3 = "/sd/1min.wav"; |
y_notsu | 0:ae31fe6f181c | 276 | else if(buf[24]=='2') wavefilename3 = "/sd/2min.wav"; |
y_notsu | 0:ae31fe6f181c | 277 | else if(buf[24]=='3') wavefilename3 = "/sd/3min.wav"; |
y_notsu | 0:ae31fe6f181c | 278 | else if(buf[24]=='4') wavefilename3 = "/sd/4min.wav"; |
y_notsu | 0:ae31fe6f181c | 279 | else if(buf[24]=='5') wavefilename3 = "/sd/5min.wav"; |
y_notsu | 0:ae31fe6f181c | 280 | else if(buf[24]=='6') wavefilename3 = "/sd/6min.wav"; |
y_notsu | 0:ae31fe6f181c | 281 | else if(buf[24]=='7') wavefilename3 = "/sd/7min.wav"; |
y_notsu | 0:ae31fe6f181c | 282 | else if(buf[24]=='8') wavefilename3 = "/sd/8min.wav"; |
y_notsu | 0:ae31fe6f181c | 283 | else if(buf[24]=='9') wavefilename3 = "/sd/9min.wav"; |
y_notsu | 0:ae31fe6f181c | 284 | } |
y_notsu | 0:ae31fe6f181c | 285 | |
y_notsu | 0:ae31fe6f181c | 286 | playflg=1; |
y_notsu | 0:ae31fe6f181c | 287 | } |
y_notsu | 0:ae31fe6f181c | 288 | |
y_notsu | 0:ae31fe6f181c | 289 | |
y_notsu | 0:ae31fe6f181c | 290 | if(playflg==1) |
y_notsu | 0:ae31fe6f181c | 291 | { |
y_notsu | 0:ae31fe6f181c | 292 | lcd.cls(); |
y_notsu | 0:ae31fe6f181c | 293 | lcd.printf("%s", buf); |
y_notsu | 1:8816ea8be54b | 294 | AMPEnable=0; |
y_notsu | 0:ae31fe6f181c | 295 | myWavPlayer.play_wave(wavefilename1); // 8 bit sample size |
y_notsu | 0:ae31fe6f181c | 296 | myWavPlayer.play_wave(wavefilename2); |
y_notsu | 0:ae31fe6f181c | 297 | myWavPlayer.play_wave(wavefilename3); |
y_notsu | 0:ae31fe6f181c | 298 | if(playflg2==1) |
y_notsu | 0:ae31fe6f181c | 299 | { |
y_notsu | 0:ae31fe6f181c | 300 | myWavPlayer.play_wave(wavefilename4); |
y_notsu | 0:ae31fe6f181c | 301 | } |
y_notsu | 1:8816ea8be54b | 302 | AMPEnable=1; |
y_notsu | 0:ae31fe6f181c | 303 | led1 = 0; |
y_notsu | 0:ae31fe6f181c | 304 | led4 = 1; |
y_notsu | 0:ae31fe6f181c | 305 | } |
y_notsu | 1:8816ea8be54b | 306 | if(SW2==0) |
y_notsu | 0:ae31fe6f181c | 307 | { |
y_notsu | 1:8816ea8be54b | 308 | AMPEnable=0; |
y_notsu | 0:ae31fe6f181c | 309 | myWavPlayer.play_wave("/sd/doubler.wav"); |
y_notsu | 1:8816ea8be54b | 310 | AMPEnable=0; |
y_notsu | 0:ae31fe6f181c | 311 | } |
y_notsu | 0:ae31fe6f181c | 312 | |
y_notsu | 0:ae31fe6f181c | 313 | wait(0.2); |
y_notsu | 0:ae31fe6f181c | 314 | led4 = 0; |
y_notsu | 0:ae31fe6f181c | 315 | led1 = 1; |
y_notsu | 0:ae31fe6f181c | 316 | playflg =0; |
y_notsu | 0:ae31fe6f181c | 317 | playflg2=0; |
y_notsu | 1:8816ea8be54b | 318 | |
y_notsu | 0:ae31fe6f181c | 319 | } |
y_notsu | 1:8816ea8be54b | 320 | |
y_notsu | 0:ae31fe6f181c | 321 | } |
y_notsu | 0:ae31fe6f181c | 322 | |
y_notsu | 0:ae31fe6f181c | 323 | |
y_notsu | 0:ae31fe6f181c | 324 | void test_file_write( char *title, char *path ) { |
y_notsu | 0:ae31fe6f181c | 325 | // SD card test |
y_notsu | 0:ae31fe6f181c | 326 | lcd.locate( 0, position() ); |
y_notsu | 0:ae31fe6f181c | 327 | lcd.printf( "%s: ", title ); |
y_notsu | 0:ae31fe6f181c | 328 | |
y_notsu | 0:ae31fe6f181c | 329 | FILE *fp = fopen( path, "w" ); |
y_notsu | 0:ae31fe6f181c | 330 | if ( fp == NULL ) { |
y_notsu | 0:ae31fe6f181c | 331 | lcd.printf( "error" ); |
y_notsu | 0:ae31fe6f181c | 332 | error( "Could not open file for write\n" ); |
y_notsu | 0:ae31fe6f181c | 333 | } |
y_notsu | 0:ae31fe6f181c | 334 | fprintf( fp, "The mbed writing a file through the star board orange (%s)!", title ); |
y_notsu | 0:ae31fe6f181c | 335 | fclose( fp ); |
y_notsu | 0:ae31fe6f181c | 336 | |
y_notsu | 0:ae31fe6f181c | 337 | lcd.printf( "OK." ); |
y_notsu | 0:ae31fe6f181c | 338 | } |
y_notsu | 0:ae31fe6f181c | 339 | |
y_notsu | 0:ae31fe6f181c | 340 | |
y_notsu | 0:ae31fe6f181c | 341 | int position( void ) { |
y_notsu | 0:ae31fe6f181c | 342 | static int p = 0; |
y_notsu | 0:ae31fe6f181c | 343 | |
y_notsu | 0:ae31fe6f181c | 344 | #ifdef USE_TextLCD_20x4 |
y_notsu | 0:ae31fe6f181c | 345 | return( ++p % 4 ); |
y_notsu | 0:ae31fe6f181c | 346 | #else |
y_notsu | 0:ae31fe6f181c | 347 | return( ++p % 2 ); |
y_notsu | 0:ae31fe6f181c | 348 | #endif |
y_notsu | 0:ae31fe6f181c | 349 | } |
y_notsu | 0:ae31fe6f181c | 350 |