a
Dependencies: HTTPClient SeeedStudioTFTv2 TFT_fonts WIZnet_Library mbed
Fork of Seeed_TFT_Touch_Shield by
main.cpp@5:9fc620b1378a, 2015-08-15 (annotated)
- Committer:
- bangbh
- Date:
- Sat Aug 15 05:12:06 2015 +0000
- Revision:
- 5:9fc620b1378a
- Parent:
- 2:5c2f6ff36ff1
a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lawliet | 1:b2794eb7c940 | 1 | /* |
lawliet | 1:b2794eb7c940 | 2 | main.cpp |
lawliet | 1:b2794eb7c940 | 3 | 2014 Copyright (c) Seeed Technology Inc. All right reserved. |
lawliet | 1:b2794eb7c940 | 4 | |
lawliet | 1:b2794eb7c940 | 5 | Author:lawliet zou(lawliet.zou@gmail.com) |
lawliet | 1:b2794eb7c940 | 6 | 2014-02-17 |
lawliet | 1:b2794eb7c940 | 7 | |
lawliet | 1:b2794eb7c940 | 8 | This library is free software; you can redistribute it and/or |
lawliet | 1:b2794eb7c940 | 9 | modify it under the terms of the GNU Lesser General Public |
lawliet | 1:b2794eb7c940 | 10 | License as published by the Free Software Foundation; either |
lawliet | 1:b2794eb7c940 | 11 | version 2.1 of the License, or (at your option) any later version. |
lawliet | 1:b2794eb7c940 | 12 | |
lawliet | 1:b2794eb7c940 | 13 | This library is distributed in the hope that it will be useful, |
lawliet | 1:b2794eb7c940 | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
lawliet | 1:b2794eb7c940 | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
lawliet | 1:b2794eb7c940 | 16 | Lesser General Public License for more details. |
lawliet | 1:b2794eb7c940 | 17 | |
lawliet | 1:b2794eb7c940 | 18 | You should have received a copy of the GNU Lesser General Public |
lawliet | 1:b2794eb7c940 | 19 | License along with this library; if not, write to the Free Software |
lawliet | 1:b2794eb7c940 | 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
lawliet | 1:b2794eb7c940 | 21 | */ |
bangbh | 5:9fc620b1378a | 22 | /*include library*/ |
bangbh | 5:9fc620b1378a | 23 | //mbed library |
neilt6 | 0:407dafce805d | 24 | #include "mbed.h" |
bangbh | 5:9fc620b1378a | 25 | |
bangbh | 5:9fc620b1378a | 26 | //HW W5500 library |
bangbh | 5:9fc620b1378a | 27 | #include "WIZnetInterface.h" |
bangbh | 5:9fc620b1378a | 28 | |
bangbh | 5:9fc620b1378a | 29 | //HW Touch lcd library |
neilt6 | 0:407dafce805d | 30 | #include "SeeedStudioTFTv2.h" |
bangbh | 5:9fc620b1378a | 31 | |
bangbh | 5:9fc620b1378a | 32 | //HW&SW SDFilsystem library |
bangbh | 5:9fc620b1378a | 33 | #include "SDFileSystem.h" |
bangbh | 5:9fc620b1378a | 34 | SDFileSystem sd(D11,D12,D13,D4, "sd"); |
bangbh | 5:9fc620b1378a | 35 | |
bangbh | 5:9fc620b1378a | 36 | //SW Font library |
neilt6 | 0:407dafce805d | 37 | #include "Arial12x12.h" |
neilt6 | 0:407dafce805d | 38 | #include "Arial24x23.h" |
neilt6 | 0:407dafce805d | 39 | #include "Arial28x28.h" |
neilt6 | 0:407dafce805d | 40 | #include "font_big.h" |
neilt6 | 0:407dafce805d | 41 | |
bangbh | 5:9fc620b1378a | 42 | //SW HTTPClient library |
bangbh | 5:9fc620b1378a | 43 | #include "HTTPClient.h" |
bangbh | 5:9fc620b1378a | 44 | |
bangbh | 5:9fc620b1378a | 45 | /*Port define and initialize*/ |
bangbh | 5:9fc620b1378a | 46 | |
bangbh | 5:9fc620b1378a | 47 | //Define W5500 port and initialization |
bangbh | 5:9fc620b1378a | 48 | SPI spi(D11,D12,D13); |
bangbh | 5:9fc620b1378a | 49 | WIZnetInterface ethernet(&spi,D10,D0); |
bangbh | 5:9fc620b1378a | 50 | |
bangbh | 5:9fc620b1378a | 51 | |
bangbh | 5:9fc620b1378a | 52 | //Define TFT LCD port and initialization |
screamer | 2:5c2f6ff36ff1 | 53 | #define PIN_XP A3 |
screamer | 2:5c2f6ff36ff1 | 54 | #define PIN_XM A1 |
screamer | 2:5c2f6ff36ff1 | 55 | #define PIN_YP A2 |
screamer | 2:5c2f6ff36ff1 | 56 | #define PIN_YM A0 |
screamer | 2:5c2f6ff36ff1 | 57 | #define PIN_MOSI D11 |
screamer | 2:5c2f6ff36ff1 | 58 | #define PIN_MISO D12 |
screamer | 2:5c2f6ff36ff1 | 59 | #define PIN_SCLK D13 |
screamer | 2:5c2f6ff36ff1 | 60 | #define PIN_CS_TFT D5 |
screamer | 2:5c2f6ff36ff1 | 61 | #define PIN_DC_TFT D6 |
screamer | 2:5c2f6ff36ff1 | 62 | #define PIN_BL_TFT D7 |
screamer | 2:5c2f6ff36ff1 | 63 | #define PIN_CS_SD D4 |
bangbh | 5:9fc620b1378a | 64 | 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); |
lawliet | 1:b2794eb7c940 | 65 | |
bangbh | 5:9fc620b1378a | 66 | //UART to USB initialization for debug message |
bangbh | 5:9fc620b1378a | 67 | Serial pc(USBTX, USBRX); |
bangbh | 5:9fc620b1378a | 68 | |
bangbh | 5:9fc620b1378a | 69 | //Ethernet information pre definition |
bangbh | 5:9fc620b1378a | 70 | const char * IP_Addr = "222.98.173.249"; |
bangbh | 5:9fc620b1378a | 71 | const char * IP_Subnet = "255.255.255.192"; |
bangbh | 5:9fc620b1378a | 72 | const char * IP_Gateway = "222.98.173.254"; |
bangbh | 5:9fc620b1378a | 73 | unsigned char MAC_Addr[6] = {0x00,0x08,0xDC,0x12,0x34,0x56}; |
neilt6 | 0:407dafce805d | 74 | |
neilt6 | 0:407dafce805d | 75 | int main() |
neilt6 | 0:407dafce805d | 76 | { |
bangbh | 5:9fc620b1378a | 77 | //Set baudrate of "U2U" |
bangbh | 5:9fc620b1378a | 78 | pc.baud(115200); |
bangbh | 5:9fc620b1378a | 79 | |
neilt6 | 0:407dafce805d | 80 | //Configure the display driver |
neilt6 | 0:407dafce805d | 81 | TFT.background(Black); |
neilt6 | 0:407dafce805d | 82 | TFT.foreground(White); |
neilt6 | 0:407dafce805d | 83 | TFT.cls(); |
bangbh | 5:9fc620b1378a | 84 | |
bangbh | 5:9fc620b1378a | 85 | //Application Start message |
neilt6 | 0:407dafce805d | 86 | TFT.set_font((unsigned char*) Arial12x12); |
neilt6 | 0:407dafce805d | 87 | TFT.locate(0,0); |
bangbh | 5:9fc620b1378a | 88 | TFT.printf(" Application Start.\n"); |
bangbh | 5:9fc620b1378a | 89 | //Ethernet configuration |
bangbh | 5:9fc620b1378a | 90 | mbed_mac_address((char *)MAC_Addr); |
bangbh | 5:9fc620b1378a | 91 | int ret = ethernet.init(MAC_Addr,IP_Addr,IP_Subnet,IP_Gateway); |
bangbh | 5:9fc620b1378a | 92 | if (!ret) { |
bangbh | 5:9fc620b1378a | 93 | TFT.printf(" Ethernet Initialized\n MAC: %s\n", ethernet.getMACAddress()); |
bangbh | 5:9fc620b1378a | 94 | ret = ethernet.connect(); |
bangbh | 5:9fc620b1378a | 95 | if (!ret) { |
bangbh | 5:9fc620b1378a | 96 | TFT.printf(" IP: %s\r\n MASK: %s\r\n GW: %s\r\n", |
bangbh | 5:9fc620b1378a | 97 | ethernet.getIPAddress(), ethernet.getNetworkMask(), ethernet.getGateway()); |
bangbh | 5:9fc620b1378a | 98 | } else { |
bangbh | 5:9fc620b1378a | 99 | TFT.printf(" Error ethernet.connect() - ret = %d\r\n", ret); |
bangbh | 5:9fc620b1378a | 100 | exit(0); |
bangbh | 5:9fc620b1378a | 101 | } |
bangbh | 5:9fc620b1378a | 102 | } else { |
bangbh | 5:9fc620b1378a | 103 | TFT.printf(" Error ethernet.init() - ret = %d\r\n", ret); |
bangbh | 5:9fc620b1378a | 104 | exit(0); |
bangbh | 5:9fc620b1378a | 105 | } |
bangbh | 5:9fc620b1378a | 106 | wait(0.5); |
neilt6 | 0:407dafce805d | 107 | |
bangbh | 5:9fc620b1378a | 108 | //HTTPClient http; |
bangbh | 5:9fc620b1378a | 109 | // |
bangbh | 5:9fc620b1378a | 110 | // char str[8192]; |
bangbh | 5:9fc620b1378a | 111 | // char get_msg[256]= ""; |
bangbh | 5:9fc620b1378a | 112 | // |
bangbh | 5:9fc620b1378a | 113 | // sprintf(get_msg,"http://www.kma.go.kr/wid/queryDFS.jsp?gridx=59&gridy=127"); |
bangbh | 5:9fc620b1378a | 114 | // |
bangbh | 5:9fc620b1378a | 115 | // ret = http.get(get_msg, str, sizeof(str),0); |
bangbh | 5:9fc620b1378a | 116 | // |
bangbh | 5:9fc620b1378a | 117 | // if(ret == HTTP_OK) |
bangbh | 5:9fc620b1378a | 118 | // { |
bangbh | 5:9fc620b1378a | 119 | // TFT.printf(" HTTP_OK\r\n"); |
bangbh | 5:9fc620b1378a | 120 | // } |
bangbh | 5:9fc620b1378a | 121 | // else |
bangbh | 5:9fc620b1378a | 122 | // { |
bangbh | 5:9fc620b1378a | 123 | // TFT.printf("error code: %d\r\n",ret); |
bangbh | 5:9fc620b1378a | 124 | // } |
bangbh | 5:9fc620b1378a | 125 | // char *startAddr; |
bangbh | 5:9fc620b1378a | 126 | // startAddr = strstr(str,"<tm>"); |
bangbh | 5:9fc620b1378a | 127 | // if(startAddr == 0) |
bangbh | 5:9fc620b1378a | 128 | // { |
bangbh | 5:9fc620b1378a | 129 | // TFT.printf("There is no data.\r\n"); |
bangbh | 5:9fc620b1378a | 130 | // } |
bangbh | 5:9fc620b1378a | 131 | // else |
bangbh | 5:9fc620b1378a | 132 | // { |
bangbh | 5:9fc620b1378a | 133 | // strncpy(get_msg,startAddr+4,12); |
bangbh | 5:9fc620b1378a | 134 | // *(get_msg+12) = 0; |
bangbh | 5:9fc620b1378a | 135 | // TFT.printf("%s",get_msg); |
bangbh | 5:9fc620b1378a | 136 | // } |
neilt6 | 0:407dafce805d | 137 | TFT.cls(); |
bangbh | 5:9fc620b1378a | 138 | FILE *fp; |
bangbh | 5:9fc620b1378a | 139 | fp = fopen("/sd/Weather_Icons_02.bmp","r"); |
bangbh | 5:9fc620b1378a | 140 | fseek(fp, 0, SEEK_SET); |
bangbh | 5:9fc620b1378a | 141 | TFT.BMP_16(100,100,fp); |
bangbh | 5:9fc620b1378a | 142 | printf("1234567890"); |
bangbh | 5:9fc620b1378a | 143 | while(1) |
bangbh | 5:9fc620b1378a | 144 | { |
bangbh | 5:9fc620b1378a | 145 | } |
bangbh | 5:9fc620b1378a | 146 | //point p; |
bangbh | 5:9fc620b1378a | 147 | // |
bangbh | 5:9fc620b1378a | 148 | // while(1) |
bangbh | 5:9fc620b1378a | 149 | // { |
bangbh | 5:9fc620b1378a | 150 | // TFT.getPixel(p); |
bangbh | 5:9fc620b1378a | 151 | // TFT.locate(0,100); |
bangbh | 5:9fc620b1378a | 152 | // TFT.printf("X: %6d, Y: %6d",p.x,p.y); |
bangbh | 5:9fc620b1378a | 153 | // } |
bangbh | 5:9fc620b1378a | 154 | // TFT.printf("msg : %s\r\n",get_msg); |
bangbh | 5:9fc620b1378a | 155 | // if(!ret) |
bangbh | 5:9fc620b1378a | 156 | // { |
bangbh | 5:9fc620b1378a | 157 | // TFT.printf("\r\nPage fetched successfully - read %d characters\r\n", strlen(str)); |
bangbh | 5:9fc620b1378a | 158 | // TFT.printf("Result: %s\r\n", str); |
bangbh | 5:9fc620b1378a | 159 | // } |
bangbh | 5:9fc620b1378a | 160 | // else |
bangbh | 5:9fc620b1378a | 161 | // { |
bangbh | 5:9fc620b1378a | 162 | // TFT.printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); |
bangbh | 5:9fc620b1378a | 163 | // } |
bangbh | 5:9fc620b1378a | 164 | // wait(20); |
bangbh | 5:9fc620b1378a | 165 | // } |
bangbh | 5:9fc620b1378a | 166 | |
neilt6 | 0:407dafce805d | 167 | } |