A S / Mbed 2 deprecated aos_mbed

Dependencies:   C12832_lcd EthernetInterface USBHost mbed-rtos mbed wave_player

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* FILE: main.cpp by Chu Van Thiem + Sidik Soleman
00002 */
00003 #include "mbed.h"
00004 #include "rtos.h"
00005 #include "EthernetInterface.h"
00006 #include "USBHostMSD.h"
00007 #include "usb.h"
00008 #include "tcp_task.h"
00009 #include "player.h"
00010 
00011 extern Ticker ticker;
00012 extern Ticker tickervolume;
00013 extern volatile int joyvalue;
00014 
00015 // Ethernet
00016 EthernetInterface eth;
00017 
00018 string songfile;
00019 char* song;
00020 
00021 volatile int cmd_en = 1;
00022 volatile int play_en = 1;
00023 
00024 int main() {
00025     int current = 0;
00026     // USB
00027     usb u("usb");
00028     while(!u.connect())
00029     {
00030         Thread::wait(5);
00031     }
00032     u.listdir("/");
00033     
00034     // Initialize ethernet interface
00035     eth.init(IP_ADDR, IP_MASK, GW_ADDR);
00036     eth.connect();
00037     //printf("Network setup completed!\n");
00038     
00039     // LCD
00040     welcome();
00041     /* print initiate */
00042     print(&(u.filenames), 0);
00043     /* reading the joystick value */
00044     ticker.attach(joystickcontrol, 0.004);
00045     /* reading the volume */
00046     tickervolume.attach(controlvolume, 0.004);
00047     
00048     // TCPIP thread
00049     Thread thread_tcp(tcp_thread, NULL, osPriorityBelowNormal, 512, NULL);
00050     Thread thread_cmd(cmd_thread, &u, osPriorityBelowNormal, 2048, NULL);
00051     
00052     while(1)
00053     {
00054         if (joyvalue == 1){
00055             if(u.filenames.size()>0){
00056                 current = (current-1)%u.filenames.size();
00057                 print(&(u.filenames),current);
00058             }
00059         }
00060         else if (joyvalue == 2){
00061             if(u.filenames.size()>0){
00062                 current = (current+1)%u.filenames.size();
00063                 print(&(u.filenames),current);
00064             }
00065         }
00066         else if (joyvalue == 3){
00067             if(u.filenames.size()>0){
00068                 if (play_en)
00069                 {
00070                     cmd_en = 0;
00071                     songfile = "/usb/";
00072                     songfile = songfile + u.filenames.at(current);
00073                     song = (char*)songfile.c_str();
00074                     play(song);
00075                     cmd_en = 1;
00076                 }
00077             }
00078         }
00079         joyvalue = 0;
00080         Thread::wait(5);
00081     }
00082 }