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/player.cpp@2:5bc47e544b8d, 2014-02-13 (annotated)
- Committer:
- aos
- Date:
- Thu Feb 13 06:51:20 2014 +0000
- Revision:
- 2:5bc47e544b8d
- Parent:
- 1:3b567aa3b09e
Update some comments
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aos | 2:5bc47e544b8d | 1 | /* FILE: player.cpp by Sidik Soleman |
aos | 2:5bc47e544b8d | 2 | */ |
aos | 1:3b567aa3b09e | 3 | #include "player.h" |
aos | 1:3b567aa3b09e | 4 | |
aos | 1:3b567aa3b09e | 5 | C12832_LCD lcd; |
aos | 1:3b567aa3b09e | 6 | AnalogOut DACout(p18); |
aos | 1:3b567aa3b09e | 7 | /* joystick location */ |
aos | 1:3b567aa3b09e | 8 | DigitalIn Up(p15); |
aos | 1:3b567aa3b09e | 9 | DigitalIn Down(p12); |
aos | 1:3b567aa3b09e | 10 | DigitalIn Left(p13); |
aos | 1:3b567aa3b09e | 11 | DigitalIn Right(p16); |
aos | 1:3b567aa3b09e | 12 | DigitalIn Play(p14); |
aos | 1:3b567aa3b09e | 13 | AnalogIn ain(p19); |
aos | 1:3b567aa3b09e | 14 | |
aos | 1:3b567aa3b09e | 15 | Ticker ticker; |
aos | 1:3b567aa3b09e | 16 | Ticker tickervolume; |
aos | 1:3b567aa3b09e | 17 | int joyup=0,joydown=0,joyplay=0; |
aos | 1:3b567aa3b09e | 18 | wave_player waver(&DACout); |
aos | 1:3b567aa3b09e | 19 | volatile int joyvalue=0; |
aos | 1:3b567aa3b09e | 20 | float aout = 0; |
aos | 1:3b567aa3b09e | 21 | FILE *wave_file; |
aos | 1:3b567aa3b09e | 22 | |
aos | 1:3b567aa3b09e | 23 | // Custom Function |
aos | 1:3b567aa3b09e | 24 | void play(char* song){ |
aos | 1:3b567aa3b09e | 25 | wave_file=fopen(song,"r"); |
aos | 1:3b567aa3b09e | 26 | waver.play(wave_file); |
aos | 1:3b567aa3b09e | 27 | fclose(wave_file); |
aos | 1:3b567aa3b09e | 28 | } |
aos | 1:3b567aa3b09e | 29 | |
aos | 1:3b567aa3b09e | 30 | void welcome(){ |
aos | 1:3b567aa3b09e | 31 | lcd.cls(); |
aos | 1:3b567aa3b09e | 32 | lcd.locate(15,0); |
aos | 1:3b567aa3b09e | 33 | lcd.printf("MBED Player"); |
aos | 1:3b567aa3b09e | 34 | Thread::wait(1); |
aos | 1:3b567aa3b09e | 35 | lcd.cls(); |
aos | 1:3b567aa3b09e | 36 | } |
aos | 1:3b567aa3b09e | 37 | |
aos | 1:3b567aa3b09e | 38 | void print(vector<string> *listoffile, int current){ |
aos | 1:3b567aa3b09e | 39 | lcd.cls(); |
aos | 1:3b567aa3b09e | 40 | int nsong = listoffile->size(); |
aos | 1:3b567aa3b09e | 41 | lcd.locate(0,0); |
aos | 1:3b567aa3b09e | 42 | lcd.printf("Song Title (%d/%d)",(current+1),nsong); |
aos | 1:3b567aa3b09e | 43 | lcd.locate(0,9); |
aos | 1:3b567aa3b09e | 44 | lcd.printf("-------------------------------"); |
aos | 1:3b567aa3b09e | 45 | if (nsong == 0){ |
aos | 1:3b567aa3b09e | 46 | lcd.locate(0,15); |
aos | 1:3b567aa3b09e | 47 | lcd.printf("No File Song"); |
aos | 1:3b567aa3b09e | 48 | } else { |
aos | 1:3b567aa3b09e | 49 | lcd.printf("> %s",(listoffile->at(current)).c_str()); |
aos | 1:3b567aa3b09e | 50 | } |
aos | 1:3b567aa3b09e | 51 | } |
aos | 1:3b567aa3b09e | 52 | |
aos | 1:3b567aa3b09e | 53 | /* JoyValue = 1: up, 2: down, 3: play */ |
aos | 1:3b567aa3b09e | 54 | void joystickcontrol(){ |
aos | 1:3b567aa3b09e | 55 | if (Up){ |
aos | 1:3b567aa3b09e | 56 | if (joyup<NSAMPLE) joyup++; |
aos | 1:3b567aa3b09e | 57 | if (joyup==NSAMPLE){ joyvalue=1; joyup=0;} |
aos | 1:3b567aa3b09e | 58 | } |
aos | 1:3b567aa3b09e | 59 | if (Down){ |
aos | 1:3b567aa3b09e | 60 | if (joydown<NSAMPLE) joydown++; |
aos | 1:3b567aa3b09e | 61 | if (joydown==NSAMPLE) { joyvalue=2; joydown = 0;} |
aos | 1:3b567aa3b09e | 62 | } |
aos | 1:3b567aa3b09e | 63 | if (Play){ |
aos | 1:3b567aa3b09e | 64 | if (joyplay<NSAMPLE) joyplay++; |
aos | 1:3b567aa3b09e | 65 | if (joyplay==NSAMPLE) { joyvalue=3; joyplay=0;} |
aos | 1:3b567aa3b09e | 66 | } |
aos | 1:3b567aa3b09e | 67 | } |
aos | 1:3b567aa3b09e | 68 | |
aos | 1:3b567aa3b09e | 69 | void controlvolume(){ |
aos | 1:3b567aa3b09e | 70 | waver.volume = (float)ain; |
aos | 1:3b567aa3b09e | 71 | } |