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@5:12a48b7c41bf, 2014-02-13 (annotated)
- Committer:
- aos
- Date:
- Thu Feb 13 17:58:20 2014 +0000
- Revision:
- 5:12a48b7c41bf
- Parent:
- 2:5bc47e544b8d
Update
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aos | 2:5bc47e544b8d | 1 | /* FILE: main.cpp by Chu Van Thiem + Sidik Soleman |
aos | 2:5bc47e544b8d | 2 | */ |
aos | 0:6a2537e4188b | 3 | #include "mbed.h" |
aos | 1:3b567aa3b09e | 4 | #include "rtos.h" |
aos | 0:6a2537e4188b | 5 | #include "EthernetInterface.h" |
aos | 1:3b567aa3b09e | 6 | #include "USBHostMSD.h" |
aos | 1:3b567aa3b09e | 7 | #include "usb.h" |
aos | 1:3b567aa3b09e | 8 | #include "tcp_task.h" |
aos | 1:3b567aa3b09e | 9 | #include "player.h" |
aos | 1:3b567aa3b09e | 10 | |
aos | 1:3b567aa3b09e | 11 | extern Ticker ticker; |
aos | 1:3b567aa3b09e | 12 | extern Ticker tickervolume; |
aos | 1:3b567aa3b09e | 13 | extern volatile int joyvalue; |
aos | 1:3b567aa3b09e | 14 | |
aos | 1:3b567aa3b09e | 15 | // Ethernet |
aos | 1:3b567aa3b09e | 16 | EthernetInterface eth; |
aos | 1:3b567aa3b09e | 17 | |
aos | 1:3b567aa3b09e | 18 | string songfile; |
aos | 1:3b567aa3b09e | 19 | char* song; |
aos | 1:3b567aa3b09e | 20 | |
aos | 1:3b567aa3b09e | 21 | volatile int cmd_en = 1; |
aos | 1:3b567aa3b09e | 22 | volatile int play_en = 1; |
aos | 0:6a2537e4188b | 23 | |
aos | 0:6a2537e4188b | 24 | int main() { |
aos | 1:3b567aa3b09e | 25 | int current = 0; |
aos | 1:3b567aa3b09e | 26 | // USB |
aos | 1:3b567aa3b09e | 27 | usb u("usb"); |
aos | 1:3b567aa3b09e | 28 | while(!u.connect()) |
aos | 1:3b567aa3b09e | 29 | { |
aos | 1:3b567aa3b09e | 30 | Thread::wait(5); |
aos | 1:3b567aa3b09e | 31 | } |
aos | 1:3b567aa3b09e | 32 | u.listdir("/"); |
aos | 0:6a2537e4188b | 33 | |
aos | 1:3b567aa3b09e | 34 | // Initialize ethernet interface |
aos | 1:3b567aa3b09e | 35 | eth.init(IP_ADDR, IP_MASK, GW_ADDR); |
aos | 1:3b567aa3b09e | 36 | eth.connect(); |
aos | 1:3b567aa3b09e | 37 | //printf("Network setup completed!\n"); |
aos | 0:6a2537e4188b | 38 | |
aos | 1:3b567aa3b09e | 39 | // LCD |
aos | 1:3b567aa3b09e | 40 | welcome(); |
aos | 1:3b567aa3b09e | 41 | /* print initiate */ |
aos | 1:3b567aa3b09e | 42 | print(&(u.filenames), 0); |
aos | 1:3b567aa3b09e | 43 | /* reading the joystick value */ |
aos | 1:3b567aa3b09e | 44 | ticker.attach(joystickcontrol, 0.004); |
aos | 1:3b567aa3b09e | 45 | /* reading the volume */ |
aos | 1:3b567aa3b09e | 46 | tickervolume.attach(controlvolume, 0.004); |
aos | 1:3b567aa3b09e | 47 | |
aos | 1:3b567aa3b09e | 48 | // TCPIP thread |
aos | 1:3b567aa3b09e | 49 | Thread thread_tcp(tcp_thread, NULL, osPriorityBelowNormal, 512, NULL); |
aos | 1:3b567aa3b09e | 50 | Thread thread_cmd(cmd_thread, &u, osPriorityBelowNormal, 2048, NULL); |
aos | 1:3b567aa3b09e | 51 | |
aos | 1:3b567aa3b09e | 52 | while(1) |
aos | 1:3b567aa3b09e | 53 | { |
aos | 1:3b567aa3b09e | 54 | if (joyvalue == 1){ |
aos | 1:3b567aa3b09e | 55 | if(u.filenames.size()>0){ |
aos | 1:3b567aa3b09e | 56 | current = (current-1)%u.filenames.size(); |
aos | 1:3b567aa3b09e | 57 | print(&(u.filenames),current); |
aos | 1:3b567aa3b09e | 58 | } |
aos | 1:3b567aa3b09e | 59 | } |
aos | 1:3b567aa3b09e | 60 | else if (joyvalue == 2){ |
aos | 1:3b567aa3b09e | 61 | if(u.filenames.size()>0){ |
aos | 1:3b567aa3b09e | 62 | current = (current+1)%u.filenames.size(); |
aos | 1:3b567aa3b09e | 63 | print(&(u.filenames),current); |
aos | 1:3b567aa3b09e | 64 | } |
aos | 1:3b567aa3b09e | 65 | } |
aos | 1:3b567aa3b09e | 66 | else if (joyvalue == 3){ |
aos | 1:3b567aa3b09e | 67 | if(u.filenames.size()>0){ |
aos | 1:3b567aa3b09e | 68 | if (play_en) |
aos | 1:3b567aa3b09e | 69 | { |
aos | 1:3b567aa3b09e | 70 | cmd_en = 0; |
aos | 1:3b567aa3b09e | 71 | songfile = "/usb/"; |
aos | 1:3b567aa3b09e | 72 | songfile = songfile + u.filenames.at(current); |
aos | 1:3b567aa3b09e | 73 | song = (char*)songfile.c_str(); |
aos | 1:3b567aa3b09e | 74 | play(song); |
aos | 1:3b567aa3b09e | 75 | cmd_en = 1; |
aos | 1:3b567aa3b09e | 76 | } |
aos | 1:3b567aa3b09e | 77 | } |
aos | 1:3b567aa3b09e | 78 | } |
aos | 1:3b567aa3b09e | 79 | joyvalue = 0; |
aos | 1:3b567aa3b09e | 80 | Thread::wait(5); |
aos | 0:6a2537e4188b | 81 | } |
aos | 0:6a2537e4188b | 82 | } |