aaaa

Dependencies:   SeeedStudioTFTv2 TFT_fonts mbed

Fork of Seeed_TFT_Touch_Shield by Bhavik Bhuta

Committer:
uswickra
Date:
Sat Oct 25 20:21:17 2014 +0000
Revision:
5:c1af1f8fa026
Parent:
4:5b088ba4f1f1
Child:
6:2a920ec91d2b
new changes

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