Smart pole
Dependencies: FTPClient SDFileSystem WIZnetInterface mbed
Fork of FTP_Streaming_Music_Player_WIZwiki-W7500 by
main.cpp
00001 #include "mbed.h" 00002 #include "EthernetInterface.h" 00003 #include "SDFileSystem.h" 00004 #include <stdio.h> 00005 #include <string.h> 00006 00007 #include "FTPClient.h" 00008 #include "VS1002.h" 00009 #include "SSD1306.h" 00010 00011 #define MAC "\x00\x08\xDC\x11\x34\x78" 00012 #define IP "192.168.0.20" 00013 #define MASK "255.255.255.0" 00014 #define GATEWAY "192.168.0.1" 00015 00016 #define FTP_SERVER_IP "192.168.0.10" 00017 00018 #define _MAX_FNAME_LEN_ 127 00019 #define _FTP_UPDATE_TIME_ 10 00020 00021 00022 Serial uart(USBTX, USBRX); 00023 AnalogIn ain(A5); 00024 //SDFileSystem sd(p5, p6, p7, p8, "sd"); // LPC1768 MBD2PMD 00025 //SDFileSystem sd(P0_18, P0_17, P0_15, P0_16, "sd"); // Seeeduino Arch Pro SPI2SD 00026 //SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // K64F 00027 //SDFileSystem sd(PB_3, PB_2, PB_1, PB_0, "sd"); // WIZwiki-W7500 00028 00029 EthernetInterface eth; 00030 InterruptIn K_VU(D3); // Create the interrupt receiver object on pin 26 00031 InterruptIn K_VD(D7); // Create the interrupt receiver object on pin 26 00032 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. 00033 00034 FTPClient myFTP("/sdc"); // mountname in MySeeedStudioTFTv2 00035 00036 //Ticker ledTick; 00037 00038 /* Global Variables to store Status*/ 00039 int new_song_number=1; //Variable to store the Song Number 00040 int volume_set=-20; //Variable to store the Volume 00041 int previous_volume; //Variable to store the volume when muted 00042 bool pause=false; //Variable to store the status of Pause button 00043 bool mute=false; //Variable to store the status of mute button 00044 00045 int check=0; //Capacitative touch generates interrupt on both press and release. This variable tracks this and updates only on press. 00046 //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 00047 00048 uint32_t ftp_time_1s = 0; 00049 00050 char myfilelist[MAX_SS] = {0,}; 00051 00052 /*void ledTickfunc() 00053 { 00054 if(ftp_time_1s) 00055 { 00056 //printf("enter ftp_time_1s:%d\r\n", ftp_time_1s); 00057 if(ftp_time_1s++ > _FTP_UPDATE_TIME_) ftp_time_1s = 0; 00058 } 00059 }*/ 00060 void Volume_Up() 00061 { 00062 volume_set+=3; // Volume Up 00063 if(volume_set>=0) 00064 volume_set=0; 00065 } 00066 00067 void Volume_Down() 00068 { 00069 volume_set-=3; //Volume Down 00070 if(volume_set<-55) 00071 volume_set=-55; 00072 } 00073 int main (void) 00074 { 00075 *(volatile uint32_t *)(0x41001014) = 0x0060100; 00076 *(volatile uint32_t *)(0x41003000) = 0x10; 00077 *(volatile uint32_t *)(0x41003004) = 0x10; 00078 *(volatile uint32_t *)(0x41003008) = 0x10; 00079 *(volatile uint32_t *)(0x41003080) = 0x10; 00080 *(volatile uint32_t *)(0x41003098) = 0x10; 00081 00082 unsigned int update_count_s=6; 00083 unsigned int update_count_ms=0; 00084 unsigned int ain_temp=0; 00085 //char* my_text = "GIF2015"; 00086 /*char* tok = NULL; 00087 char* lasts = NULL; 00088 char filename[_MAX_FNAME_LEN_]; 00089 FILE* fp;*/ 00090 00091 init(); 00092 cls(); 00093 //OLED_DrawBMP(0,0,128,8,(unsigned char *)GIF2015); 00094 //OLED_ShowStr(0,0,my_text,2); 00095 OLED_DrawBMP(0,0,128,8,(unsigned char *)wiznet); 00096 //LED_P23x32Str(0, 0, my_text); 00097 // Serial Interface eth; 00098 uart.baud(115200); 00099 uart.printf("Initializing\r\n"); 00100 00101 // EthernetInterface eth; 00102 uart.printf("Initializing Ethernet\r\n"); 00103 00104 //eth.init(); //Use DHCP 00105 eth.init((uint8_t*)MAC,IP,MASK,GATEWAY); //IP,mask,Gateway 00106 uart.printf("Connecting\r\n"); 00107 eth.connect(); 00108 uart.printf("IP Address is %s\r\n", eth.getIPAddress()); 00109 00110 // Check File System 00111 uart.printf("Checking File System\r\n"); 00112 DIR *d = opendir("/sdc/"); 00113 if (d != NULL) { 00114 uart.printf("SD Card Present\r\n"); 00115 closedir(d); 00116 } else { 00117 uart.printf("SD Card Root Directory Not Found\r\n"); 00118 } 00119 00120 //ledTick.attach(&ledTickfunc,2); 00121 /* UI Button setup */ 00122 K_VU.fall(&Volume_Up); 00123 K_VU.mode(PullUp); 00124 K_VD.fall(&Volume_Down); 00125 K_VD.mode(PullUp); 00126 00127 while(1) 00128 { 00129 update_count_ms++; 00130 if(update_count_ms>5000) 00131 { 00132 printf("update_count_ms count : %d\r\n", update_count_s); 00133 update_count_ms=0; 00134 update_count_s++; 00135 } 00136 //printf("ftp_time_1s:%d\r\n", ftp_time_1s); 00137 //if(ftp_time_1s == 0) 00138 if(update_count_s>=5) 00139 { 00140 //Configure the display driver 00141 update_count_s = 0; 00142 00143 printf(" UPDATING MP3\r\n"); 00144 printf("==================\n\r\n"); 00145 00146 if(myFTP.open("192.168.0.10", 21, "user", "pass")) 00147 { 00148 printf("Connect Success to FTPServer\r\n"); 00149 printf("Connected to FTP Server\r\n"); 00150 00151 myFTP.getfile("1.mp3"); 00152 myFTP.getfile("2.mp3"); 00153 myFTP.getfile("3.mp3"); 00154 00155 printf("\n UPDATE DONE\n\r\n"); 00156 myFTP.quit(); 00157 } 00158 else 00159 { 00160 printf(" Can't connect to FTP Server\r\n"); 00161 printf(" UPDATE FAIL\r\n"); 00162 } 00163 printf("==================\n"); 00164 } 00165 00166 /*============================================================ 00167 * MP3 Initialising 00168 *==========================================================*/ 00169 00170 mp3._RST = 1; 00171 mp3.cs_high(); //chip disabled 00172 mp3.sci_initialise(); //initialise MBED 00173 mp3.sci_write(0x00,(SM_SDINEW+SM_STREAM+SM_DIFF)); 00174 mp3.sci_write(0x03, 0x9800); 00175 mp3.sdi_initialise(); 00176 00177 ain_temp = ain.read_u16(); 00178 //printf("normalized: %d \n\r", ain_temp); 00179 00180 if (ain_temp>3000) 00181 { 00182 printf("enter song\r\n"); 00183 mp3.play_song(new_song_number); 00184 } 00185 } 00186 }
Generated on Thu Jul 14 2022 08:09:14 by 1.7.2