aaa
Dependencies: SeeedStudioTFTv2 TFT_fonts mbed
Fork of Seeed_TFT_Touch_Shield by
main.cpp@9:1efb9e26fbeb, 2014-10-26 (annotated)
- Committer:
- bhavk11
- Date:
- Sun Oct 26 00:56:52 2014 +0000
- Revision:
- 9:1efb9e26fbeb
- Parent:
- 8:5e8c0b37bcf9
recv
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 | */ |
lawliet | 1:b2794eb7c940 | 22 | |
neilt6 | 0:407dafce805d | 23 | #include "mbed.h" |
neilt6 | 0:407dafce805d | 24 | #include "SeeedStudioTFTv2.h" |
neilt6 | 0:407dafce805d | 25 | #include "Arial12x12.h" |
neilt6 | 0:407dafce805d | 26 | #include "Arial24x23.h" |
neilt6 | 0:407dafce805d | 27 | #include "Arial28x28.h" |
neilt6 | 0:407dafce805d | 28 | #include "font_big.h" |
neilt6 | 0:407dafce805d | 29 | |
screamer | 2:5c2f6ff36ff1 | 30 | #define PIN_XP A3 |
screamer | 2:5c2f6ff36ff1 | 31 | #define PIN_XM A1 |
screamer | 2:5c2f6ff36ff1 | 32 | #define PIN_YP A2 |
screamer | 2:5c2f6ff36ff1 | 33 | #define PIN_YM A0 |
screamer | 2:5c2f6ff36ff1 | 34 | #define PIN_MOSI D11 |
screamer | 2:5c2f6ff36ff1 | 35 | #define PIN_MISO D12 |
screamer | 2:5c2f6ff36ff1 | 36 | #define PIN_SCLK D13 |
screamer | 2:5c2f6ff36ff1 | 37 | #define PIN_CS_TFT D5 |
screamer | 2:5c2f6ff36ff1 | 38 | #define PIN_DC_TFT D6 |
screamer | 2:5c2f6ff36ff1 | 39 | #define PIN_BL_TFT D7 |
screamer | 2:5c2f6ff36ff1 | 40 | #define PIN_CS_SD D4 |
lawliet | 1:b2794eb7c940 | 41 | |
bhavk11 | 4:5b088ba4f1f1 | 42 | Timer t; |
bhavk11 | 4:5b088ba4f1f1 | 43 | Serial pc(USBTX,USBRX); |
screamer | 2:5c2f6ff36ff1 | 44 | 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); |
neilt6 | 0:407dafce805d | 45 | |
bhavk11 | 6:cd0294454118 | 46 | char ip0[] = {' ','0','+'}; |
bhavk11 | 6:cd0294454118 | 47 | char ip2[] = {'a','b','c','2'}; |
bhavk11 | 6:cd0294454118 | 48 | char ip3[] = {'d','e','f','3'}; |
bhavk11 | 6:cd0294454118 | 49 | char ip4[] = {'g','h','i','4'}; |
bhavk11 | 6:cd0294454118 | 50 | char ip5[] = {'j','k','l','5'}; |
bhavk11 | 6:cd0294454118 | 51 | char ip6[] = {'m','o','p','6'}; |
bhavk11 | 6:cd0294454118 | 52 | char ip7[] = {'p','q','r','s','7'}; |
bhavk11 | 6:cd0294454118 | 53 | char ip8[] = {'t','u','v','8'}; |
bhavk11 | 6:cd0294454118 | 54 | char ip9[] = {'w','x','y','z','9'}; |
bhavk11 | 6:cd0294454118 | 55 | |
bhavk11 | 8:5e8c0b37bcf9 | 56 | char* cmd = NULL; |
bhavk11 | 8:5e8c0b37bcf9 | 57 | |
bhavk11 | 4:5b088ba4f1f1 | 58 | void printKey(int x, int y, char* digit, char* alphas) |
bhavk11 | 4:5b088ba4f1f1 | 59 | { |
bhavk11 | 4:5b088ba4f1f1 | 60 | TFT.foreground(Blue); |
bhavk11 | 4:5b088ba4f1f1 | 61 | TFT.set_font((unsigned char*) Arial24x23); |
bhavk11 | 4:5b088ba4f1f1 | 62 | TFT.locate(x,y); |
bhavk11 | 4:5b088ba4f1f1 | 63 | TFT.printf(digit); |
bhavk11 | 4:5b088ba4f1f1 | 64 | TFT.foreground(Black); |
bhavk11 | 4:5b088ba4f1f1 | 65 | TFT.set_font((unsigned char*) Arial12x12); |
bhavk11 | 4:5b088ba4f1f1 | 66 | TFT.locate(x+15,y+10); |
bhavk11 | 4:5b088ba4f1f1 | 67 | TFT.printf(alphas); |
bhavk11 | 4:5b088ba4f1f1 | 68 | } |
bhavk11 | 4:5b088ba4f1f1 | 69 | |
bhavk11 | 4:5b088ba4f1f1 | 70 | void initKeypad() |
bhavk11 | 4:5b088ba4f1f1 | 71 | { |
bhavk11 | 4:5b088ba4f1f1 | 72 | TFT.background(White); |
bhavk11 | 4:5b088ba4f1f1 | 73 | TFT.cls(); |
bhavk11 | 4:5b088ba4f1f1 | 74 | TFT.foreground(Black); |
bhavk11 | 4:5b088ba4f1f1 | 75 | TFT.set_font((unsigned char*) Arial12x12); |
bhavk11 | 4:5b088ba4f1f1 | 76 | TFT.locate(210,84); |
bhavk11 | 4:5b088ba4f1f1 | 77 | TFT.printf("Del"); |
bhavk11 | 4:5b088ba4f1f1 | 78 | TFT.line(0,100,240,100,Black); |
bhavk11 | 4:5b088ba4f1f1 | 79 | TFT.rect(205,80,235,95,Black); |
bhavk11 | 4:5b088ba4f1f1 | 80 | TFT.line(205,80,195,95,White); |
bhavk11 | 4:5b088ba4f1f1 | 81 | TFT.line(192,87,205,80,Black); |
bhavk11 | 4:5b088ba4f1f1 | 82 | TFT.line(192,87,205,95,Black); |
bhavk11 | 4:5b088ba4f1f1 | 83 | printKey(20,120,"1"," "); |
bhavk11 | 4:5b088ba4f1f1 | 84 | printKey(95,120,"2","ABC"); |
bhavk11 | 4:5b088ba4f1f1 | 85 | printKey(170,120,"3","DEF"); |
bhavk11 | 4:5b088ba4f1f1 | 86 | printKey(20,160,"4","GHI"); |
bhavk11 | 4:5b088ba4f1f1 | 87 | printKey(95,160,"5","JKL"); |
bhavk11 | 4:5b088ba4f1f1 | 88 | printKey(170,160,"6","MNO"); |
bhavk11 | 4:5b088ba4f1f1 | 89 | printKey(20,200,"7","PQRS"); |
bhavk11 | 4:5b088ba4f1f1 | 90 | printKey(95,200,"8","TUV"); |
bhavk11 | 4:5b088ba4f1f1 | 91 | printKey(170,200,"9","WXYZ"); |
bhavk11 | 4:5b088ba4f1f1 | 92 | printKey(20,240,"*",""); |
bhavk11 | 4:5b088ba4f1f1 | 93 | printKey(95,240,"0","+"); |
bhavk11 | 4:5b088ba4f1f1 | 94 | printKey(170,240,"#",""); |
bhavk11 | 4:5b088ba4f1f1 | 95 | printKey(20,280,"<--",""); |
bhavk11 | 4:5b088ba4f1f1 | 96 | } |
bhavk11 | 4:5b088ba4f1f1 | 97 | |
bhavk11 | 4:5b088ba4f1f1 | 98 | int getKey() |
bhavk11 | 4:5b088ba4f1f1 | 99 | { |
bhavk11 | 4:5b088ba4f1f1 | 100 | int key = -1; |
bhavk11 | 4:5b088ba4f1f1 | 101 | point p; |
bhavk11 | 4:5b088ba4f1f1 | 102 | int count = 0; |
bhavk11 | 4:5b088ba4f1f1 | 103 | if(TFT.getTouch(p) == TFT.NO || TFT.getTouch(p) == TFT.MAYBE) |
bhavk11 | 4:5b088ba4f1f1 | 104 | { return key; |
bhavk11 | 4:5b088ba4f1f1 | 105 | } |
bhavk11 | 4:5b088ba4f1f1 | 106 | while(TFT.getTouch(p) == TFT.YES) |
bhavk11 | 4:5b088ba4f1f1 | 107 | { |
bhavk11 | 4:5b088ba4f1f1 | 108 | count++; |
bhavk11 | 4:5b088ba4f1f1 | 109 | } |
bhavk11 | 4:5b088ba4f1f1 | 110 | if(count > 300) |
bhavk11 | 4:5b088ba4f1f1 | 111 | { |
bhavk11 | 4:5b088ba4f1f1 | 112 | //TFT.foreground(Black); |
bhavk11 | 4:5b088ba4f1f1 | 113 | // TFT.set_font((unsigned char*) Arial12x12); |
bhavk11 | 4:5b088ba4f1f1 | 114 | // TFT.locate(0,0); |
bhavk11 | 4:5b088ba4f1f1 | 115 | // TFT.printf("X:%d, Y:%d\n\r",p.x,p.y); |
bhavk11 | 4:5b088ba4f1f1 | 116 | if (p.x>2700 && p.x<7250) |
bhavk11 | 4:5b088ba4f1f1 | 117 | { |
bhavk11 | 4:5b088ba4f1f1 | 118 | if(p.x<3750) |
bhavk11 | 4:5b088ba4f1f1 | 119 | { |
bhavk11 | 4:5b088ba4f1f1 | 120 | if(p.y<3000) |
bhavk11 | 4:5b088ba4f1f1 | 121 | key = 1; //1 |
bhavk11 | 4:5b088ba4f1f1 | 122 | else if(p.y<5250) |
bhavk11 | 4:5b088ba4f1f1 | 123 | key = 2; //2 |
bhavk11 | 4:5b088ba4f1f1 | 124 | else |
bhavk11 | 4:5b088ba4f1f1 | 125 | key = 3; //3 |
bhavk11 | 4:5b088ba4f1f1 | 126 | } |
bhavk11 | 4:5b088ba4f1f1 | 127 | else if(p.x<4600) |
bhavk11 | 4:5b088ba4f1f1 | 128 | { |
bhavk11 | 4:5b088ba4f1f1 | 129 | if(p.y<3000) |
bhavk11 | 4:5b088ba4f1f1 | 130 | key = 4; //4 |
bhavk11 | 4:5b088ba4f1f1 | 131 | else if(p.y<5250) |
bhavk11 | 4:5b088ba4f1f1 | 132 | key = 5; //5 |
bhavk11 | 4:5b088ba4f1f1 | 133 | else |
bhavk11 | 4:5b088ba4f1f1 | 134 | key = 6; //6 |
bhavk11 | 4:5b088ba4f1f1 | 135 | } |
bhavk11 | 4:5b088ba4f1f1 | 136 | else if(p.x<5400) |
bhavk11 | 4:5b088ba4f1f1 | 137 | { |
bhavk11 | 4:5b088ba4f1f1 | 138 | if(p.y<3000) |
bhavk11 | 4:5b088ba4f1f1 | 139 | key = 7; //7 |
bhavk11 | 4:5b088ba4f1f1 | 140 | else if(p.y<5250) |
bhavk11 | 4:5b088ba4f1f1 | 141 | key = 8; //8 |
bhavk11 | 4:5b088ba4f1f1 | 142 | else |
bhavk11 | 4:5b088ba4f1f1 | 143 | key = 9; //9 |
bhavk11 | 4:5b088ba4f1f1 | 144 | } |
bhavk11 | 4:5b088ba4f1f1 | 145 | else if(p.x<6300) |
bhavk11 | 4:5b088ba4f1f1 | 146 | { |
bhavk11 | 4:5b088ba4f1f1 | 147 | if(p.y<3000) |
bhavk11 | 4:5b088ba4f1f1 | 148 | key = 42; //* |
bhavk11 | 4:5b088ba4f1f1 | 149 | else if(p.y<5250) |
bhavk11 | 4:5b088ba4f1f1 | 150 | key = 0; //0 |
bhavk11 | 4:5b088ba4f1f1 | 151 | else |
bhavk11 | 4:5b088ba4f1f1 | 152 | key = 35; //# |
bhavk11 | 4:5b088ba4f1f1 | 153 | } |
bhavk11 | 4:5b088ba4f1f1 | 154 | else |
bhavk11 | 4:5b088ba4f1f1 | 155 | { |
bhavk11 | 4:5b088ba4f1f1 | 156 | if(p.y<3000) |
bhavk11 | 4:5b088ba4f1f1 | 157 | key = 60; // back |
bhavk11 | 4:5b088ba4f1f1 | 158 | else |
bhavk11 | 4:5b088ba4f1f1 | 159 | key = 43; // go (call/text) |
bhavk11 | 4:5b088ba4f1f1 | 160 | } |
bhavk11 | 4:5b088ba4f1f1 | 161 | } |
bhavk11 | 4:5b088ba4f1f1 | 162 | if(p.x > 2200 && p.x < 2500 && p.y > 6200 && p.y < 7000) |
bhavk11 | 4:5b088ba4f1f1 | 163 | key = 127; |
bhavk11 | 4:5b088ba4f1f1 | 164 | } |
bhavk11 | 4:5b088ba4f1f1 | 165 | return key; |
bhavk11 | 4:5b088ba4f1f1 | 166 | } |
bhavk11 | 4:5b088ba4f1f1 | 167 | |
bhavk11 | 4:5b088ba4f1f1 | 168 | bool displayChar(point& cursor, char letter) |
bhavk11 | 4:5b088ba4f1f1 | 169 | { |
bhavk11 | 4:5b088ba4f1f1 | 170 | TFT.locate(cursor.x,cursor.y); |
bhavk11 | 6:cd0294454118 | 171 | if(cursor.x + 12 <= 228) |
bhavk11 | 6:cd0294454118 | 172 | cursor.x += 12; |
bhavk11 | 4:5b088ba4f1f1 | 173 | else |
bhavk11 | 4:5b088ba4f1f1 | 174 | { |
bhavk11 | 4:5b088ba4f1f1 | 175 | cursor.x = 0; |
bhavk11 | 4:5b088ba4f1f1 | 176 | if(cursor.y + 21 <= 65 ) |
bhavk11 | 4:5b088ba4f1f1 | 177 | cursor.y += 21; |
bhavk11 | 4:5b088ba4f1f1 | 178 | else |
bhavk11 | 4:5b088ba4f1f1 | 179 | return false; |
bhavk11 | 4:5b088ba4f1f1 | 180 | } |
bhavk11 | 6:cd0294454118 | 181 | TFT.set_font((unsigned char*) Arial12x12); |
bhavk11 | 4:5b088ba4f1f1 | 182 | TFT.printf("%c",letter); |
bhavk11 | 4:5b088ba4f1f1 | 183 | return true; |
bhavk11 | 4:5b088ba4f1f1 | 184 | } |
bhavk11 | 4:5b088ba4f1f1 | 185 | |
bhavk11 | 7:11eb2c8df6a9 | 186 | int getAlpha(point& x, char** pt) |
bhavk11 | 6:cd0294454118 | 187 | { |
bhavk11 | 6:cd0294454118 | 188 | int touchCount = 1, count = 1; |
bhavk11 | 6:cd0294454118 | 189 | int key, begin, end; |
bhavk11 | 6:cd0294454118 | 190 | int prevKey; |
bhavk11 | 6:cd0294454118 | 191 | do { |
bhavk11 | 6:cd0294454118 | 192 | prevKey = key = getKey(); |
bhavk11 | 8:5e8c0b37bcf9 | 193 | }while(prevKey == -1 && strcmp(cmd, "Text") == 0); |
bhavk11 | 6:cd0294454118 | 194 | |
bhavk11 | 6:cd0294454118 | 195 | point cursor = x; |
bhavk11 | 7:11eb2c8df6a9 | 196 | char* ptr = *pt; |
bhavk11 | 6:cd0294454118 | 197 | t.reset(); |
bhavk11 | 6:cd0294454118 | 198 | t.start(); |
bhavk11 | 6:cd0294454118 | 199 | begin = t.read_ms(); |
bhavk11 | 6:cd0294454118 | 200 | end = t.read_ms(); |
bhavk11 | 6:cd0294454118 | 201 | while((end - begin) < 2000) |
bhavk11 | 6:cd0294454118 | 202 | { |
bhavk11 | 6:cd0294454118 | 203 | cursor = x; |
bhavk11 | 7:11eb2c8df6a9 | 204 | ptr = *pt; |
bhavk11 | 6:cd0294454118 | 205 | touchCount = count; |
bhavk11 | 7:11eb2c8df6a9 | 206 | START: |
bhavk11 | 6:cd0294454118 | 207 | switch(key) |
bhavk11 | 6:cd0294454118 | 208 | { |
bhavk11 | 6:cd0294454118 | 209 | case 0: |
bhavk11 | 6:cd0294454118 | 210 | touchCount = (touchCount-1)%(sizeof(ip0)/sizeof(ip0[0])); |
bhavk11 | 6:cd0294454118 | 211 | if(displayChar(cursor, ip0[touchCount])) { |
bhavk11 | 6:cd0294454118 | 212 | *ptr = ip0[touchCount]; |
bhavk11 | 6:cd0294454118 | 213 | ptr++; |
bhavk11 | 6:cd0294454118 | 214 | } |
bhavk11 | 6:cd0294454118 | 215 | break; |
bhavk11 | 6:cd0294454118 | 216 | case 1: |
bhavk11 | 6:cd0294454118 | 217 | if(displayChar(cursor, '1')) { |
bhavk11 | 6:cd0294454118 | 218 | *ptr = '1'; |
bhavk11 | 6:cd0294454118 | 219 | ptr++; |
bhavk11 | 6:cd0294454118 | 220 | } |
bhavk11 | 6:cd0294454118 | 221 | break; |
bhavk11 | 6:cd0294454118 | 222 | case 2: |
bhavk11 | 6:cd0294454118 | 223 | touchCount = (touchCount-1)%(sizeof(ip2)/sizeof(ip2[0])); |
bhavk11 | 6:cd0294454118 | 224 | if(displayChar(cursor, ip2[touchCount])) { |
bhavk11 | 6:cd0294454118 | 225 | *ptr = ip2[touchCount]; |
bhavk11 | 6:cd0294454118 | 226 | ptr++; |
bhavk11 | 6:cd0294454118 | 227 | } |
bhavk11 | 6:cd0294454118 | 228 | break; |
bhavk11 | 6:cd0294454118 | 229 | case 3: |
bhavk11 | 6:cd0294454118 | 230 | touchCount = (touchCount-1)%(sizeof(ip3)/sizeof(ip3[0])); |
bhavk11 | 6:cd0294454118 | 231 | if(displayChar(cursor, ip3[touchCount])) { |
bhavk11 | 6:cd0294454118 | 232 | *ptr = ip3[touchCount]; |
bhavk11 | 6:cd0294454118 | 233 | ptr++; |
bhavk11 | 6:cd0294454118 | 234 | } |
bhavk11 | 6:cd0294454118 | 235 | break; |
bhavk11 | 6:cd0294454118 | 236 | case 4: |
bhavk11 | 6:cd0294454118 | 237 | touchCount = (touchCount-1)%(sizeof(ip4)/sizeof(ip4[0])); |
bhavk11 | 6:cd0294454118 | 238 | if(displayChar(cursor, ip4[touchCount])) { |
bhavk11 | 6:cd0294454118 | 239 | *ptr = ip4[touchCount]; |
bhavk11 | 6:cd0294454118 | 240 | ptr++; |
bhavk11 | 6:cd0294454118 | 241 | } |
bhavk11 | 6:cd0294454118 | 242 | break; |
bhavk11 | 6:cd0294454118 | 243 | case 5: |
bhavk11 | 6:cd0294454118 | 244 | touchCount = (touchCount-1)%(sizeof(ip5)/sizeof(ip5[0])); |
bhavk11 | 6:cd0294454118 | 245 | if(displayChar(cursor, ip5[touchCount])) { |
bhavk11 | 6:cd0294454118 | 246 | *ptr = ip5[touchCount]; |
bhavk11 | 6:cd0294454118 | 247 | ptr++; |
bhavk11 | 6:cd0294454118 | 248 | } |
bhavk11 | 6:cd0294454118 | 249 | break; |
bhavk11 | 6:cd0294454118 | 250 | case 6: |
bhavk11 | 6:cd0294454118 | 251 | touchCount = (touchCount-1)%(sizeof(ip6)/sizeof(ip6[0])); |
bhavk11 | 6:cd0294454118 | 252 | if(displayChar(cursor, ip6[touchCount])) { |
bhavk11 | 6:cd0294454118 | 253 | *ptr = ip6[touchCount]; |
bhavk11 | 6:cd0294454118 | 254 | ptr++; |
bhavk11 | 6:cd0294454118 | 255 | } |
bhavk11 | 6:cd0294454118 | 256 | break; |
bhavk11 | 6:cd0294454118 | 257 | case 7: |
bhavk11 | 6:cd0294454118 | 258 | touchCount = (touchCount-1)%(sizeof(ip7)/sizeof(ip7[0])); |
bhavk11 | 6:cd0294454118 | 259 | if(displayChar(cursor, ip7[touchCount])) { |
bhavk11 | 6:cd0294454118 | 260 | *ptr = ip7[touchCount]; |
bhavk11 | 6:cd0294454118 | 261 | ptr++; |
bhavk11 | 6:cd0294454118 | 262 | } |
bhavk11 | 6:cd0294454118 | 263 | break; |
bhavk11 | 6:cd0294454118 | 264 | case 8: |
bhavk11 | 6:cd0294454118 | 265 | touchCount = (touchCount-1)%(sizeof(ip8)/sizeof(ip8[0])); |
bhavk11 | 6:cd0294454118 | 266 | if(displayChar(cursor, ip8[touchCount])) { |
bhavk11 | 6:cd0294454118 | 267 | *ptr = ip8[touchCount]; |
bhavk11 | 6:cd0294454118 | 268 | ptr++; |
bhavk11 | 6:cd0294454118 | 269 | } |
bhavk11 | 6:cd0294454118 | 270 | break; |
bhavk11 | 6:cd0294454118 | 271 | case 9: |
bhavk11 | 6:cd0294454118 | 272 | touchCount = (touchCount-1)%(sizeof(ip9)/sizeof(ip9[0])); |
bhavk11 | 6:cd0294454118 | 273 | if(displayChar(cursor, ip9[touchCount])) { |
bhavk11 | 6:cd0294454118 | 274 | *ptr = ip9[touchCount]; |
bhavk11 | 6:cd0294454118 | 275 | ptr++; |
bhavk11 | 6:cd0294454118 | 276 | } |
bhavk11 | 6:cd0294454118 | 277 | break; |
bhavk11 | 6:cd0294454118 | 278 | case 35: |
bhavk11 | 6:cd0294454118 | 279 | if(displayChar(cursor, '#')) { |
bhavk11 | 6:cd0294454118 | 280 | *ptr = '#'; |
bhavk11 | 6:cd0294454118 | 281 | ptr++; |
bhavk11 | 6:cd0294454118 | 282 | } |
bhavk11 | 6:cd0294454118 | 283 | break; |
bhavk11 | 6:cd0294454118 | 284 | case 42: |
bhavk11 | 6:cd0294454118 | 285 | if(displayChar(cursor, '*')) { |
bhavk11 | 6:cd0294454118 | 286 | *ptr = '*'; |
bhavk11 | 6:cd0294454118 | 287 | ptr++; |
bhavk11 | 6:cd0294454118 | 288 | } |
bhavk11 | 6:cd0294454118 | 289 | break; |
bhavk11 | 6:cd0294454118 | 290 | } |
bhavk11 | 6:cd0294454118 | 291 | |
bhavk11 | 6:cd0294454118 | 292 | key = getKey(); |
bhavk11 | 6:cd0294454118 | 293 | end = t.read_ms(); |
bhavk11 | 8:5e8c0b37bcf9 | 294 | if(key == -1 && ((end - begin) < 2000)) goto START; |
bhavk11 | 6:cd0294454118 | 295 | |
bhavk11 | 6:cd0294454118 | 296 | if(!(prevKey == key)){ |
bhavk11 | 6:cd0294454118 | 297 | break; |
bhavk11 | 6:cd0294454118 | 298 | } |
bhavk11 | 6:cd0294454118 | 299 | count++; |
bhavk11 | 6:cd0294454118 | 300 | |
bhavk11 | 6:cd0294454118 | 301 | pc.printf("ok curr count :%d key : %d prev_key : %d \r\n", touchCount,key, prevKey); |
bhavk11 | 6:cd0294454118 | 302 | } |
bhavk11 | 6:cd0294454118 | 303 | t.stop(); |
bhavk11 | 6:cd0294454118 | 304 | pc.printf("ok count is :%d \r\n", touchCount); |
bhavk11 | 7:11eb2c8df6a9 | 305 | pc.printf("PTR: %x, PT: %x\r\n",ptr,*pt); |
bhavk11 | 6:cd0294454118 | 306 | |
bhavk11 | 6:cd0294454118 | 307 | x = cursor; |
bhavk11 | 7:11eb2c8df6a9 | 308 | *pt = ptr; |
bhavk11 | 6:cd0294454118 | 309 | return prevKey; |
bhavk11 | 6:cd0294454118 | 310 | } |
bhavk11 | 6:cd0294454118 | 311 | |
neilt6 | 0:407dafce805d | 312 | int main() |
neilt6 | 0:407dafce805d | 313 | { |
bhavk11 | 4:5b088ba4f1f1 | 314 | point p; |
bhavk11 | 8:5e8c0b37bcf9 | 315 | bool isMsg = false; |
bhavk11 | 8:5e8c0b37bcf9 | 316 | char numbuffer[140]; |
bhavk11 | 8:5e8c0b37bcf9 | 317 | char msgbuffer[140]; |
neilt6 | 0:407dafce805d | 318 | //Configure the display driver |
neilt6 | 0:407dafce805d | 319 | TFT.background(Black); |
neilt6 | 0:407dafce805d | 320 | TFT.foreground(White); |
neilt6 | 0:407dafce805d | 321 | TFT.cls(); |
neilt6 | 0:407dafce805d | 322 | |
bhavk11 | 4:5b088ba4f1f1 | 323 | while(true) |
bhavk11 | 4:5b088ba4f1f1 | 324 | { |
bhavk11 | 4:5b088ba4f1f1 | 325 | //Print a welcome message |
bhavk11 | 4:5b088ba4f1f1 | 326 | TFT.background(White); |
bhavk11 | 4:5b088ba4f1f1 | 327 | TFT.set_font((unsigned char*) Neu42x35); |
bhavk11 | 4:5b088ba4f1f1 | 328 | TFT.foreground(Maroon); |
bhavk11 | 4:5b088ba4f1f1 | 329 | TFT.cls(); |
bhavk11 | 4:5b088ba4f1f1 | 330 | TFT.locate(100,60); |
bhavk11 | 4:5b088ba4f1f1 | 331 | TFT.printf("IU"); |
bhavk11 | 4:5b088ba4f1f1 | 332 | |
bhavk11 | 4:5b088ba4f1f1 | 333 | TFT.set_font((unsigned char*) Arial24x23); |
bhavk11 | 4:5b088ba4f1f1 | 334 | TFT.locate(28,230); |
bhavk11 | 4:5b088ba4f1f1 | 335 | TFT.printf("CALL"); |
bhavk11 | 4:5b088ba4f1f1 | 336 | TFT.circle(60,240,50,Maroon); |
bhavk11 | 4:5b088ba4f1f1 | 337 | |
bhavk11 | 4:5b088ba4f1f1 | 338 | TFT.locate(140,230); |
bhavk11 | 4:5b088ba4f1f1 | 339 | TFT.printf("TEXT"); |
bhavk11 | 4:5b088ba4f1f1 | 340 | TFT.circle(180,240,50,Maroon); |
bhavk11 | 4:5b088ba4f1f1 | 341 | |
bhavk11 | 9:1efb9e26fbeb | 342 | while((strcmp(cmd, "Back") == 0) || cmd == NULL) |
bhavk11 | 4:5b088ba4f1f1 | 343 | { |
bhavk11 | 4:5b088ba4f1f1 | 344 | if (TFT.getTouch(p) == TFT.YES) |
bhavk11 | 4:5b088ba4f1f1 | 345 | { |
bhavk11 | 4:5b088ba4f1f1 | 346 | if(p.x >= 4500 && p.x <= 6600) |
bhavk11 | 4:5b088ba4f1f1 | 347 | { |
bhavk11 | 4:5b088ba4f1f1 | 348 | if(p.y >= 1500 && p.y <= 3800) |
bhavk11 | 4:5b088ba4f1f1 | 349 | { |
bhavk11 | 4:5b088ba4f1f1 | 350 | //call |
bhavk11 | 9:1efb9e26fbeb | 351 | cmd = "Call"; |
bhavk11 | 4:5b088ba4f1f1 | 352 | } |
bhavk11 | 4:5b088ba4f1f1 | 353 | else if(p.y >= 4500 && p.y <= 7100) |
bhavk11 | 4:5b088ba4f1f1 | 354 | { |
bhavk11 | 4:5b088ba4f1f1 | 355 | //text |
bhavk11 | 4:5b088ba4f1f1 | 356 | cmd = "Text"; |
bhavk11 | 4:5b088ba4f1f1 | 357 | } |
bhavk11 | 4:5b088ba4f1f1 | 358 | } |
bhavk11 | 5:4add240cef16 | 359 | } |
bhavk11 | 4:5b088ba4f1f1 | 360 | } |
bhavk11 | 4:5b088ba4f1f1 | 361 | if(strcmp(cmd, "Call") == 0) |
bhavk11 | 4:5b088ba4f1f1 | 362 | { |
bhavk11 | 4:5b088ba4f1f1 | 363 | initKeypad(); |
bhavk11 | 8:5e8c0b37bcf9 | 364 | if(!isMsg) |
bhavk11 | 8:5e8c0b37bcf9 | 365 | printKey(130,280,"CALL","" ); |
bhavk11 | 8:5e8c0b37bcf9 | 366 | else |
bhavk11 | 8:5e8c0b37bcf9 | 367 | printKey(130,280,"SEND","" ); |
bhavk11 | 4:5b088ba4f1f1 | 368 | point cursor; |
bhavk11 | 4:5b088ba4f1f1 | 369 | cursor.x = 0; |
bhavk11 | 4:5b088ba4f1f1 | 370 | cursor.y = 5; |
bhavk11 | 8:5e8c0b37bcf9 | 371 | char *ptr = numbuffer; |
bhavk11 | 4:5b088ba4f1f1 | 372 | while(strcmp(cmd, "Call") == 0) |
bhavk11 | 4:5b088ba4f1f1 | 373 | { |
bhavk11 | 4:5b088ba4f1f1 | 374 | TFT.foreground(Black); |
bhavk11 | 4:5b088ba4f1f1 | 375 | int key = getKey(); |
bhavk11 | 4:5b088ba4f1f1 | 376 | switch(key) |
bhavk11 | 4:5b088ba4f1f1 | 377 | { |
bhavk11 | 4:5b088ba4f1f1 | 378 | case 0: |
bhavk11 | 4:5b088ba4f1f1 | 379 | if(displayChar(cursor, '0')) { |
bhavk11 | 4:5b088ba4f1f1 | 380 | *ptr = '0'; |
bhavk11 | 4:5b088ba4f1f1 | 381 | ptr++; |
bhavk11 | 4:5b088ba4f1f1 | 382 | } |
bhavk11 | 4:5b088ba4f1f1 | 383 | break; |
bhavk11 | 4:5b088ba4f1f1 | 384 | case 1: |
bhavk11 | 4:5b088ba4f1f1 | 385 | if(displayChar(cursor, '1')) { |
bhavk11 | 4:5b088ba4f1f1 | 386 | *ptr = '1'; |
bhavk11 | 4:5b088ba4f1f1 | 387 | ptr++; |
bhavk11 | 4:5b088ba4f1f1 | 388 | } |
bhavk11 | 4:5b088ba4f1f1 | 389 | break; |
bhavk11 | 4:5b088ba4f1f1 | 390 | case 2: |
bhavk11 | 4:5b088ba4f1f1 | 391 | if(displayChar(cursor, '2')) { |
bhavk11 | 4:5b088ba4f1f1 | 392 | *ptr = '2'; |
bhavk11 | 4:5b088ba4f1f1 | 393 | ptr++; |
bhavk11 | 4:5b088ba4f1f1 | 394 | } |
bhavk11 | 4:5b088ba4f1f1 | 395 | break; |
bhavk11 | 4:5b088ba4f1f1 | 396 | case 3: |
bhavk11 | 4:5b088ba4f1f1 | 397 | if(displayChar(cursor, '3')) { |
bhavk11 | 4:5b088ba4f1f1 | 398 | *ptr = '3'; |
bhavk11 | 4:5b088ba4f1f1 | 399 | ptr++; |
bhavk11 | 4:5b088ba4f1f1 | 400 | } |
bhavk11 | 4:5b088ba4f1f1 | 401 | break; |
bhavk11 | 4:5b088ba4f1f1 | 402 | case 4: |
bhavk11 | 4:5b088ba4f1f1 | 403 | if(displayChar(cursor, '4')) { |
bhavk11 | 4:5b088ba4f1f1 | 404 | *ptr = '4'; |
bhavk11 | 4:5b088ba4f1f1 | 405 | ptr++; |
bhavk11 | 4:5b088ba4f1f1 | 406 | } |
bhavk11 | 4:5b088ba4f1f1 | 407 | break; |
bhavk11 | 4:5b088ba4f1f1 | 408 | case 5: |
bhavk11 | 4:5b088ba4f1f1 | 409 | if(displayChar(cursor, '5')) { |
bhavk11 | 4:5b088ba4f1f1 | 410 | *ptr = '5'; |
bhavk11 | 4:5b088ba4f1f1 | 411 | ptr++; |
bhavk11 | 4:5b088ba4f1f1 | 412 | } |
bhavk11 | 4:5b088ba4f1f1 | 413 | break; |
bhavk11 | 4:5b088ba4f1f1 | 414 | case 6: |
bhavk11 | 4:5b088ba4f1f1 | 415 | if(displayChar(cursor, '6')) { |
bhavk11 | 4:5b088ba4f1f1 | 416 | *ptr = '6'; |
bhavk11 | 4:5b088ba4f1f1 | 417 | ptr++; |
bhavk11 | 4:5b088ba4f1f1 | 418 | } |
bhavk11 | 4:5b088ba4f1f1 | 419 | break; |
bhavk11 | 4:5b088ba4f1f1 | 420 | case 7: |
bhavk11 | 4:5b088ba4f1f1 | 421 | if(displayChar(cursor, '7')) { |
bhavk11 | 4:5b088ba4f1f1 | 422 | *ptr = '7'; |
bhavk11 | 4:5b088ba4f1f1 | 423 | ptr++; |
bhavk11 | 4:5b088ba4f1f1 | 424 | } |
bhavk11 | 4:5b088ba4f1f1 | 425 | break; |
bhavk11 | 4:5b088ba4f1f1 | 426 | case 8: |
bhavk11 | 4:5b088ba4f1f1 | 427 | if(displayChar(cursor, '8')) { |
bhavk11 | 4:5b088ba4f1f1 | 428 | *ptr = '8'; |
bhavk11 | 4:5b088ba4f1f1 | 429 | ptr++; |
bhavk11 | 4:5b088ba4f1f1 | 430 | } |
bhavk11 | 4:5b088ba4f1f1 | 431 | break; |
bhavk11 | 4:5b088ba4f1f1 | 432 | case 9: |
bhavk11 | 4:5b088ba4f1f1 | 433 | if(displayChar(cursor, '9')) { |
bhavk11 | 4:5b088ba4f1f1 | 434 | *ptr = '9'; |
bhavk11 | 4:5b088ba4f1f1 | 435 | ptr++; |
bhavk11 | 4:5b088ba4f1f1 | 436 | } |
bhavk11 | 4:5b088ba4f1f1 | 437 | break; |
bhavk11 | 4:5b088ba4f1f1 | 438 | case 35: |
bhavk11 | 4:5b088ba4f1f1 | 439 | if(displayChar(cursor, '#')) { |
bhavk11 | 4:5b088ba4f1f1 | 440 | *ptr = '#'; |
bhavk11 | 4:5b088ba4f1f1 | 441 | ptr++; |
bhavk11 | 4:5b088ba4f1f1 | 442 | } |
bhavk11 | 4:5b088ba4f1f1 | 443 | break; |
bhavk11 | 4:5b088ba4f1f1 | 444 | case 42: |
bhavk11 | 4:5b088ba4f1f1 | 445 | if(displayChar(cursor, '*')) { |
bhavk11 | 4:5b088ba4f1f1 | 446 | *ptr = '*'; |
bhavk11 | 4:5b088ba4f1f1 | 447 | ptr++; |
bhavk11 | 4:5b088ba4f1f1 | 448 | } |
bhavk11 | 4:5b088ba4f1f1 | 449 | break; |
bhavk11 | 4:5b088ba4f1f1 | 450 | case 43: |
bhavk11 | 8:5e8c0b37bcf9 | 451 | if(isMsg) |
bhavk11 | 8:5e8c0b37bcf9 | 452 | cmd = "Send"; |
bhavk11 | 8:5e8c0b37bcf9 | 453 | else |
bhavk11 | 8:5e8c0b37bcf9 | 454 | cmd = "Make"; |
bhavk11 | 8:5e8c0b37bcf9 | 455 | isMsg = false; |
bhavk11 | 4:5b088ba4f1f1 | 456 | break; |
bhavk11 | 4:5b088ba4f1f1 | 457 | case 60: |
bhavk11 | 4:5b088ba4f1f1 | 458 | cmd = "Back"; |
bhavk11 | 8:5e8c0b37bcf9 | 459 | isMsg = false; |
bhavk11 | 4:5b088ba4f1f1 | 460 | break; |
bhavk11 | 4:5b088ba4f1f1 | 461 | case 127: |
bhavk11 | 8:5e8c0b37bcf9 | 462 | if(ptr > numbuffer) |
bhavk11 | 4:5b088ba4f1f1 | 463 | { |
bhavk11 | 4:5b088ba4f1f1 | 464 | ptr--; |
bhavk11 | 6:cd0294454118 | 465 | if(cursor.x - 12 >= 0) |
bhavk11 | 6:cd0294454118 | 466 | cursor.x -= 12; |
bhavk11 | 4:5b088ba4f1f1 | 467 | else |
bhavk11 | 4:5b088ba4f1f1 | 468 | { |
bhavk11 | 6:cd0294454118 | 469 | cursor.x = 240; |
bhavk11 | 4:5b088ba4f1f1 | 470 | if(cursor.y - 21 >= 5 ) |
bhavk11 | 4:5b088ba4f1f1 | 471 | cursor.y -= 21; |
bhavk11 | 4:5b088ba4f1f1 | 472 | } |
bhavk11 | 4:5b088ba4f1f1 | 473 | TFT.locate(cursor.x,cursor.y); |
bhavk11 | 4:5b088ba4f1f1 | 474 | TFT.printf(" "); |
bhavk11 | 4:5b088ba4f1f1 | 475 | } |
bhavk11 | 4:5b088ba4f1f1 | 476 | break; |
bhavk11 | 4:5b088ba4f1f1 | 477 | } |
bhavk11 | 4:5b088ba4f1f1 | 478 | } |
bhavk11 | 4:5b088ba4f1f1 | 479 | if(strcmp(cmd, "Make") == 0) |
bhavk11 | 4:5b088ba4f1f1 | 480 | { |
bhavk11 | 4:5b088ba4f1f1 | 481 | TFT.background(Black); |
bhavk11 | 4:5b088ba4f1f1 | 482 | TFT.foreground(White); |
bhavk11 | 4:5b088ba4f1f1 | 483 | TFT.cls(); |
bhavk11 | 4:5b088ba4f1f1 | 484 | int i=0; |
bhavk11 | 4:5b088ba4f1f1 | 485 | cursor.x = 0; |
bhavk11 | 4:5b088ba4f1f1 | 486 | cursor.y = 5; |
bhavk11 | 4:5b088ba4f1f1 | 487 | TFT.locate(0,0); |
bhavk11 | 8:5e8c0b37bcf9 | 488 | while(&numbuffer[i] < ptr) |
bhavk11 | 8:5e8c0b37bcf9 | 489 | displayChar(cursor, numbuffer[i++]); |
bhavk11 | 4:5b088ba4f1f1 | 490 | TFT.line(0,270,240,270,Red); |
bhavk11 | 4:5b088ba4f1f1 | 491 | TFT.foreground(Red); |
bhavk11 | 4:5b088ba4f1f1 | 492 | TFT.locate(60,280); |
bhavk11 | 5:4add240cef16 | 493 | TFT.set_font((unsigned char*) Arial24x23); |
bhavk11 | 4:5b088ba4f1f1 | 494 | TFT.printf("Hang Up"); |
bhavk11 | 4:5b088ba4f1f1 | 495 | while(strcmp(cmd, "Make") == 0) |
bhavk11 | 4:5b088ba4f1f1 | 496 | { |
bhavk11 | 4:5b088ba4f1f1 | 497 | if(TFT.getTouch(p) == TFT.YES && p.x >= 6300 && p.x <= 7250) |
bhavk11 | 4:5b088ba4f1f1 | 498 | cmd = "Back"; |
bhavk11 | 4:5b088ba4f1f1 | 499 | } |
bhavk11 | 4:5b088ba4f1f1 | 500 | } |
bhavk11 | 8:5e8c0b37bcf9 | 501 | else if(strcmp(cmd,"Send") == 0) |
bhavk11 | 8:5e8c0b37bcf9 | 502 | { |
bhavk11 | 8:5e8c0b37bcf9 | 503 | // numbuffer has number |
bhavk11 | 8:5e8c0b37bcf9 | 504 | // msgbuffer has msg |
bhavk11 | 8:5e8c0b37bcf9 | 505 | TFT.background(Black); |
bhavk11 | 8:5e8c0b37bcf9 | 506 | TFT.foreground(White); |
bhavk11 | 8:5e8c0b37bcf9 | 507 | TFT.cls(); |
bhavk11 | 8:5e8c0b37bcf9 | 508 | TFT.locate(90,60); |
bhavk11 | 8:5e8c0b37bcf9 | 509 | TFT.printf("Text %s",msgbuffer); |
bhavk11 | 8:5e8c0b37bcf9 | 510 | TFT.locate(90,95); |
bhavk11 | 8:5e8c0b37bcf9 | 511 | TFT.printf("Sent to %s!",numbuffer); |
bhavk11 | 8:5e8c0b37bcf9 | 512 | wait(2.5); |
bhavk11 | 8:5e8c0b37bcf9 | 513 | cmd = "Back"; |
bhavk11 | 8:5e8c0b37bcf9 | 514 | } |
bhavk11 | 4:5b088ba4f1f1 | 515 | if(strcmp(cmd, "Back") == 0) |
bhavk11 | 4:5b088ba4f1f1 | 516 | { |
bhavk11 | 4:5b088ba4f1f1 | 517 | //Home screen |
bhavk11 | 4:5b088ba4f1f1 | 518 | } |
bhavk11 | 4:5b088ba4f1f1 | 519 | } |
bhavk11 | 4:5b088ba4f1f1 | 520 | else if(strcmp(cmd, "Text") == 0) |
bhavk11 | 4:5b088ba4f1f1 | 521 | { |
bhavk11 | 4:5b088ba4f1f1 | 522 | initKeypad(); |
bhavk11 | 4:5b088ba4f1f1 | 523 | printKey(130,280,"SEND","" ); |
bhavk11 | 4:5b088ba4f1f1 | 524 | point cursor; |
bhavk11 | 4:5b088ba4f1f1 | 525 | cursor.x = 0; |
bhavk11 | 4:5b088ba4f1f1 | 526 | cursor.y = 5; |
bhavk11 | 8:5e8c0b37bcf9 | 527 | char *ptr = msgbuffer; |
bhavk11 | 4:5b088ba4f1f1 | 528 | while(strcmp(cmd, "Text") == 0) |
bhavk11 | 4:5b088ba4f1f1 | 529 | { |
bhavk11 | 7:11eb2c8df6a9 | 530 | int key = getAlpha(cursor, &ptr); |
bhavk11 | 4:5b088ba4f1f1 | 531 | switch(key) |
bhavk11 | 4:5b088ba4f1f1 | 532 | { |
bhavk11 | 4:5b088ba4f1f1 | 533 | case 43: |
bhavk11 | 8:5e8c0b37bcf9 | 534 | isMsg = true; |
bhavk11 | 8:5e8c0b37bcf9 | 535 | cmd = "Call"; |
bhavk11 | 4:5b088ba4f1f1 | 536 | break; |
bhavk11 | 4:5b088ba4f1f1 | 537 | case 60: |
bhavk11 | 4:5b088ba4f1f1 | 538 | cmd = "Back"; |
bhavk11 | 4:5b088ba4f1f1 | 539 | break; |
bhavk11 | 4:5b088ba4f1f1 | 540 | case 127: |
bhavk11 | 8:5e8c0b37bcf9 | 541 | pc.printf("PTR: %x, Buff: %x, Buffer: %s\r\n",ptr, &msgbuffer[0], msgbuffer); |
bhavk11 | 7:11eb2c8df6a9 | 542 | |
bhavk11 | 8:5e8c0b37bcf9 | 543 | if(ptr > msgbuffer) |
bhavk11 | 4:5b088ba4f1f1 | 544 | { |
bhavk11 | 7:11eb2c8df6a9 | 545 | pc.printf("true"); |
bhavk11 | 4:5b088ba4f1f1 | 546 | ptr--; |
bhavk11 | 6:cd0294454118 | 547 | if(cursor.x - 12 >= 0) |
bhavk11 | 6:cd0294454118 | 548 | cursor.x -= 12; |
bhavk11 | 4:5b088ba4f1f1 | 549 | else |
bhavk11 | 4:5b088ba4f1f1 | 550 | { |
bhavk11 | 6:cd0294454118 | 551 | cursor.x = 240; |
bhavk11 | 4:5b088ba4f1f1 | 552 | if(cursor.y - 21 >= 5 ) |
bhavk11 | 4:5b088ba4f1f1 | 553 | cursor.y -= 21; |
bhavk11 | 4:5b088ba4f1f1 | 554 | } |
bhavk11 | 4:5b088ba4f1f1 | 555 | TFT.locate(cursor.x,cursor.y); |
bhavk11 | 4:5b088ba4f1f1 | 556 | TFT.printf(" "); |
bhavk11 | 4:5b088ba4f1f1 | 557 | } |
bhavk11 | 4:5b088ba4f1f1 | 558 | break; |
bhavk11 | 4:5b088ba4f1f1 | 559 | } |
bhavk11 | 4:5b088ba4f1f1 | 560 | } |
bhavk11 | 4:5b088ba4f1f1 | 561 | } |
bhavk11 | 5:4add240cef16 | 562 | else if (strcmp(cmd, "Ring") == 0) |
bhavk11 | 5:4add240cef16 | 563 | { |
bhavk11 | 8:5e8c0b37bcf9 | 564 | |
bhavk11 | 5:4add240cef16 | 565 | TFT.background(Black); |
bhavk11 | 5:4add240cef16 | 566 | TFT.foreground(White); |
bhavk11 | 5:4add240cef16 | 567 | TFT.cls(); |
bhavk11 | 5:4add240cef16 | 568 | TFT.locate(0,0); |
bhavk11 | 5:4add240cef16 | 569 | TFT.printf("Incoming Call..."); |
bhavk11 | 5:4add240cef16 | 570 | TFT.foreground(Green); |
bhavk11 | 5:4add240cef16 | 571 | TFT.set_font((unsigned char*) Arial24x23); |
bhavk11 | 5:4add240cef16 | 572 | TFT.locate(28,230); |
bhavk11 | 5:4add240cef16 | 573 | TFT.printf("ANS"); |
bhavk11 | 8:5e8c0b37bcf9 | 574 | TFT.circle(60,240,50,Green); |
bhavk11 | 5:4add240cef16 | 575 | |
bhavk11 | 5:4add240cef16 | 576 | TFT.foreground(Red); |
bhavk11 | 8:5e8c0b37bcf9 | 577 | TFT.locate(140,220); |
bhavk11 | 8:5e8c0b37bcf9 | 578 | TFT.printf("HANG"); |
bhavk11 | 8:5e8c0b37bcf9 | 579 | TFT.locate(160,240); |
bhavk11 | 8:5e8c0b37bcf9 | 580 | TFT.printf("UP"); |
bhavk11 | 8:5e8c0b37bcf9 | 581 | TFT.circle(180,240,50,Red); |
bhavk11 | 8:5e8c0b37bcf9 | 582 | while(strcmp(cmd, "Ring") == 0) |
bhavk11 | 5:4add240cef16 | 583 | { |
bhavk11 | 8:5e8c0b37bcf9 | 584 | if (TFT.getTouch(p) == TFT.YES) |
bhavk11 | 8:5e8c0b37bcf9 | 585 | { |
bhavk11 | 8:5e8c0b37bcf9 | 586 | if(p.x >= 4500 && p.x <= 6600) |
bhavk11 | 8:5e8c0b37bcf9 | 587 | { |
bhavk11 | 8:5e8c0b37bcf9 | 588 | if(p.y >= 1500 && p.y <= 3800) |
bhavk11 | 8:5e8c0b37bcf9 | 589 | { |
bhavk11 | 8:5e8c0b37bcf9 | 590 | //answer cal |
bhavk11 | 8:5e8c0b37bcf9 | 591 | cmd = "Answer"; |
bhavk11 | 8:5e8c0b37bcf9 | 592 | break; |
bhavk11 | 8:5e8c0b37bcf9 | 593 | } |
bhavk11 | 8:5e8c0b37bcf9 | 594 | else if(p.y >= 4500 && p.y <= 7100) |
bhavk11 | 8:5e8c0b37bcf9 | 595 | { |
bhavk11 | 8:5e8c0b37bcf9 | 596 | //hang up |
bhavk11 | 8:5e8c0b37bcf9 | 597 | cmd = "Back"; |
bhavk11 | 8:5e8c0b37bcf9 | 598 | break; |
bhavk11 | 8:5e8c0b37bcf9 | 599 | } |
bhavk11 | 8:5e8c0b37bcf9 | 600 | |
bhavk11 | 8:5e8c0b37bcf9 | 601 | } |
bhavk11 | 8:5e8c0b37bcf9 | 602 | } |
bhavk11 | 8:5e8c0b37bcf9 | 603 | } |
bhavk11 | 8:5e8c0b37bcf9 | 604 | if(strcmp(cmd, "Answer") == 0) |
bhavk11 | 8:5e8c0b37bcf9 | 605 | { |
bhavk11 | 8:5e8c0b37bcf9 | 606 | TFT.background(Black); |
bhavk11 | 8:5e8c0b37bcf9 | 607 | TFT.foreground(White); |
bhavk11 | 8:5e8c0b37bcf9 | 608 | TFT.cls(); |
bhavk11 | 8:5e8c0b37bcf9 | 609 | TFT.locate(0,0); |
bhavk11 | 8:5e8c0b37bcf9 | 610 | TFT.printf("Call in Progress..."); |
bhavk11 | 8:5e8c0b37bcf9 | 611 | TFT.line(0,270,240,270,Red); |
bhavk11 | 8:5e8c0b37bcf9 | 612 | TFT.foreground(Red); |
bhavk11 | 8:5e8c0b37bcf9 | 613 | TFT.locate(60,280); |
bhavk11 | 8:5e8c0b37bcf9 | 614 | TFT.set_font((unsigned char*) Arial24x23); |
bhavk11 | 8:5e8c0b37bcf9 | 615 | TFT.printf("Hang Up"); |
bhavk11 | 8:5e8c0b37bcf9 | 616 | while(strcmp(cmd, "Answer") == 0) |
bhavk11 | 8:5e8c0b37bcf9 | 617 | { |
bhavk11 | 8:5e8c0b37bcf9 | 618 | if(TFT.getTouch(p) == TFT.YES && p.x >= 6300 && p.x <= 7250) |
bhavk11 | 8:5e8c0b37bcf9 | 619 | cmd = "Back"; |
bhavk11 | 8:5e8c0b37bcf9 | 620 | } |
bhavk11 | 5:4add240cef16 | 621 | } |
bhavk11 | 5:4add240cef16 | 622 | } |
bhavk11 | 5:4add240cef16 | 623 | else if(strcmp(cmd, "RecvM") == 0) |
bhavk11 | 5:4add240cef16 | 624 | { |
bhavk11 | 9:1efb9e26fbeb | 625 | TFT.background(White); |
bhavk11 | 9:1efb9e26fbeb | 626 | TFT.foreground(Blue); |
bhavk11 | 9:1efb9e26fbeb | 627 | TFT.set_font((unsigned char*) Arial24x23); |
bhavk11 | 9:1efb9e26fbeb | 628 | char *start_pos, *end_pos, *msg_pos; |
bhavk11 | 9:1efb9e26fbeb | 629 | start_pos = strstr(recv_msgbuffer,"+CMT: \""); |
bhavk11 | 9:1efb9e26fbeb | 630 | char txtnum[20]; |
bhavk11 | 9:1efb9e26fbeb | 631 | gsm.cleanBuffer(txtnum,20); |
bhavk11 | 9:1efb9e26fbeb | 632 | char recv_msg[140]; |
bhavk11 | 9:1efb9e26fbeb | 633 | gsm.cleanBuffer(recv_msg,140); |
bhavk11 | 9:1efb9e26fbeb | 634 | start_pos += 7; |
bhavk11 | 9:1efb9e26fbeb | 635 | if(strstr(start_pos,"\",") != NULL) |
bhavk11 | 9:1efb9e26fbeb | 636 | { |
bhavk11 | 9:1efb9e26fbeb | 637 | end_pos = strstr(start_pos,"\","); |
bhavk11 | 9:1efb9e26fbeb | 638 | strncpy(txtnum,start_pos,(end_pos - start_pos)); |
bhavk11 | 9:1efb9e26fbeb | 639 | TFT.locate(0,5); |
bhavk11 | 9:1efb9e26fbeb | 640 | TFT.printf("\r\nFrom: %s \r\n",txtnum); |
bhavk11 | 9:1efb9e26fbeb | 641 | } |
bhavk11 | 9:1efb9e26fbeb | 642 | if(strstr(start_pos,"\n") != NULL) |
bhavk11 | 9:1efb9e26fbeb | 643 | { |
bhavk11 | 9:1efb9e26fbeb | 644 | msg_pos = strstr(start_pos,"\n"); |
bhavk11 | 9:1efb9e26fbeb | 645 | if(strstr(msg_pos+1,"\n") != NULL) |
bhavk11 | 9:1efb9e26fbeb | 646 | { |
bhavk11 | 9:1efb9e26fbeb | 647 | end_pos = strstr(msg_pos+1,"\n"); |
bhavk11 | 9:1efb9e26fbeb | 648 | strncpy(recv_msg,msg_pos+1,(end_pos - msg_pos - 1)); |
bhavk11 | 9:1efb9e26fbeb | 649 | TFT.locate(0,100); |
bhavk11 | 9:1efb9e26fbeb | 650 | TFT.printf("Message: %s\r\n",recv_msg); |
bhavk11 | 9:1efb9e26fbeb | 651 | } |
bhavk11 | 9:1efb9e26fbeb | 652 | } |
bhavk11 | 9:1efb9e26fbeb | 653 | TFT.line(0,270,240,270,Red); |
bhavk11 | 9:1efb9e26fbeb | 654 | TFT.foreground(Blue); |
bhavk11 | 9:1efb9e26fbeb | 655 | TFT.locate(60,280); |
bhavk11 | 9:1efb9e26fbeb | 656 | TFT.set_font((unsigned char*) Arial24x23); |
bhavk11 | 9:1efb9e26fbeb | 657 | TFT.printf("OK"); |
bhavk11 | 9:1efb9e26fbeb | 658 | while(strcmp(cmd, "RecvM") == 0) |
bhavk11 | 9:1efb9e26fbeb | 659 | { |
bhavk11 | 9:1efb9e26fbeb | 660 | if(TFT.getTouch(p) == TFT.YES && p.x >= 6300 && p.x <= 7250) |
bhavk11 | 9:1efb9e26fbeb | 661 | cmd = "Back"; |
bhavk11 | 9:1efb9e26fbeb | 662 | } |
bhavk11 | 5:4add240cef16 | 663 | } |
neilt6 | 0:407dafce805d | 664 | } |
neilt6 | 0:407dafce805d | 665 | } |