Smart pole
Dependencies: FTPClient SDFileSystem WIZnetInterface mbed
Fork of FTP_Streaming_Music_Player_WIZwiki-W7500 by
Diff: main.cpp
- Revision:
- 1:c47c255fcad4
- Parent:
- 0:fa775d326f9c
--- a/main.cpp Tue Sep 22 23:14:59 2015 +0000 +++ b/main.cpp Fri Oct 30 03:53:23 2015 +0000 @@ -5,43 +5,35 @@ #include <string.h> #include "FTPClient.h" - #include "VS1002.h" - #include "TextLCD.h" +#include "VS1002.h" +#include "SSD1306.h" #define MAC "\x00\x08\xDC\x11\x34\x78" -#define IP "192.168.77.191" +#define IP "192.168.0.20" #define MASK "255.255.255.0" -#define GATEWAY "192.168.77.1" +#define GATEWAY "192.168.0.1" -#define FTP_SERVER_IP "192.168.77.209" +#define FTP_SERVER_IP "192.168.0.10" #define _MAX_FNAME_LEN_ 127 -#define _FTP_UPDATE_TIME_ 20 +#define _FTP_UPDATE_TIME_ 10 Serial uart(USBTX, USBRX); - +AnalogIn ain(A5); //SDFileSystem sd(p5, p6, p7, p8, "sd"); // LPC1768 MBD2PMD //SDFileSystem sd(P0_18, P0_17, P0_15, P0_16, "sd"); // Seeeduino Arch Pro SPI2SD //SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // K64F //SDFileSystem sd(PB_3, PB_2, PB_1, PB_0, "sd"); // WIZwiki-W7500 EthernetInterface eth; - -DigitalOut led1(LED1); //server listning status -DigitalOut led2(LED2); //socket connecting status - InterruptIn K_VU(D3); // Create the interrupt receiver object on pin 26 -InterruptIn K_NT(D4); // Create the interrupt receiver object on pin 26 -InterruptIn K_PS(D5); // Create the interrupt receiver object on pin 26 -InterruptIn K_BK(D6); // Create the interrupt receiver object on pin 26 InterruptIn K_VD(D7); // Create the interrupt receiver object on pin 26 VS1002 mp3(PB_3, PB_2, PB_1, PB_0,"sdc",D11, D12 ,D13, PC_12, PC_15, PC_14, PC_13); //Setup Audio decoder. Name is VS1002 even though VS1053 is used. -TextLCD lcd1(D8, D9, D0, D1, D2, D15); //setup lcd FTPClient myFTP("/sdc"); // mountname in MySeeedStudioTFTv2 -Ticker ledTick; +//Ticker ledTick; /* Global Variables to store Status*/ int new_song_number=1; //Variable to store the Song Number @@ -51,93 +43,33 @@ bool mute=false; //Variable to store the status of mute button int check=0; //Capacitative touch generates interrupt on both press and release. This variable tracks this and updates only on press. -char *song_name[9]={"Good Day","Leong","Sponsor","I'm So Sexy","My Life","Oh My god","Wonderful bar","Whale Hunting","Love"}; //Array of song names entered manually +//char *song_name[9]={"Good Day","Leong","Sponsor","I'm So Sexy","My Life","Oh My god","Wonderful bar","Whale Hunting","Love"}; //Array of song names entered manually uint32_t ftp_time_1s = 0; char myfilelist[MAX_SS] = {0,}; -void ledTickfunc() +/*void ledTickfunc() { - led1 = !led1; if(ftp_time_1s) { + //printf("enter ftp_time_1s:%d\r\n", ftp_time_1s); if(ftp_time_1s++ > _FTP_UPDATE_TIME_) ftp_time_1s = 0; } -} - -void Next_Song() -{ - new_song_number+=1; // Next Song - if(new_song_number==10) - new_song_number=1; - - lcd1.cls(); - if(pause) - lcd1.printf(" Paused "); - else - lcd1.printf(" Playing..."); - - lcd1.printf("\n %d %s",new_song_number,song_name[new_song_number-1]); -} - -void Preveious_Song() -{ - new_song_number-=1; // Preveious Song - if(new_song_number==0) - new_song_number=9; - - lcd1.cls(); - if(pause) - lcd1.printf(" Paused "); - else - lcd1.printf(" Playing..."); - - lcd1.printf("\n %d %s",new_song_number,song_name[new_song_number-1]); -} - -void Pause_Song() -{ - pause=!pause; // Pause/Play button - - lcd1.cls(); - if(pause) - lcd1.printf(" Paused "); - else - lcd1.printf(" Playing..."); - - lcd1.printf("\n %d %s",new_song_number,song_name[new_song_number-1]); -} - +}*/ void Volume_Up() { volume_set+=3; // Volume Up if(volume_set>=0) volume_set=0; } - + void Volume_Down() { volume_set-=3; //Volume Down if(volume_set<-55) volume_set=-55; } -/* -void Volume_Mute() -{ - mute=!mute; //Mute/Unmute - - if(mute) - { - previous_volume=volume_set; // Attenuation of -55 db is small enough to not hear anything - volume_set=-55; - } - else - { - volume_set=previous_volume; - } -}*/ - int main (void) { *(volatile uint32_t *)(0x41001014) = 0x0060100; @@ -147,11 +79,21 @@ *(volatile uint32_t *)(0x41003080) = 0x10; *(volatile uint32_t *)(0x41003098) = 0x10; - char* tok = NULL; + unsigned int update_count_s=6; + unsigned int update_count_ms=0; + unsigned int ain_temp=0; + //char* my_text = "GIF2015"; + /*char* tok = NULL; char* lasts = NULL; char filename[_MAX_FNAME_LEN_]; - FILE* fp; + FILE* fp;*/ + init(); + cls(); + //OLED_DrawBMP(0,0,128,8,(unsigned char *)GIF2015); + //OLED_ShowStr(0,0,my_text,2); + OLED_DrawBMP(0,0,128,8,(unsigned char *)wiznet); + //LED_P23x32Str(0, 0, my_text); // Serial Interface eth; uart.baud(115200); uart.printf("Initializing\r\n"); @@ -175,53 +117,41 @@ uart.printf("SD Card Root Directory Not Found\r\n"); } - ledTick.attach(&ledTickfunc,1); - + //ledTick.attach(&ledTickfunc,2); + /* UI Button setup */ + K_VU.fall(&Volume_Up); + K_VU.mode(PullUp); + K_VD.fall(&Volume_Down); + K_VD.mode(PullUp); + while(1) { - if(ftp_time_1s == 0) + update_count_ms++; + if(update_count_ms>5000) + { + printf("update_count_ms count : %d\r\n", update_count_s); + update_count_ms=0; + update_count_s++; + } + //printf("ftp_time_1s:%d\r\n", ftp_time_1s); + //if(ftp_time_1s == 0) + if(update_count_s>=5) { //Configure the display driver - ftp_time_1s = 1; + update_count_s = 0; printf(" UPDATING MP3\r\n"); printf("==================\n\r\n"); - myFTP.open("192.168.77.209", 21, "user", "pass"); - if(myFTP.open("192.168.77.209", 21, "user", "pass")) + if(myFTP.open("192.168.0.10", 21, "user", "pass")) { printf("Connect Success to FTPServer\r\n"); printf("Connected to FTP Server\r\n"); - - myFTP.ls(myfilelist); - - if(*myfilelist !=0) - { - tok = myfilelist; - while(tok) - { - tok = strtok_r(tok,"\r\n",&lasts); - if(tok != NULL) - { - printf("tok=%s\r\n",tok); - if(strstr(tok,"mp3")) - { - sprintf(filename,"/sdc/%s",tok); - fp = fopen(filename, "r"); - printf("fp=%d\r\n",fp); - if(fp==NULL) - { - myFTP.getfile(tok); - printf("Get File : %s\r\n",tok); - printf("New file : %s\r\n",tok); - } - else fclose(fp); - } - tok = lasts; - } - } - } - else printf(" Empty FTP Server\r\n"); + + myFTP.getfile("1.mp3"); + myFTP.getfile("2.mp3"); + myFTP.getfile("3.mp3"); + printf("\n UPDATE DONE\n\r\n"); myFTP.quit(); } @@ -244,20 +174,12 @@ mp3.sci_write(0x03, 0x9800); mp3.sdi_initialise(); - /* UI Button setup */ - K_VU.fall(&Volume_Up); - K_VU.mode(PullUp); - K_VD.fall(&Volume_Down); - K_VD.mode(PullUp); - K_NT.fall(&Next_Song); - K_NT.mode(PullUp); - K_BK.fall(&Preveious_Song); - K_BK.mode(PullUp); - K_PS.fall(&Pause_Song); - K_PS.mode(PullUp); + ain_temp = ain.read_u16(); + //printf("normalized: %d \n\r", ain_temp); - while(1) + if (ain_temp>3000) { + printf("enter song\r\n"); mp3.play_song(new_song_number); } }