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

Revision:
1:3b567aa3b09e
Parent:
0:6a2537e4188b
Child:
2:5bc47e544b8d
--- a/src/main.cpp	Tue Jan 07 04:15:05 2014 +0000
+++ b/src/main.cpp	Sun Feb 02 10:49:19 2014 +0000
@@ -1,31 +1,104 @@
 #include "mbed.h"
+#include "rtos.h"
 #include "EthernetInterface.h"
+#include "USBHostMSD.h"
+#include "usb.h"
+#include "tcp_task.h"
+#include "player.h"
+
+extern Ticker ticker;
+extern Ticker tickervolume;
+extern volatile int joyvalue;
+
+// Ethernet
+EthernetInterface eth;
+
+// Analog Out Jack
+//AnalogOut DACout(p18);
+// On Board Speaker
+//PwmOut PWMout(p26);
+// Wave file player
+//wave_player waver(&DACout,&PWMout);
+
+string songfile;
+char* song;
+
+volatile int cmd_en = 1;
+volatile int play_en = 1;
 
 int main() {
-    EthernetInterface eth;
-    eth.init(); //Use DHCP
-    eth.connect();
-    printf("IP Address is %s\n", eth.getIPAddress());
+    int current = 0;
+    // USB
+    usb u("usb");
+    while(!u.connect())
+    {
+        Thread::wait(5);
+    }
+    u.listdir("/");
+    /*u.listdir("/");
     
-    TCPSocketConnection sock;
-    sock.connect("mbed.org", 80);
+    for(vector<string>::iterator it = u.filenames.begin(); it < u.filenames.end(); it++)
+    {
+        printf("%s\n", it->c_str());
+    }*/
+    /*
+    FILE *wave_file;
+    //setup PWM hardware for a Class D style audio output
+    PWMout.period(1.0/400000.0);
+    //open wav file and play it
+    string s = "/usb/";
+    s.append((u.filenames.begin())->c_str());
+    wave_file=fopen(s.c_str(),"r");
+    waver.play(wave_file);
+    fclose(wave_file);
+    */
     
-    char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n";
-    sock.send_all(http_cmd, sizeof(http_cmd)-1);
+    // Initialize ethernet interface
+    eth.init(IP_ADDR, IP_MASK, GW_ADDR);
+    eth.connect();
+    //printf("Network setup completed!\n");
     
-    char buffer[300];
-    int ret;
-    while (true) {
-        ret = sock.receive(buffer, sizeof(buffer)-1);
-        if (ret <= 0)
-            break;
-        buffer[ret] = '\0';
-        printf("Received %d chars from server:\n%s\n", ret, buffer);
+    // LCD
+    welcome();
+    /* print initiate */
+    print(&(u.filenames), 0);
+    /* reading the joystick value */
+    ticker.attach(joystickcontrol, 0.004);
+    /* reading the volume */
+    tickervolume.attach(controlvolume, 0.004);
+    
+    // TCPIP thread
+    Thread thread_tcp(tcp_thread, NULL, osPriorityBelowNormal, 512, NULL);
+    Thread thread_cmd(cmd_thread, &u, osPriorityBelowNormal, 2048, NULL);
+    
+    while(1)
+    {
+        if (joyvalue == 1){
+            if(u.filenames.size()>0){
+                current = (current-1)%u.filenames.size();
+                print(&(u.filenames),current);
+            }
+        }
+        else if (joyvalue == 2){
+            if(u.filenames.size()>0){
+                current = (current+1)%u.filenames.size();
+                print(&(u.filenames),current);
+            }
+        }
+        else if (joyvalue == 3){
+            if(u.filenames.size()>0){
+                if (play_en)
+                {
+                    cmd_en = 0;
+                    songfile = "/usb/";
+                    songfile = songfile + u.filenames.at(current);
+                    song = (char*)songfile.c_str();
+                    play(song);
+                    cmd_en = 1;
+                }
+            }
+        }
+        joyvalue = 0;
+        Thread::wait(5);
     }
-      
-    sock.close();
-    
-    eth.disconnect();
-    
-    while(1) {}
 }