Advanced Operating Systems - Final Project A @ Tokyo Tech ////////////// Author: Chu Van Thiem and Sidik Soleman ////////////// A WAVE file player on the MBED Application Board with an interface to a software on PC via a TCP connection. ////////////// Main functions: 1. Browse files of an attached USB flash 2. The list of the files of the attached USB are displayed on the LCD 3. Use an joystick to select a WAVE file and give an instruction to play that file 4. Adjust the volume using a potentiometer 5. Output audio to the analog audio out jack ////////////// Software (https://github.com/thiemcv/VS/tree/master/Terminal): 1. Connect with the MBED application board via Ethernet connection 2. Read the list of files stored on the USB flash 3. Write files to the USB flash
Dependencies: C12832_lcd EthernetInterface USBHost mbed-rtos mbed wave_player
src/main.cpp@1:3b567aa3b09e, 2014-02-02 (annotated)
- Committer:
- aos
- Date:
- Sun Feb 02 10:49:19 2014 +0000
- Revision:
- 1:3b567aa3b09e
- Parent:
- 0:6a2537e4188b
- Child:
- 2:5bc47e544b8d
Final Project V1: Integrated WAV player + USB file management via ethernet connection
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aos | 0:6a2537e4188b | 1 | #include "mbed.h" |
aos | 1:3b567aa3b09e | 2 | #include "rtos.h" |
aos | 0:6a2537e4188b | 3 | #include "EthernetInterface.h" |
aos | 1:3b567aa3b09e | 4 | #include "USBHostMSD.h" |
aos | 1:3b567aa3b09e | 5 | #include "usb.h" |
aos | 1:3b567aa3b09e | 6 | #include "tcp_task.h" |
aos | 1:3b567aa3b09e | 7 | #include "player.h" |
aos | 1:3b567aa3b09e | 8 | |
aos | 1:3b567aa3b09e | 9 | extern Ticker ticker; |
aos | 1:3b567aa3b09e | 10 | extern Ticker tickervolume; |
aos | 1:3b567aa3b09e | 11 | extern volatile int joyvalue; |
aos | 1:3b567aa3b09e | 12 | |
aos | 1:3b567aa3b09e | 13 | // Ethernet |
aos | 1:3b567aa3b09e | 14 | EthernetInterface eth; |
aos | 1:3b567aa3b09e | 15 | |
aos | 1:3b567aa3b09e | 16 | // Analog Out Jack |
aos | 1:3b567aa3b09e | 17 | //AnalogOut DACout(p18); |
aos | 1:3b567aa3b09e | 18 | // On Board Speaker |
aos | 1:3b567aa3b09e | 19 | //PwmOut PWMout(p26); |
aos | 1:3b567aa3b09e | 20 | // Wave file player |
aos | 1:3b567aa3b09e | 21 | //wave_player waver(&DACout,&PWMout); |
aos | 1:3b567aa3b09e | 22 | |
aos | 1:3b567aa3b09e | 23 | string songfile; |
aos | 1:3b567aa3b09e | 24 | char* song; |
aos | 1:3b567aa3b09e | 25 | |
aos | 1:3b567aa3b09e | 26 | volatile int cmd_en = 1; |
aos | 1:3b567aa3b09e | 27 | volatile int play_en = 1; |
aos | 0:6a2537e4188b | 28 | |
aos | 0:6a2537e4188b | 29 | int main() { |
aos | 1:3b567aa3b09e | 30 | int current = 0; |
aos | 1:3b567aa3b09e | 31 | // USB |
aos | 1:3b567aa3b09e | 32 | usb u("usb"); |
aos | 1:3b567aa3b09e | 33 | while(!u.connect()) |
aos | 1:3b567aa3b09e | 34 | { |
aos | 1:3b567aa3b09e | 35 | Thread::wait(5); |
aos | 1:3b567aa3b09e | 36 | } |
aos | 1:3b567aa3b09e | 37 | u.listdir("/"); |
aos | 1:3b567aa3b09e | 38 | /*u.listdir("/"); |
aos | 0:6a2537e4188b | 39 | |
aos | 1:3b567aa3b09e | 40 | for(vector<string>::iterator it = u.filenames.begin(); it < u.filenames.end(); it++) |
aos | 1:3b567aa3b09e | 41 | { |
aos | 1:3b567aa3b09e | 42 | printf("%s\n", it->c_str()); |
aos | 1:3b567aa3b09e | 43 | }*/ |
aos | 1:3b567aa3b09e | 44 | /* |
aos | 1:3b567aa3b09e | 45 | FILE *wave_file; |
aos | 1:3b567aa3b09e | 46 | //setup PWM hardware for a Class D style audio output |
aos | 1:3b567aa3b09e | 47 | PWMout.period(1.0/400000.0); |
aos | 1:3b567aa3b09e | 48 | //open wav file and play it |
aos | 1:3b567aa3b09e | 49 | string s = "/usb/"; |
aos | 1:3b567aa3b09e | 50 | s.append((u.filenames.begin())->c_str()); |
aos | 1:3b567aa3b09e | 51 | wave_file=fopen(s.c_str(),"r"); |
aos | 1:3b567aa3b09e | 52 | waver.play(wave_file); |
aos | 1:3b567aa3b09e | 53 | fclose(wave_file); |
aos | 1:3b567aa3b09e | 54 | */ |
aos | 0:6a2537e4188b | 55 | |
aos | 1:3b567aa3b09e | 56 | // Initialize ethernet interface |
aos | 1:3b567aa3b09e | 57 | eth.init(IP_ADDR, IP_MASK, GW_ADDR); |
aos | 1:3b567aa3b09e | 58 | eth.connect(); |
aos | 1:3b567aa3b09e | 59 | //printf("Network setup completed!\n"); |
aos | 0:6a2537e4188b | 60 | |
aos | 1:3b567aa3b09e | 61 | // LCD |
aos | 1:3b567aa3b09e | 62 | welcome(); |
aos | 1:3b567aa3b09e | 63 | /* print initiate */ |
aos | 1:3b567aa3b09e | 64 | print(&(u.filenames), 0); |
aos | 1:3b567aa3b09e | 65 | /* reading the joystick value */ |
aos | 1:3b567aa3b09e | 66 | ticker.attach(joystickcontrol, 0.004); |
aos | 1:3b567aa3b09e | 67 | /* reading the volume */ |
aos | 1:3b567aa3b09e | 68 | tickervolume.attach(controlvolume, 0.004); |
aos | 1:3b567aa3b09e | 69 | |
aos | 1:3b567aa3b09e | 70 | // TCPIP thread |
aos | 1:3b567aa3b09e | 71 | Thread thread_tcp(tcp_thread, NULL, osPriorityBelowNormal, 512, NULL); |
aos | 1:3b567aa3b09e | 72 | Thread thread_cmd(cmd_thread, &u, osPriorityBelowNormal, 2048, NULL); |
aos | 1:3b567aa3b09e | 73 | |
aos | 1:3b567aa3b09e | 74 | while(1) |
aos | 1:3b567aa3b09e | 75 | { |
aos | 1:3b567aa3b09e | 76 | if (joyvalue == 1){ |
aos | 1:3b567aa3b09e | 77 | if(u.filenames.size()>0){ |
aos | 1:3b567aa3b09e | 78 | current = (current-1)%u.filenames.size(); |
aos | 1:3b567aa3b09e | 79 | print(&(u.filenames),current); |
aos | 1:3b567aa3b09e | 80 | } |
aos | 1:3b567aa3b09e | 81 | } |
aos | 1:3b567aa3b09e | 82 | else if (joyvalue == 2){ |
aos | 1:3b567aa3b09e | 83 | if(u.filenames.size()>0){ |
aos | 1:3b567aa3b09e | 84 | current = (current+1)%u.filenames.size(); |
aos | 1:3b567aa3b09e | 85 | print(&(u.filenames),current); |
aos | 1:3b567aa3b09e | 86 | } |
aos | 1:3b567aa3b09e | 87 | } |
aos | 1:3b567aa3b09e | 88 | else if (joyvalue == 3){ |
aos | 1:3b567aa3b09e | 89 | if(u.filenames.size()>0){ |
aos | 1:3b567aa3b09e | 90 | if (play_en) |
aos | 1:3b567aa3b09e | 91 | { |
aos | 1:3b567aa3b09e | 92 | cmd_en = 0; |
aos | 1:3b567aa3b09e | 93 | songfile = "/usb/"; |
aos | 1:3b567aa3b09e | 94 | songfile = songfile + u.filenames.at(current); |
aos | 1:3b567aa3b09e | 95 | song = (char*)songfile.c_str(); |
aos | 1:3b567aa3b09e | 96 | play(song); |
aos | 1:3b567aa3b09e | 97 | cmd_en = 1; |
aos | 1:3b567aa3b09e | 98 | } |
aos | 1:3b567aa3b09e | 99 | } |
aos | 1:3b567aa3b09e | 100 | } |
aos | 1:3b567aa3b09e | 101 | joyvalue = 0; |
aos | 1:3b567aa3b09e | 102 | Thread::wait(5); |
aos | 0:6a2537e4188b | 103 | } |
aos | 0:6a2537e4188b | 104 | } |