a
Dependencies: HTTPClient SDFileSystemA SeeedStudioTFTv2 TFT_fonts WIZnet_Library mbed
Fork of Seeed_TFT_Touch_Shield by
Diff: main.cpp
- Revision:
- 6:12f28bac9400
- Parent:
- 5:9fc620b1378a
diff -r 9fc620b1378a -r 12f28bac9400 main.cpp --- a/main.cpp Sat Aug 15 05:12:06 2015 +0000 +++ b/main.cpp Sat Aug 15 21:14:53 2015 +0000 @@ -29,10 +29,6 @@ //HW Touch lcd library #include "SeeedStudioTFTv2.h" -//HW&SW SDFilsystem library -#include "SDFileSystem.h" -SDFileSystem sd(D11,D12,D13,D4, "sd"); - //SW Font library #include "Arial12x12.h" #include "Arial24x23.h" @@ -41,13 +37,17 @@ //SW HTTPClient library #include "HTTPClient.h" +// +#include "SDFileSystem.h" +//SDFileSystem sd(D11,D12,D13,D4, "sdc"); /*Port define and initialize*/ //Define W5500 port and initialization SPI spi(D11,D12,D13); -WIZnetInterface ethernet(&spi,D10,D0); +WIZnetInterface ethernet(&spi,D10,D15); +#include "MySeeedStudioTFTv2.h" //Define TFT LCD port and initialization #define PIN_XP A3 @@ -61,22 +61,30 @@ #define PIN_DC_TFT D6 #define PIN_BL_TFT D7 #define PIN_CS_SD D4 -SeeedStudioTFTv2 TFT(PIN_XP, PIN_XM, PIN_YP, PIN_YM, PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TFT, PIN_DC_TFT, PIN_BL_TFT, PIN_CS_SD); +MySeeedStudioTFTv2 TFT(PIN_XP, PIN_XM, PIN_YP, PIN_YM, PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TFT, PIN_DC_TFT, PIN_BL_TFT, PIN_CS_SD); + +#include "typedefinition.h" //UART to USB initialization for debug message Serial pc(USBTX, USBRX); +Serial sound(PA_11,PA_12); + //Ethernet information pre definition const char * IP_Addr = "222.98.173.249"; const char * IP_Subnet = "255.255.255.192"; const char * IP_Gateway = "222.98.173.254"; unsigned char MAC_Addr[6] = {0x00,0x08,0xDC,0x12,0x34,0x56}; +void SndPlay(int TrackNumber); +void Sndvol(unsigned char updn); +void basicDisplay(void); +void weatherDisplay(void); + int main() { //Set baudrate of "U2U" pc.baud(115200); - //Configure the display driver TFT.background(Black); TFT.foreground(White); @@ -88,7 +96,7 @@ TFT.printf(" Application Start.\n"); //Ethernet configuration mbed_mac_address((char *)MAC_Addr); - int ret = ethernet.init(MAC_Addr,IP_Addr,IP_Subnet,IP_Gateway); + int ret = ethernet.init(MAC_Addr); if (!ret) { TFT.printf(" Ethernet Initialized\n MAC: %s\n", ethernet.getMACAddress()); ret = ethernet.connect(); @@ -103,48 +111,15 @@ TFT.printf(" Error ethernet.init() - ret = %d\r\n", ret); exit(0); } - wait(0.5); - - //HTTPClient http; -// -// char str[8192]; -// char get_msg[256]= ""; -// -// sprintf(get_msg,"http://www.kma.go.kr/wid/queryDFS.jsp?gridx=59&gridy=127"); -// -// ret = http.get(get_msg, str, sizeof(str),0); -// -// if(ret == HTTP_OK) -// { -// TFT.printf(" HTTP_OK\r\n"); -// } -// else -// { -// TFT.printf("error code: %d\r\n",ret); -// } -// char *startAddr; -// startAddr = strstr(str,"<tm>"); -// if(startAddr == 0) -// { -// TFT.printf("There is no data.\r\n"); -// } -// else -// { -// strncpy(get_msg,startAddr+4,12); -// *(get_msg+12) = 0; -// TFT.printf("%s",get_msg); -// } TFT.cls(); - FILE *fp; - fp = fopen("/sd/Weather_Icons_02.bmp","r"); - fseek(fp, 0, SEEK_SET); - TFT.BMP_16(100,100,fp); - printf("1234567890"); + basicDisplay(); + wait(20); + weatherDisplay(); while(1) { } //point p; -// +// d // while(1) // { // TFT.getPixel(p); @@ -165,3 +140,104 @@ // } } + +void SndPlay(int TrackNumber) +{ + char tempBuffer[50]; + sprintf(tempBuffer,"play,%04d,$",TrackNumber); + sound.printf("%s",tempBuffer); + pc.printf("%s",tempBuffer); +} + +void SndVol(unsigned char updn) +{ + if(updn) + sound.printf("vol+$"); + else + sound.printf("vol-$"); +} + +void basicDisplay(void) +{ + TFT.locate(0,80); + TFT.set_font((unsigned char*) Neu42x35); + TFT.printf(" 15.08.09\n"); + TFT.printf(" 21:08\n\n"); + TFT.set_font((unsigned char*) Arial28x28); + TFT.printf(" 29'C 57/100"); +} + +void weatherDisplay(void) +{ + TFT.background(White); + TFT.foreground(Black); + TFT.cls(); + int ret=0; + char str[8192]; + char get_msg[256]= ""; + char *CurrentAddr=0; + kmaWid kwid[5]; + + HTTPClient http; + sprintf(get_msg,"http://www.kma.go.kr/wid/queryDFS.jsp?gridx=60&gridy=127"); + ret = http.get(get_msg, str, sizeof(str),0); + char tempBufferForParser[50]; + + for(int i = 0 ; i < 5 ; i++) + { + sprintf(tempBufferForParser,"<data seq=\"%d\">",i); + CurrentAddr = strstr(str,tempBufferForParser); + CurrentAddr = strstr(CurrentAddr,"<hour>"); + if((*(CurrentAddr+7)) == '<'){ + kwid[i].hour[0] = *(CurrentAddr+6); + kwid[i].hour[1] = 0; + kwid[i].hour[2] = 0; + } + else{ + kwid[i].hour[0] = *(CurrentAddr+6); + kwid[i].hour[1] = *(CurrentAddr+7); + kwid[i].hour[2] = 0; + } + pc.printf("hour:%s \r\n",kwid[i].hour); + CurrentAddr = strstr(CurrentAddr,"<temp>"); + memcpy(kwid[i].temperature,(CurrentAddr+6),4); + kwid[i].temperature[4]=0; + pc.printf("temp:%s \r\n",kwid[i].temperature); + CurrentAddr = strstr(CurrentAddr,"<sky>"); + kwid[i].sky = *(CurrentAddr+5); + pc.printf("sky:%c \r\n",kwid[i].sky); + } + char tempBuffer[50]; + sprintf(tempBuffer,"/sdc/%c.bmp",kwid[0].sky); + FILE *fp; + fp = fopen(tempBuffer,"r"); + TFT.cls(); + TFT.DrawBitmapFile(20,40,fp); + fclose(fp); + TFT.locate(0,0); + TFT.set_font((unsigned char*) Arial24x23); + TFT.printf("Seoul"); + TFT.set_font((unsigned char*) Neu42x35); + TFT.locate(0,240); + TFT.printf(" %s'C",kwid[0].temperature); + switch(kwid[0].sky) + { + case '1': + SndPlay(1); + break; + case '2': + case '3': + case '4': + SndPlay(2); + break; + case '5': + SndPlay(3); + break; + case '6': + case '7': + SndPlay(4); + break; + default: + break; + } +} \ No newline at end of file