aaa

Dependencies:   SeeedStudioTFTv2 TFT_fonts mbed

Fork of Seeed_TFT_Touch_Shield by Shields

Committer:
bhavk11
Date:
Thu Oct 23 23:13:57 2014 +0000
Revision:
4:5b088ba4f1f1
Parent:
2:5c2f6ff36ff1
Child:
5:4add240cef16
my

Who changed what in which revision?

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