Smart pole

Dependencies:   FTPClient SDFileSystem WIZnetInterface mbed

Fork of FTP_Streaming_Music_Player_WIZwiki-W7500 by justin kim

Committer:
Ricky_Kwon
Date:
Fri Oct 30 03:53:23 2015 +0000
Revision:
1:c47c255fcad4
Parent:
0:fa775d326f9c
Smart pole

Who changed what in which revision?

UserRevisionLine numberNew contents of line
justinkim 0:fa775d326f9c 1 #include "mbed.h"
justinkim 0:fa775d326f9c 2 #include "EthernetInterface.h"
justinkim 0:fa775d326f9c 3 #include "SDFileSystem.h"
justinkim 0:fa775d326f9c 4 #include <stdio.h>
justinkim 0:fa775d326f9c 5 #include <string.h>
justinkim 0:fa775d326f9c 6
justinkim 0:fa775d326f9c 7 #include "FTPClient.h"
Ricky_Kwon 1:c47c255fcad4 8 #include "VS1002.h"
Ricky_Kwon 1:c47c255fcad4 9 #include "SSD1306.h"
justinkim 0:fa775d326f9c 10
justinkim 0:fa775d326f9c 11 #define MAC "\x00\x08\xDC\x11\x34\x78"
Ricky_Kwon 1:c47c255fcad4 12 #define IP "192.168.0.20"
justinkim 0:fa775d326f9c 13 #define MASK "255.255.255.0"
Ricky_Kwon 1:c47c255fcad4 14 #define GATEWAY "192.168.0.1"
justinkim 0:fa775d326f9c 15
Ricky_Kwon 1:c47c255fcad4 16 #define FTP_SERVER_IP "192.168.0.10"
justinkim 0:fa775d326f9c 17
justinkim 0:fa775d326f9c 18 #define _MAX_FNAME_LEN_ 127
Ricky_Kwon 1:c47c255fcad4 19 #define _FTP_UPDATE_TIME_ 10
justinkim 0:fa775d326f9c 20
justinkim 0:fa775d326f9c 21
justinkim 0:fa775d326f9c 22 Serial uart(USBTX, USBRX);
Ricky_Kwon 1:c47c255fcad4 23 AnalogIn ain(A5);
justinkim 0:fa775d326f9c 24 //SDFileSystem sd(p5, p6, p7, p8, "sd"); // LPC1768 MBD2PMD
justinkim 0:fa775d326f9c 25 //SDFileSystem sd(P0_18, P0_17, P0_15, P0_16, "sd"); // Seeeduino Arch Pro SPI2SD
justinkim 0:fa775d326f9c 26 //SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // K64F
justinkim 0:fa775d326f9c 27 //SDFileSystem sd(PB_3, PB_2, PB_1, PB_0, "sd"); // WIZwiki-W7500
justinkim 0:fa775d326f9c 28
justinkim 0:fa775d326f9c 29 EthernetInterface eth;
justinkim 0:fa775d326f9c 30 InterruptIn K_VU(D3); // Create the interrupt receiver object on pin 26
justinkim 0:fa775d326f9c 31 InterruptIn K_VD(D7); // Create the interrupt receiver object on pin 26
justinkim 0:fa775d326f9c 32 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.
justinkim 0:fa775d326f9c 33
justinkim 0:fa775d326f9c 34 FTPClient myFTP("/sdc"); // mountname in MySeeedStudioTFTv2
justinkim 0:fa775d326f9c 35
Ricky_Kwon 1:c47c255fcad4 36 //Ticker ledTick;
justinkim 0:fa775d326f9c 37
justinkim 0:fa775d326f9c 38 /* Global Variables to store Status*/
justinkim 0:fa775d326f9c 39 int new_song_number=1; //Variable to store the Song Number
justinkim 0:fa775d326f9c 40 int volume_set=-20; //Variable to store the Volume
justinkim 0:fa775d326f9c 41 int previous_volume; //Variable to store the volume when muted
justinkim 0:fa775d326f9c 42 bool pause=false; //Variable to store the status of Pause button
justinkim 0:fa775d326f9c 43 bool mute=false; //Variable to store the status of mute button
justinkim 0:fa775d326f9c 44
justinkim 0:fa775d326f9c 45 int check=0; //Capacitative touch generates interrupt on both press and release. This variable tracks this and updates only on press.
Ricky_Kwon 1:c47c255fcad4 46 //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
justinkim 0:fa775d326f9c 47
justinkim 0:fa775d326f9c 48 uint32_t ftp_time_1s = 0;
justinkim 0:fa775d326f9c 49
justinkim 0:fa775d326f9c 50 char myfilelist[MAX_SS] = {0,};
justinkim 0:fa775d326f9c 51
Ricky_Kwon 1:c47c255fcad4 52 /*void ledTickfunc()
justinkim 0:fa775d326f9c 53 {
justinkim 0:fa775d326f9c 54 if(ftp_time_1s)
justinkim 0:fa775d326f9c 55 {
Ricky_Kwon 1:c47c255fcad4 56 //printf("enter ftp_time_1s:%d\r\n", ftp_time_1s);
justinkim 0:fa775d326f9c 57 if(ftp_time_1s++ > _FTP_UPDATE_TIME_) ftp_time_1s = 0;
justinkim 0:fa775d326f9c 58 }
Ricky_Kwon 1:c47c255fcad4 59 }*/
justinkim 0:fa775d326f9c 60 void Volume_Up()
justinkim 0:fa775d326f9c 61 {
justinkim 0:fa775d326f9c 62 volume_set+=3; // Volume Up
justinkim 0:fa775d326f9c 63 if(volume_set>=0)
justinkim 0:fa775d326f9c 64 volume_set=0;
justinkim 0:fa775d326f9c 65 }
Ricky_Kwon 1:c47c255fcad4 66
justinkim 0:fa775d326f9c 67 void Volume_Down()
justinkim 0:fa775d326f9c 68 {
justinkim 0:fa775d326f9c 69 volume_set-=3; //Volume Down
justinkim 0:fa775d326f9c 70 if(volume_set<-55)
justinkim 0:fa775d326f9c 71 volume_set=-55;
justinkim 0:fa775d326f9c 72 }
justinkim 0:fa775d326f9c 73 int main (void)
justinkim 0:fa775d326f9c 74 {
justinkim 0:fa775d326f9c 75 *(volatile uint32_t *)(0x41001014) = 0x0060100;
justinkim 0:fa775d326f9c 76 *(volatile uint32_t *)(0x41003000) = 0x10;
justinkim 0:fa775d326f9c 77 *(volatile uint32_t *)(0x41003004) = 0x10;
justinkim 0:fa775d326f9c 78 *(volatile uint32_t *)(0x41003008) = 0x10;
justinkim 0:fa775d326f9c 79 *(volatile uint32_t *)(0x41003080) = 0x10;
justinkim 0:fa775d326f9c 80 *(volatile uint32_t *)(0x41003098) = 0x10;
justinkim 0:fa775d326f9c 81
Ricky_Kwon 1:c47c255fcad4 82 unsigned int update_count_s=6;
Ricky_Kwon 1:c47c255fcad4 83 unsigned int update_count_ms=0;
Ricky_Kwon 1:c47c255fcad4 84 unsigned int ain_temp=0;
Ricky_Kwon 1:c47c255fcad4 85 //char* my_text = "GIF2015";
Ricky_Kwon 1:c47c255fcad4 86 /*char* tok = NULL;
justinkim 0:fa775d326f9c 87 char* lasts = NULL;
justinkim 0:fa775d326f9c 88 char filename[_MAX_FNAME_LEN_];
Ricky_Kwon 1:c47c255fcad4 89 FILE* fp;*/
justinkim 0:fa775d326f9c 90
Ricky_Kwon 1:c47c255fcad4 91 init();
Ricky_Kwon 1:c47c255fcad4 92 cls();
Ricky_Kwon 1:c47c255fcad4 93 //OLED_DrawBMP(0,0,128,8,(unsigned char *)GIF2015);
Ricky_Kwon 1:c47c255fcad4 94 //OLED_ShowStr(0,0,my_text,2);
Ricky_Kwon 1:c47c255fcad4 95 OLED_DrawBMP(0,0,128,8,(unsigned char *)wiznet);
Ricky_Kwon 1:c47c255fcad4 96 //LED_P23x32Str(0, 0, my_text);
justinkim 0:fa775d326f9c 97 // Serial Interface eth;
justinkim 0:fa775d326f9c 98 uart.baud(115200);
justinkim 0:fa775d326f9c 99 uart.printf("Initializing\r\n");
justinkim 0:fa775d326f9c 100
justinkim 0:fa775d326f9c 101 // EthernetInterface eth;
justinkim 0:fa775d326f9c 102 uart.printf("Initializing Ethernet\r\n");
justinkim 0:fa775d326f9c 103
justinkim 0:fa775d326f9c 104 //eth.init(); //Use DHCP
justinkim 0:fa775d326f9c 105 eth.init((uint8_t*)MAC,IP,MASK,GATEWAY); //IP,mask,Gateway
justinkim 0:fa775d326f9c 106 uart.printf("Connecting\r\n");
justinkim 0:fa775d326f9c 107 eth.connect();
justinkim 0:fa775d326f9c 108 uart.printf("IP Address is %s\r\n", eth.getIPAddress());
justinkim 0:fa775d326f9c 109
justinkim 0:fa775d326f9c 110 // Check File System
justinkim 0:fa775d326f9c 111 uart.printf("Checking File System\r\n");
justinkim 0:fa775d326f9c 112 DIR *d = opendir("/sdc/");
justinkim 0:fa775d326f9c 113 if (d != NULL) {
justinkim 0:fa775d326f9c 114 uart.printf("SD Card Present\r\n");
justinkim 0:fa775d326f9c 115 closedir(d);
justinkim 0:fa775d326f9c 116 } else {
justinkim 0:fa775d326f9c 117 uart.printf("SD Card Root Directory Not Found\r\n");
justinkim 0:fa775d326f9c 118 }
justinkim 0:fa775d326f9c 119
Ricky_Kwon 1:c47c255fcad4 120 //ledTick.attach(&ledTickfunc,2);
Ricky_Kwon 1:c47c255fcad4 121 /* UI Button setup */
Ricky_Kwon 1:c47c255fcad4 122 K_VU.fall(&Volume_Up);
Ricky_Kwon 1:c47c255fcad4 123 K_VU.mode(PullUp);
Ricky_Kwon 1:c47c255fcad4 124 K_VD.fall(&Volume_Down);
Ricky_Kwon 1:c47c255fcad4 125 K_VD.mode(PullUp);
Ricky_Kwon 1:c47c255fcad4 126
justinkim 0:fa775d326f9c 127 while(1)
justinkim 0:fa775d326f9c 128 {
Ricky_Kwon 1:c47c255fcad4 129 update_count_ms++;
Ricky_Kwon 1:c47c255fcad4 130 if(update_count_ms>5000)
Ricky_Kwon 1:c47c255fcad4 131 {
Ricky_Kwon 1:c47c255fcad4 132 printf("update_count_ms count : %d\r\n", update_count_s);
Ricky_Kwon 1:c47c255fcad4 133 update_count_ms=0;
Ricky_Kwon 1:c47c255fcad4 134 update_count_s++;
Ricky_Kwon 1:c47c255fcad4 135 }
Ricky_Kwon 1:c47c255fcad4 136 //printf("ftp_time_1s:%d\r\n", ftp_time_1s);
Ricky_Kwon 1:c47c255fcad4 137 //if(ftp_time_1s == 0)
Ricky_Kwon 1:c47c255fcad4 138 if(update_count_s>=5)
justinkim 0:fa775d326f9c 139 {
justinkim 0:fa775d326f9c 140 //Configure the display driver
Ricky_Kwon 1:c47c255fcad4 141 update_count_s = 0;
justinkim 0:fa775d326f9c 142
justinkim 0:fa775d326f9c 143 printf(" UPDATING MP3\r\n");
justinkim 0:fa775d326f9c 144 printf("==================\n\r\n");
justinkim 0:fa775d326f9c 145
Ricky_Kwon 1:c47c255fcad4 146 if(myFTP.open("192.168.0.10", 21, "user", "pass"))
justinkim 0:fa775d326f9c 147 {
justinkim 0:fa775d326f9c 148 printf("Connect Success to FTPServer\r\n");
justinkim 0:fa775d326f9c 149 printf("Connected to FTP Server\r\n");
Ricky_Kwon 1:c47c255fcad4 150
Ricky_Kwon 1:c47c255fcad4 151 myFTP.getfile("1.mp3");
Ricky_Kwon 1:c47c255fcad4 152 myFTP.getfile("2.mp3");
Ricky_Kwon 1:c47c255fcad4 153 myFTP.getfile("3.mp3");
Ricky_Kwon 1:c47c255fcad4 154
justinkim 0:fa775d326f9c 155 printf("\n UPDATE DONE\n\r\n");
justinkim 0:fa775d326f9c 156 myFTP.quit();
justinkim 0:fa775d326f9c 157 }
justinkim 0:fa775d326f9c 158 else
justinkim 0:fa775d326f9c 159 {
justinkim 0:fa775d326f9c 160 printf(" Can't connect to FTP Server\r\n");
justinkim 0:fa775d326f9c 161 printf(" UPDATE FAIL\r\n");
justinkim 0:fa775d326f9c 162 }
justinkim 0:fa775d326f9c 163 printf("==================\n");
justinkim 0:fa775d326f9c 164 }
justinkim 0:fa775d326f9c 165
justinkim 0:fa775d326f9c 166 /*============================================================
justinkim 0:fa775d326f9c 167 * MP3 Initialising
justinkim 0:fa775d326f9c 168 *==========================================================*/
justinkim 0:fa775d326f9c 169
justinkim 0:fa775d326f9c 170 mp3._RST = 1;
justinkim 0:fa775d326f9c 171 mp3.cs_high(); //chip disabled
justinkim 0:fa775d326f9c 172 mp3.sci_initialise(); //initialise MBED
justinkim 0:fa775d326f9c 173 mp3.sci_write(0x00,(SM_SDINEW+SM_STREAM+SM_DIFF));
justinkim 0:fa775d326f9c 174 mp3.sci_write(0x03, 0x9800);
justinkim 0:fa775d326f9c 175 mp3.sdi_initialise();
justinkim 0:fa775d326f9c 176
Ricky_Kwon 1:c47c255fcad4 177 ain_temp = ain.read_u16();
Ricky_Kwon 1:c47c255fcad4 178 //printf("normalized: %d \n\r", ain_temp);
justinkim 0:fa775d326f9c 179
Ricky_Kwon 1:c47c255fcad4 180 if (ain_temp>3000)
justinkim 0:fa775d326f9c 181 {
Ricky_Kwon 1:c47c255fcad4 182 printf("enter song\r\n");
justinkim 0:fa775d326f9c 183 mp3.play_song(new_song_number);
justinkim 0:fa775d326f9c 184 }
justinkim 0:fa775d326f9c 185 }
justinkim 0:fa775d326f9c 186 }