a

Dependencies:   HTTPClient SDFileSystemA SeeedStudioTFTv2 TFT_fonts WIZnet_Library mbed

Fork of Seeed_TFT_Touch_Shield by Bohyun Bang

Files at this revision

API Documentation at this revision

Comitter:
bangbh
Date:
Sat Aug 15 21:14:53 2015 +0000
Parent:
5:9fc620b1378a
Commit message:
A

Changed in this revision

MySeeedStudioTFTv2.cpp Show annotated file Show diff for this revision Revisions of this file
MySeeedStudioTFTv2.h Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
SeeedStudioTFTv2.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
typedefinition.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MySeeedStudioTFTv2.cpp	Sat Aug 15 21:14:53 2015 +0000
@@ -0,0 +1,141 @@
+/* mbed library for resistive touch pads
+ * uses 4 pins - 2 IO and 2 Analog
+
+ * c 2011 Peter Drescher - DC2PD
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+
+#include "mbed.h"
+#include "MySeeedStudioTFTv2.h"
+
+//#define TFT_DEBUG
+
+#ifdef TFT_DEBUG
+extern Serial pc;
+#endif
+
+
+MySeeedStudioTFTv2::MySeeedStudioTFTv2(PinName xp, PinName xm, PinName yp, PinName ym,
+                     PinName mosi, PinName miso, PinName sclk,
+                     PinName csTft, PinName dcTft, PinName blTft,
+                     PinName csSd) : SeeedStudioTFTv2(xp,xm,yp,ym,mosi,miso,sclk,csTft,dcTft,blTft,csSd)
+{
+    SeeedStudioTFTv2::SPI_TFT_ILI9341::_spi.frequency(24000000);
+    SeeedStudioTFTv2::SDFileSystem::_spi.frequency(24000000);     
+}
+
+int MySeeedStudioTFTv2::DrawBitmapFile(unsigned char x, unsigned char y, FILE * fp)
+{
+   
+    char img[3*240];
+    uint32_t imgsize = 0;
+    uint32_t offset = 0;
+    uint32_t imgw = 0;
+    uint32_t imgh = 0;
+    char colbits = 0;
+    char compress = 0;
+    uint16_t col;
+
+    int i, j;
+ 
+    if(fp == NULL) return -1;
+    if(fgetc(fp) != 0x42) return -2;
+    if(fgetc(fp) != 0x4D) return -2;
+
+    for(i = 0; i < 4; i++)
+    {
+        imgsize += (((uint32_t)fgetc(fp)) << i*8);
+    }
+#ifdef TFT_DEBUG
+    pc.printf("BMP SIZE:%d\r\n",imgsize);
+#endif
+    fseek(fp,4,SEEK_CUR);
+    for(i = 0; i < 4; i++)
+    {
+        offset += (((uint32_t)fgetc(fp)) << i*8);
+    }
+#ifdef TFT_DEBUG    
+    pc.printf("BMP OFFSET:%d\r\n",offset);
+#endif
+    fseek(fp,4,SEEK_CUR);
+    for(i = 0; i < 4; i++)
+    {
+        imgw += (((uint32_t)fgetc(fp)) << i*8);
+    }
+    if(imgw > 240) return -3;
+    
+    for(i = 0; i < 4; i++)
+    {
+        imgh += (((uint32_t)fgetc(fp)) << i*8);
+    }
+    if(imgh > 320) return -3;
+    
+    fseek(fp,2,SEEK_CUR);
+    colbits = fgetc(fp);
+    //if(colbits != 16 || colbits != 24) return -4;
+    fgetc(fp);
+    if((compress=fgetc(fp)) != 0)
+    {
+    #ifdef TFT_DEBUG    
+        pc.printf("Not supported compress : %d\r\n",compress);
+    #endif
+        return -4;    
+    }
+    
+
+#ifdef TFT_DEBUG    
+    pc.printf("RESOL : %d col, %d X %d",colbits,imgw,imgh);
+#endif    
+    
+    fseek(fp, offset, SEEK_SET);
+    for (j = imgh-1; j >= 0; j--)        //Lines bottoms up
+    {  
+        fread(img,sizeof(char),imgw*3,fp);
+        window(x, j+y, imgw, 1);    
+        window(x, j+y, imgw, 1); 
+        wr_cmd(0x2C);  // send pixel
+    #ifndef TARGET_KL25Z  // 16 Bit SPI 
+        SeeedStudioTFTv2::SPI_TFT_ILI9341::_spi.format(16,3);
+    #endif                            // switch to 16 bit Mode 3
+
+        for(i = 0; i < imgw; i++)
+        {
+/*            if(colbits == 16)
+            {
+                col = (uint16_t)img[2*i+1];
+                col <<= 8;
+                col += (uint16_t)img[2*i];
+            }
+            else if(colbits == 24) */
+            {
+                col = RGB((uint16_t)img[3*i+2],(uint16_t)img[3*i+1], (uint16_t)img[3*i]);
+            }
+        #ifdef TFT_DEBUG    
+            //pc.printf("RGB(%d): (%d,%d,%d) -> %04X\r\n ",i,img[3*i+2],img[3*i+1],img[3*i],col);
+        #endif    
+
+        #ifdef TAGET_KL25Z
+            SeeedStudioTFTv2::SPI_TFT_ILI9341::_spi.write((char)(col>>8));
+            SeeedStudioTFTv2::SPI_TFT_ILI9341::_spi.write((char)col);
+        #else
+           SeeedStudioTFTv2::SPI_TFT_ILI9341::_spi.write(col);
+        #endif
+        }
+        SeeedStudioTFTv2::SPI_TFT_ILI9341::_cs = 1;
+        #ifndef TARGET_KL25Z  // 16 Bit SPI 
+            SeeedStudioTFTv2::SPI_TFT_ILI9341::_spi.format(8,3);
+        #endif
+ 
+    }
+    WindowMax();
+    
+    return 0;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MySeeedStudioTFTv2.h	Sat Aug 15 21:14:53 2015 +0000
@@ -0,0 +1,47 @@
+/* mbed library for touchscreen connected to 4 mbed pins
+ * derive from SPI_TFT lib
+ * Copyright (c) 2011 Peter Drescher - DC2PD
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef MYMBED_TOUCH_H
+#define MYMBED_TOUCH_H
+
+#include "mbed.h"
+
+#include "SeeedStudioTFTv2.h"
+#ifndef USE_SDCARD
+#error "Shoud be defined USE_SDCARD in SeeedStudioTFTv2.0.h
+#endif
+
+
+class MySeeedStudioTFTv2 : public SeeedStudioTFTv2
+{
+public:
+    /** create a TFT with touch object connected to the pins:
+     *
+     * @param pin xp resistiv touch x+
+     * @param pin xm resistiv touch x-
+     * @param pin yp resistiv touch y+
+     * @param pin ym resistiv touch y-
+     * @param mosi,miso,sclk SPI connection to TFT
+     * @param cs pin connected to CS of display
+     * @param reset pin connected to RESET of display
+     * based on my SPI_TFT lib
+     */
+    MySeeedStudioTFTv2(PinName xp, PinName xm, PinName yp, PinName ym,
+                     PinName mosi, PinName miso, PinName sclk,
+                     PinName csTft, PinName dcTft, PinName blTft,
+                     PinName csSd);
+
+    int DrawBitmapFile(unsigned char x, unsigned char y, FILE * fp);
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Sat Aug 15 21:14:53 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/bangbh/code/SDFileSystemA/#ae027b79c156
--- a/SeeedStudioTFTv2.lib	Sat Aug 15 05:12:06 2015 +0000
+++ b/SeeedStudioTFTv2.lib	Sat Aug 15 21:14:53 2015 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/users/bangbh/code/SeeedStudioTFTv2/#2b2929d22714
+https://developer.mbed.org/users/MidnightCow/code/SeeedStudioTFTv2/#1ed8ed0c17cd
--- 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
--- a/mbed.bld	Sat Aug 15 05:12:06 2015 +0000
+++ b/mbed.bld	Sat Aug 15 21:14:53 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/e188a91d3eaa
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/bad568076d81
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/typedefinition.h	Sat Aug 15 21:14:53 2015 +0000
@@ -0,0 +1,6 @@
+typedef struct
+{
+    char temperature[5];
+    char sky;
+    char hour[3];
+}kmaWid;