aaaa
Dependencies: SeeedStudioTFTv2 TFT_fonts mbed
Fork of Seeed_TFT_Touch_Shield by
main.cpp@12:f27b67e10b0c, 2014-10-26 (annotated)
- Committer:
- uswickra
- Date:
- Sun Oct 26 16:19:28 2014 +0000
- Revision:
- 12:f27b67e10b0c
- Parent:
- 11:575dfd388778
fixed sms display
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; |
uswickra | 11:575dfd388778 | 43 | //Serial pc(USBTX,USBRX); |
uswickra | 11:575dfd388778 | 44 | Serial pc(SERIAL_TX, SERIAL_RX); |
uswickra | 11:575dfd388778 | 45 | |
screamer | 2:5c2f6ff36ff1 | 46 | 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 | 11:575dfd388778 | 47 | #define PHONE_NUMBER "+12246781239" |
uswickra | 5:c1af1f8fa026 | 48 | #include "Modem.h" |
uswickra | 5:c1af1f8fa026 | 49 | |
uswickra | 11:575dfd388778 | 50 | void cleanBuffer(char *buffer, int count); |
uswickra | 11:575dfd388778 | 51 | |
uswickra | 5:c1af1f8fa026 | 52 | Modem gsm (D10, D2, 19200, PHONE_NUMBER); |
uswickra | 5:c1af1f8fa026 | 53 | DigitalOut modem_power(D9); |
uswickra | 5:c1af1f8fa026 | 54 | char* cmd = NULL; |
uswickra | 11:575dfd388778 | 55 | volatile int type = 0 ; |
uswickra | 11:575dfd388778 | 56 | volatile int disable = 0 ; |
uswickra | 11:575dfd388778 | 57 | volatile int int_state = 0 ; |
uswickra | 5:c1af1f8fa026 | 58 | |
uswickra | 11:575dfd388778 | 59 | /* |
uswickra | 7:5cf5aeae1954 | 60 | void rxCallback() { |
uswickra | 7:5cf5aeae1954 | 61 | //__disable_irq(); |
uswickra | 7:5cf5aeae1954 | 62 | if(gsm.serial_modem.readable()){ |
uswickra | 7:5cf5aeae1954 | 63 | char c = gsm.serial_modem.getc(); |
uswickra | 7:5cf5aeae1954 | 64 | type = gsm.updateBuffer(c); |
uswickra | 11:575dfd388778 | 65 | pc.putc(c); |
uswickra | 10:5ea126441b8a | 66 | if(int_state == 1 && type == MESSAGE_RING){ |
uswickra | 7:5cf5aeae1954 | 67 | // pc.putc('R'); |
uswickra | 7:5cf5aeae1954 | 68 | cmd = "Ring" ; |
uswickra | 10:5ea126441b8a | 69 | int_state = 0 ; |
uswickra | 10:5ea126441b8a | 70 | // TFT.printf(cmd); |
uswickra | 7:5cf5aeae1954 | 71 | } |
uswickra | 10:5ea126441b8a | 72 | if(int_state == 1 && type == MESSAGE_SMS){ |
uswickra | 7:5cf5aeae1954 | 73 | // pc.putc('S'); |
uswickra | 11:575dfd388778 | 74 | cmd = "RecvM" ; |
uswickra | 11:575dfd388778 | 75 | pc.putc('S'); |
uswickra | 11:575dfd388778 | 76 | int_state = 0 ; |
uswickra | 11:575dfd388778 | 77 | } |
uswickra | 11:575dfd388778 | 78 | |
uswickra | 11:575dfd388778 | 79 | } |
uswickra | 11:575dfd388778 | 80 | //__enable_irq(); |
uswickra | 11:575dfd388778 | 81 | }*/ |
uswickra | 11:575dfd388778 | 82 | |
uswickra | 11:575dfd388778 | 83 | void rxCallback() { |
uswickra | 11:575dfd388778 | 84 | //__disable_irq(); |
uswickra | 11:575dfd388778 | 85 | if(!int_state && gsm.serial_modem.readable()){ |
uswickra | 11:575dfd388778 | 86 | char c = gsm.serial_modem.getc(); |
uswickra | 11:575dfd388778 | 87 | type = gsm.updateBuffer(c); |
uswickra | 11:575dfd388778 | 88 | // pc.putc(c); |
uswickra | 11:575dfd388778 | 89 | if(type == MESSAGE_RING){ |
uswickra | 11:575dfd388778 | 90 | // pc.putc('R'); |
uswickra | 11:575dfd388778 | 91 | cmd = "Ring" ; |
uswickra | 11:575dfd388778 | 92 | int_state = true; |
uswickra | 11:575dfd388778 | 93 | } |
uswickra | 11:575dfd388778 | 94 | if(type == MESSAGE_SMS){ |
uswickra | 11:575dfd388778 | 95 | // pc.putc('S'); |
uswickra | 11:575dfd388778 | 96 | cmd = "RecvM" ; |
uswickra | 11:575dfd388778 | 97 | int_state = true; |
uswickra | 7:5cf5aeae1954 | 98 | } |
uswickra | 7:5cf5aeae1954 | 99 | |
uswickra | 7:5cf5aeae1954 | 100 | } |
uswickra | 7:5cf5aeae1954 | 101 | //__enable_irq(); |
uswickra | 5:c1af1f8fa026 | 102 | } |
uswickra | 5:c1af1f8fa026 | 103 | |
neilt6 | 0:407dafce805d | 104 | |
bhavk11 | 4:5b088ba4f1f1 | 105 | void printKey(int x, int y, char* digit, char* alphas) |
bhavk11 | 4:5b088ba4f1f1 | 106 | { |
bhavk11 | 4:5b088ba4f1f1 | 107 | TFT.foreground(Blue); |
bhavk11 | 4:5b088ba4f1f1 | 108 | TFT.set_font((unsigned char*) Arial24x23); |
bhavk11 | 4:5b088ba4f1f1 | 109 | TFT.locate(x,y); |
bhavk11 | 4:5b088ba4f1f1 | 110 | TFT.printf(digit); |
bhavk11 | 4:5b088ba4f1f1 | 111 | TFT.foreground(Black); |
bhavk11 | 4:5b088ba4f1f1 | 112 | TFT.set_font((unsigned char*) Arial12x12); |
bhavk11 | 4:5b088ba4f1f1 | 113 | TFT.locate(x+15,y+10); |
bhavk11 | 4:5b088ba4f1f1 | 114 | TFT.printf(alphas); |
bhavk11 | 4:5b088ba4f1f1 | 115 | } |
bhavk11 | 4:5b088ba4f1f1 | 116 | |
bhavk11 | 4:5b088ba4f1f1 | 117 | void initKeypad() |
bhavk11 | 4:5b088ba4f1f1 | 118 | { |
bhavk11 | 4:5b088ba4f1f1 | 119 | TFT.background(White); |
bhavk11 | 4:5b088ba4f1f1 | 120 | TFT.cls(); |
bhavk11 | 4:5b088ba4f1f1 | 121 | TFT.foreground(Black); |
bhavk11 | 4:5b088ba4f1f1 | 122 | TFT.set_font((unsigned char*) Arial12x12); |
bhavk11 | 4:5b088ba4f1f1 | 123 | TFT.locate(210,84); |
bhavk11 | 4:5b088ba4f1f1 | 124 | TFT.printf("Del"); |
bhavk11 | 4:5b088ba4f1f1 | 125 | TFT.line(0,100,240,100,Black); |
bhavk11 | 4:5b088ba4f1f1 | 126 | TFT.rect(205,80,235,95,Black); |
bhavk11 | 4:5b088ba4f1f1 | 127 | TFT.line(205,80,195,95,White); |
bhavk11 | 4:5b088ba4f1f1 | 128 | TFT.line(192,87,205,80,Black); |
bhavk11 | 4:5b088ba4f1f1 | 129 | TFT.line(192,87,205,95,Black); |
bhavk11 | 4:5b088ba4f1f1 | 130 | printKey(20,120,"1"," "); |
bhavk11 | 4:5b088ba4f1f1 | 131 | printKey(95,120,"2","ABC"); |
bhavk11 | 4:5b088ba4f1f1 | 132 | printKey(170,120,"3","DEF"); |
bhavk11 | 4:5b088ba4f1f1 | 133 | printKey(20,160,"4","GHI"); |
bhavk11 | 4:5b088ba4f1f1 | 134 | printKey(95,160,"5","JKL"); |
bhavk11 | 4:5b088ba4f1f1 | 135 | printKey(170,160,"6","MNO"); |
bhavk11 | 4:5b088ba4f1f1 | 136 | printKey(20,200,"7","PQRS"); |
bhavk11 | 4:5b088ba4f1f1 | 137 | printKey(95,200,"8","TUV"); |
bhavk11 | 4:5b088ba4f1f1 | 138 | printKey(170,200,"9","WXYZ"); |
bhavk11 | 4:5b088ba4f1f1 | 139 | printKey(20,240,"*",""); |
bhavk11 | 4:5b088ba4f1f1 | 140 | printKey(95,240,"0","+"); |
bhavk11 | 4:5b088ba4f1f1 | 141 | printKey(170,240,"#",""); |
bhavk11 | 4:5b088ba4f1f1 | 142 | printKey(20,280,"<--",""); |
bhavk11 | 4:5b088ba4f1f1 | 143 | } |
bhavk11 | 4:5b088ba4f1f1 | 144 | |
bhavk11 | 4:5b088ba4f1f1 | 145 | int getKey() |
bhavk11 | 4:5b088ba4f1f1 | 146 | { |
bhavk11 | 4:5b088ba4f1f1 | 147 | int key = -1; |
bhavk11 | 4:5b088ba4f1f1 | 148 | point p; |
bhavk11 | 4:5b088ba4f1f1 | 149 | int count = 0; |
bhavk11 | 4:5b088ba4f1f1 | 150 | if(TFT.getTouch(p) == TFT.NO || TFT.getTouch(p) == TFT.MAYBE) |
bhavk11 | 4:5b088ba4f1f1 | 151 | { return key; |
bhavk11 | 4:5b088ba4f1f1 | 152 | } |
bhavk11 | 4:5b088ba4f1f1 | 153 | while(TFT.getTouch(p) == TFT.YES) |
bhavk11 | 4:5b088ba4f1f1 | 154 | { |
bhavk11 | 4:5b088ba4f1f1 | 155 | count++; |
bhavk11 | 4:5b088ba4f1f1 | 156 | } |
bhavk11 | 4:5b088ba4f1f1 | 157 | if(count > 300) |
bhavk11 | 4:5b088ba4f1f1 | 158 | { |
bhavk11 | 4:5b088ba4f1f1 | 159 | //TFT.foreground(Black); |
bhavk11 | 4:5b088ba4f1f1 | 160 | // TFT.set_font((unsigned char*) Arial12x12); |
bhavk11 | 4:5b088ba4f1f1 | 161 | // TFT.locate(0,0); |
bhavk11 | 4:5b088ba4f1f1 | 162 | // TFT.printf("X:%d, Y:%d\n\r",p.x,p.y); |
bhavk11 | 4:5b088ba4f1f1 | 163 | if (p.x>2700 && p.x<7250) |
bhavk11 | 4:5b088ba4f1f1 | 164 | { |
bhavk11 | 4:5b088ba4f1f1 | 165 | if(p.x<3750) |
bhavk11 | 4:5b088ba4f1f1 | 166 | { |
bhavk11 | 4:5b088ba4f1f1 | 167 | if(p.y<3000) |
bhavk11 | 4:5b088ba4f1f1 | 168 | key = 1; //1 |
bhavk11 | 4:5b088ba4f1f1 | 169 | else if(p.y<5250) |
bhavk11 | 4:5b088ba4f1f1 | 170 | key = 2; //2 |
bhavk11 | 4:5b088ba4f1f1 | 171 | else |
bhavk11 | 4:5b088ba4f1f1 | 172 | key = 3; //3 |
bhavk11 | 4:5b088ba4f1f1 | 173 | } |
bhavk11 | 4:5b088ba4f1f1 | 174 | else if(p.x<4600) |
bhavk11 | 4:5b088ba4f1f1 | 175 | { |
bhavk11 | 4:5b088ba4f1f1 | 176 | if(p.y<3000) |
bhavk11 | 4:5b088ba4f1f1 | 177 | key = 4; //4 |
bhavk11 | 4:5b088ba4f1f1 | 178 | else if(p.y<5250) |
bhavk11 | 4:5b088ba4f1f1 | 179 | key = 5; //5 |
bhavk11 | 4:5b088ba4f1f1 | 180 | else |
bhavk11 | 4:5b088ba4f1f1 | 181 | key = 6; //6 |
bhavk11 | 4:5b088ba4f1f1 | 182 | } |
bhavk11 | 4:5b088ba4f1f1 | 183 | else if(p.x<5400) |
bhavk11 | 4:5b088ba4f1f1 | 184 | { |
bhavk11 | 4:5b088ba4f1f1 | 185 | if(p.y<3000) |
bhavk11 | 4:5b088ba4f1f1 | 186 | key = 7; //7 |
bhavk11 | 4:5b088ba4f1f1 | 187 | else if(p.y<5250) |
bhavk11 | 4:5b088ba4f1f1 | 188 | key = 8; //8 |
bhavk11 | 4:5b088ba4f1f1 | 189 | else |
bhavk11 | 4:5b088ba4f1f1 | 190 | key = 9; //9 |
bhavk11 | 4:5b088ba4f1f1 | 191 | } |
bhavk11 | 4:5b088ba4f1f1 | 192 | else if(p.x<6300) |
bhavk11 | 4:5b088ba4f1f1 | 193 | { |
bhavk11 | 4:5b088ba4f1f1 | 194 | if(p.y<3000) |
bhavk11 | 4:5b088ba4f1f1 | 195 | key = 42; //* |
bhavk11 | 4:5b088ba4f1f1 | 196 | else if(p.y<5250) |
bhavk11 | 4:5b088ba4f1f1 | 197 | key = 0; //0 |
bhavk11 | 4:5b088ba4f1f1 | 198 | else |
bhavk11 | 4:5b088ba4f1f1 | 199 | key = 35; //# |
bhavk11 | 4:5b088ba4f1f1 | 200 | } |
bhavk11 | 4:5b088ba4f1f1 | 201 | else |
bhavk11 | 4:5b088ba4f1f1 | 202 | { |
bhavk11 | 4:5b088ba4f1f1 | 203 | if(p.y<3000) |
bhavk11 | 4:5b088ba4f1f1 | 204 | key = 60; // back |
bhavk11 | 4:5b088ba4f1f1 | 205 | else |
bhavk11 | 4:5b088ba4f1f1 | 206 | key = 43; // go (call/text) |
bhavk11 | 4:5b088ba4f1f1 | 207 | } |
bhavk11 | 4:5b088ba4f1f1 | 208 | } |
bhavk11 | 4:5b088ba4f1f1 | 209 | if(p.x > 2200 && p.x < 2500 && p.y > 6200 && p.y < 7000) |
bhavk11 | 4:5b088ba4f1f1 | 210 | key = 127; |
bhavk11 | 4:5b088ba4f1f1 | 211 | } |
bhavk11 | 4:5b088ba4f1f1 | 212 | return key; |
bhavk11 | 4:5b088ba4f1f1 | 213 | } |
bhavk11 | 4:5b088ba4f1f1 | 214 | |
uswickra | 5:c1af1f8fa026 | 215 | char ip0[] = {' ','0','+'}; |
uswickra | 5:c1af1f8fa026 | 216 | char ip2[] = {'a','b','c','2'}; |
uswickra | 5:c1af1f8fa026 | 217 | char ip3[] = {'d','e','f','3'}; |
uswickra | 5:c1af1f8fa026 | 218 | char ip4[] = {'g','h','i','4'}; |
uswickra | 5:c1af1f8fa026 | 219 | char ip5[] = {'j','k','l','5'}; |
uswickra | 5:c1af1f8fa026 | 220 | char ip6[] = {'m','o','p','6'}; |
uswickra | 5:c1af1f8fa026 | 221 | char ip7[] = {'p','q','r','s','7'}; |
uswickra | 5:c1af1f8fa026 | 222 | char ip8[] = {'t','u','v','8'}; |
uswickra | 5:c1af1f8fa026 | 223 | char ip9[] = {'w','x','y','z','9'}; |
bhavk11 | 4:5b088ba4f1f1 | 224 | |
bhavk11 | 4:5b088ba4f1f1 | 225 | |
bhavk11 | 4:5b088ba4f1f1 | 226 | bool displayChar(point& cursor, char letter) |
bhavk11 | 4:5b088ba4f1f1 | 227 | { |
bhavk11 | 4:5b088ba4f1f1 | 228 | TFT.locate(cursor.x,cursor.y); |
uswickra | 5:c1af1f8fa026 | 229 | if(cursor.x + 12 <= 228) |
uswickra | 5:c1af1f8fa026 | 230 | cursor.x += 12; |
bhavk11 | 4:5b088ba4f1f1 | 231 | else |
bhavk11 | 4:5b088ba4f1f1 | 232 | { |
bhavk11 | 4:5b088ba4f1f1 | 233 | cursor.x = 0; |
bhavk11 | 4:5b088ba4f1f1 | 234 | if(cursor.y + 21 <= 65 ) |
bhavk11 | 4:5b088ba4f1f1 | 235 | cursor.y += 21; |
bhavk11 | 4:5b088ba4f1f1 | 236 | else |
bhavk11 | 4:5b088ba4f1f1 | 237 | return false; |
bhavk11 | 4:5b088ba4f1f1 | 238 | } |
uswickra | 5:c1af1f8fa026 | 239 | TFT.set_font((unsigned char*) Arial12x12); |
bhavk11 | 4:5b088ba4f1f1 | 240 | TFT.printf("%c",letter); |
bhavk11 | 4:5b088ba4f1f1 | 241 | return true; |
bhavk11 | 4:5b088ba4f1f1 | 242 | } |
bhavk11 | 4:5b088ba4f1f1 | 243 | |
uswickra | 5:c1af1f8fa026 | 244 | int getAlpha(point& x, char** pt) |
uswickra | 5:c1af1f8fa026 | 245 | { |
uswickra | 5:c1af1f8fa026 | 246 | int touchCount = 1, count = 1; |
uswickra | 5:c1af1f8fa026 | 247 | int key, begin, end; |
uswickra | 5:c1af1f8fa026 | 248 | int prevKey; |
uswickra | 5:c1af1f8fa026 | 249 | do { |
uswickra | 5:c1af1f8fa026 | 250 | prevKey = key = getKey(); |
bhavk11 | 6:2a920ec91d2b | 251 | }while(prevKey == -1 && strcmp(cmd, "Text") == 0); |
uswickra | 5:c1af1f8fa026 | 252 | |
uswickra | 5:c1af1f8fa026 | 253 | point cursor = x; |
uswickra | 5:c1af1f8fa026 | 254 | char* ptr = *pt; |
uswickra | 5:c1af1f8fa026 | 255 | t.reset(); |
uswickra | 5:c1af1f8fa026 | 256 | t.start(); |
uswickra | 5:c1af1f8fa026 | 257 | begin = t.read_ms(); |
uswickra | 5:c1af1f8fa026 | 258 | end = t.read_ms(); |
uswickra | 5:c1af1f8fa026 | 259 | while((end - begin) < 2000) |
uswickra | 5:c1af1f8fa026 | 260 | { |
uswickra | 5:c1af1f8fa026 | 261 | cursor = x; |
uswickra | 5:c1af1f8fa026 | 262 | ptr = *pt; |
uswickra | 5:c1af1f8fa026 | 263 | touchCount = count; |
uswickra | 5:c1af1f8fa026 | 264 | START: |
uswickra | 5:c1af1f8fa026 | 265 | switch(key) |
uswickra | 5:c1af1f8fa026 | 266 | { |
uswickra | 5:c1af1f8fa026 | 267 | case 0: |
uswickra | 5:c1af1f8fa026 | 268 | touchCount = (touchCount-1)%(sizeof(ip0)/sizeof(ip0[0])); |
uswickra | 5:c1af1f8fa026 | 269 | if(displayChar(cursor, ip0[touchCount])) { |
uswickra | 5:c1af1f8fa026 | 270 | *ptr = ip0[touchCount]; |
uswickra | 5:c1af1f8fa026 | 271 | ptr++; |
uswickra | 5:c1af1f8fa026 | 272 | } |
uswickra | 5:c1af1f8fa026 | 273 | break; |
uswickra | 5:c1af1f8fa026 | 274 | case 1: |
uswickra | 5:c1af1f8fa026 | 275 | if(displayChar(cursor, '1')) { |
uswickra | 5:c1af1f8fa026 | 276 | *ptr = '1'; |
uswickra | 5:c1af1f8fa026 | 277 | ptr++; |
uswickra | 5:c1af1f8fa026 | 278 | } |
uswickra | 5:c1af1f8fa026 | 279 | break; |
uswickra | 5:c1af1f8fa026 | 280 | case 2: |
uswickra | 5:c1af1f8fa026 | 281 | touchCount = (touchCount-1)%(sizeof(ip2)/sizeof(ip2[0])); |
uswickra | 5:c1af1f8fa026 | 282 | if(displayChar(cursor, ip2[touchCount])) { |
uswickra | 5:c1af1f8fa026 | 283 | *ptr = ip2[touchCount]; |
uswickra | 5:c1af1f8fa026 | 284 | ptr++; |
uswickra | 5:c1af1f8fa026 | 285 | } |
uswickra | 5:c1af1f8fa026 | 286 | break; |
uswickra | 5:c1af1f8fa026 | 287 | case 3: |
uswickra | 5:c1af1f8fa026 | 288 | touchCount = (touchCount-1)%(sizeof(ip3)/sizeof(ip3[0])); |
uswickra | 5:c1af1f8fa026 | 289 | if(displayChar(cursor, ip3[touchCount])) { |
uswickra | 5:c1af1f8fa026 | 290 | *ptr = ip3[touchCount]; |
uswickra | 5:c1af1f8fa026 | 291 | ptr++; |
uswickra | 5:c1af1f8fa026 | 292 | } |
uswickra | 5:c1af1f8fa026 | 293 | break; |
uswickra | 5:c1af1f8fa026 | 294 | case 4: |
uswickra | 5:c1af1f8fa026 | 295 | touchCount = (touchCount-1)%(sizeof(ip4)/sizeof(ip4[0])); |
uswickra | 5:c1af1f8fa026 | 296 | if(displayChar(cursor, ip4[touchCount])) { |
uswickra | 5:c1af1f8fa026 | 297 | *ptr = ip4[touchCount]; |
uswickra | 5:c1af1f8fa026 | 298 | ptr++; |
uswickra | 5:c1af1f8fa026 | 299 | } |
uswickra | 5:c1af1f8fa026 | 300 | break; |
uswickra | 5:c1af1f8fa026 | 301 | case 5: |
uswickra | 5:c1af1f8fa026 | 302 | touchCount = (touchCount-1)%(sizeof(ip5)/sizeof(ip5[0])); |
uswickra | 5:c1af1f8fa026 | 303 | if(displayChar(cursor, ip5[touchCount])) { |
uswickra | 5:c1af1f8fa026 | 304 | *ptr = ip5[touchCount]; |
uswickra | 5:c1af1f8fa026 | 305 | ptr++; |
uswickra | 5:c1af1f8fa026 | 306 | } |
uswickra | 5:c1af1f8fa026 | 307 | break; |
uswickra | 5:c1af1f8fa026 | 308 | case 6: |
uswickra | 5:c1af1f8fa026 | 309 | touchCount = (touchCount-1)%(sizeof(ip6)/sizeof(ip6[0])); |
uswickra | 5:c1af1f8fa026 | 310 | if(displayChar(cursor, ip6[touchCount])) { |
uswickra | 5:c1af1f8fa026 | 311 | *ptr = ip6[touchCount]; |
uswickra | 5:c1af1f8fa026 | 312 | ptr++; |
uswickra | 5:c1af1f8fa026 | 313 | } |
uswickra | 5:c1af1f8fa026 | 314 | break; |
uswickra | 5:c1af1f8fa026 | 315 | case 7: |
uswickra | 5:c1af1f8fa026 | 316 | touchCount = (touchCount-1)%(sizeof(ip7)/sizeof(ip7[0])); |
uswickra | 5:c1af1f8fa026 | 317 | if(displayChar(cursor, ip7[touchCount])) { |
uswickra | 5:c1af1f8fa026 | 318 | *ptr = ip7[touchCount]; |
uswickra | 5:c1af1f8fa026 | 319 | ptr++; |
uswickra | 5:c1af1f8fa026 | 320 | } |
uswickra | 5:c1af1f8fa026 | 321 | break; |
uswickra | 5:c1af1f8fa026 | 322 | case 8: |
uswickra | 5:c1af1f8fa026 | 323 | touchCount = (touchCount-1)%(sizeof(ip8)/sizeof(ip8[0])); |
uswickra | 5:c1af1f8fa026 | 324 | if(displayChar(cursor, ip8[touchCount])) { |
uswickra | 5:c1af1f8fa026 | 325 | *ptr = ip8[touchCount]; |
uswickra | 5:c1af1f8fa026 | 326 | ptr++; |
uswickra | 5:c1af1f8fa026 | 327 | } |
uswickra | 5:c1af1f8fa026 | 328 | break; |
uswickra | 5:c1af1f8fa026 | 329 | case 9: |
uswickra | 5:c1af1f8fa026 | 330 | touchCount = (touchCount-1)%(sizeof(ip9)/sizeof(ip9[0])); |
uswickra | 5:c1af1f8fa026 | 331 | if(displayChar(cursor, ip9[touchCount])) { |
uswickra | 5:c1af1f8fa026 | 332 | *ptr = ip9[touchCount]; |
uswickra | 5:c1af1f8fa026 | 333 | ptr++; |
uswickra | 5:c1af1f8fa026 | 334 | } |
uswickra | 5:c1af1f8fa026 | 335 | break; |
uswickra | 5:c1af1f8fa026 | 336 | case 35: |
uswickra | 5:c1af1f8fa026 | 337 | if(displayChar(cursor, '#')) { |
uswickra | 5:c1af1f8fa026 | 338 | *ptr = '#'; |
uswickra | 5:c1af1f8fa026 | 339 | ptr++; |
uswickra | 5:c1af1f8fa026 | 340 | } |
uswickra | 5:c1af1f8fa026 | 341 | break; |
uswickra | 5:c1af1f8fa026 | 342 | case 42: |
uswickra | 5:c1af1f8fa026 | 343 | if(displayChar(cursor, '*')) { |
uswickra | 5:c1af1f8fa026 | 344 | *ptr = '*'; |
uswickra | 5:c1af1f8fa026 | 345 | ptr++; |
uswickra | 5:c1af1f8fa026 | 346 | } |
uswickra | 5:c1af1f8fa026 | 347 | break; |
uswickra | 5:c1af1f8fa026 | 348 | } |
uswickra | 5:c1af1f8fa026 | 349 | |
uswickra | 5:c1af1f8fa026 | 350 | key = getKey(); |
uswickra | 5:c1af1f8fa026 | 351 | end = t.read_ms(); |
uswickra | 5:c1af1f8fa026 | 352 | if(key == -1 && ((end - begin) < 2000)) goto START; |
uswickra | 5:c1af1f8fa026 | 353 | |
uswickra | 5:c1af1f8fa026 | 354 | if(!(prevKey == key)){ |
uswickra | 5:c1af1f8fa026 | 355 | break; |
uswickra | 5:c1af1f8fa026 | 356 | } |
uswickra | 5:c1af1f8fa026 | 357 | count++; |
uswickra | 5:c1af1f8fa026 | 358 | |
uswickra | 5:c1af1f8fa026 | 359 | pc.printf("ok curr count :%d key : %d prev_key : %d \r\n", touchCount,key, prevKey); |
uswickra | 5:c1af1f8fa026 | 360 | } |
uswickra | 5:c1af1f8fa026 | 361 | t.stop(); |
uswickra | 5:c1af1f8fa026 | 362 | pc.printf("ok count is :%d \r\n", touchCount); |
uswickra | 5:c1af1f8fa026 | 363 | |
uswickra | 5:c1af1f8fa026 | 364 | x = cursor; |
uswickra | 5:c1af1f8fa026 | 365 | *pt = ptr; |
uswickra | 5:c1af1f8fa026 | 366 | return prevKey; |
uswickra | 5:c1af1f8fa026 | 367 | } |
uswickra | 5:c1af1f8fa026 | 368 | |
uswickra | 5:c1af1f8fa026 | 369 | |
uswickra | 5:c1af1f8fa026 | 370 | void init_modem(){ |
uswickra | 11:575dfd388778 | 371 | modem_power = 0 ; |
uswickra | 11:575dfd388778 | 372 | wait(5); |
uswickra | 5:c1af1f8fa026 | 373 | modem_power = 1 ; |
uswickra | 5:c1af1f8fa026 | 374 | wait(1); |
uswickra | 5:c1af1f8fa026 | 375 | // gsm.serial_modem.attach(&messageHandle); |
uswickra | 5:c1af1f8fa026 | 376 | while(gsm.init() != 1) { |
uswickra | 5:c1af1f8fa026 | 377 | // TFT.printf("waiting... \r\n"); |
uswickra | 5:c1af1f8fa026 | 378 | wait(1); |
uswickra | 5:c1af1f8fa026 | 379 | } |
uswickra | 7:5cf5aeae1954 | 380 | gsm.serial_modem.attach(&rxCallback, Serial::RxIrq); |
uswickra | 5:c1af1f8fa026 | 381 | } |
uswickra | 5:c1af1f8fa026 | 382 | |
uswickra | 5:c1af1f8fa026 | 383 | |
neilt6 | 0:407dafce805d | 384 | int main() |
neilt6 | 0:407dafce805d | 385 | { |
bhavk11 | 4:5b088ba4f1f1 | 386 | point p; |
uswickra | 11:575dfd388778 | 387 | // pc.baud(115200); |
bhavk11 | 6:2a920ec91d2b | 388 | bool isMsg = false; |
bhavk11 | 6:2a920ec91d2b | 389 | char numbuffer[140]; |
bhavk11 | 6:2a920ec91d2b | 390 | char msgbuffer[140]; |
bhavk11 | 6:2a920ec91d2b | 391 | |
neilt6 | 0:407dafce805d | 392 | //Configure the display driver |
neilt6 | 0:407dafce805d | 393 | TFT.background(Black); |
neilt6 | 0:407dafce805d | 394 | TFT.foreground(White); |
neilt6 | 0:407dafce805d | 395 | TFT.cls(); |
uswickra | 5:c1af1f8fa026 | 396 | //initialize the modem - may take few seconds |
uswickra | 5:c1af1f8fa026 | 397 | init_modem(); |
uswickra | 11:575dfd388778 | 398 | pc.printf("\r\n start \r\n"); |
uswickra | 5:c1af1f8fa026 | 399 | |
bhavk11 | 4:5b088ba4f1f1 | 400 | while(true) |
bhavk11 | 4:5b088ba4f1f1 | 401 | { |
bhavk11 | 4:5b088ba4f1f1 | 402 | //Print a welcome message |
bhavk11 | 4:5b088ba4f1f1 | 403 | TFT.background(White); |
bhavk11 | 4:5b088ba4f1f1 | 404 | TFT.set_font((unsigned char*) Neu42x35); |
bhavk11 | 4:5b088ba4f1f1 | 405 | TFT.foreground(Maroon); |
bhavk11 | 4:5b088ba4f1f1 | 406 | TFT.cls(); |
uswickra | 5:c1af1f8fa026 | 407 | |
bhavk11 | 4:5b088ba4f1f1 | 408 | TFT.locate(100,60); |
bhavk11 | 4:5b088ba4f1f1 | 409 | TFT.printf("IU"); |
bhavk11 | 4:5b088ba4f1f1 | 410 | |
bhavk11 | 4:5b088ba4f1f1 | 411 | TFT.set_font((unsigned char*) Arial24x23); |
bhavk11 | 4:5b088ba4f1f1 | 412 | TFT.locate(28,230); |
bhavk11 | 4:5b088ba4f1f1 | 413 | TFT.printf("CALL"); |
bhavk11 | 4:5b088ba4f1f1 | 414 | TFT.circle(60,240,50,Maroon); |
bhavk11 | 4:5b088ba4f1f1 | 415 | |
bhavk11 | 4:5b088ba4f1f1 | 416 | TFT.locate(140,230); |
bhavk11 | 4:5b088ba4f1f1 | 417 | TFT.printf("TEXT"); |
bhavk11 | 4:5b088ba4f1f1 | 418 | TFT.circle(180,240,50,Maroon); |
bhavk11 | 4:5b088ba4f1f1 | 419 | |
bhavk11 | 9:f226caed4c66 | 420 | while((strcmp(cmd, "Back") == 0) || cmd == NULL) |
bhavk11 | 4:5b088ba4f1f1 | 421 | { |
bhavk11 | 4:5b088ba4f1f1 | 422 | if (TFT.getTouch(p) == TFT.YES) |
bhavk11 | 4:5b088ba4f1f1 | 423 | { |
bhavk11 | 4:5b088ba4f1f1 | 424 | if(p.x >= 4500 && p.x <= 6600) |
bhavk11 | 4:5b088ba4f1f1 | 425 | { |
bhavk11 | 4:5b088ba4f1f1 | 426 | if(p.y >= 1500 && p.y <= 3800) |
bhavk11 | 4:5b088ba4f1f1 | 427 | { |
bhavk11 | 4:5b088ba4f1f1 | 428 | //call |
bhavk11 | 4:5b088ba4f1f1 | 429 | cmd = "Call"; |
bhavk11 | 4:5b088ba4f1f1 | 430 | } |
bhavk11 | 4:5b088ba4f1f1 | 431 | else if(p.y >= 4500 && p.y <= 7100) |
bhavk11 | 4:5b088ba4f1f1 | 432 | { |
bhavk11 | 4:5b088ba4f1f1 | 433 | //text |
bhavk11 | 4:5b088ba4f1f1 | 434 | cmd = "Text"; |
bhavk11 | 4:5b088ba4f1f1 | 435 | } |
bhavk11 | 4:5b088ba4f1f1 | 436 | } |
bhavk11 | 9:f226caed4c66 | 437 | } |
bhavk11 | 4:5b088ba4f1f1 | 438 | } |
bhavk11 | 4:5b088ba4f1f1 | 439 | |
bhavk11 | 4:5b088ba4f1f1 | 440 | if(strcmp(cmd, "Call") == 0) |
bhavk11 | 4:5b088ba4f1f1 | 441 | { |
bhavk11 | 4:5b088ba4f1f1 | 442 | initKeypad(); |
bhavk11 | 6:2a920ec91d2b | 443 | if(!isMsg) |
bhavk11 | 6:2a920ec91d2b | 444 | printKey(130,280,"CALL","" ); |
bhavk11 | 6:2a920ec91d2b | 445 | else |
bhavk11 | 6:2a920ec91d2b | 446 | printKey(130,280,"SEND","" ); |
bhavk11 | 4:5b088ba4f1f1 | 447 | point cursor; |
bhavk11 | 4:5b088ba4f1f1 | 448 | cursor.x = 0; |
bhavk11 | 4:5b088ba4f1f1 | 449 | cursor.y = 5; |
bhavk11 | 6:2a920ec91d2b | 450 | char *ptr = numbuffer; |
bhavk11 | 4:5b088ba4f1f1 | 451 | while(strcmp(cmd, "Call") == 0) |
bhavk11 | 4:5b088ba4f1f1 | 452 | { |
bhavk11 | 4:5b088ba4f1f1 | 453 | TFT.foreground(Black); |
bhavk11 | 4:5b088ba4f1f1 | 454 | int key = getKey(); |
bhavk11 | 4:5b088ba4f1f1 | 455 | switch(key) |
bhavk11 | 4:5b088ba4f1f1 | 456 | { |
bhavk11 | 4:5b088ba4f1f1 | 457 | case 0: |
bhavk11 | 4:5b088ba4f1f1 | 458 | if(displayChar(cursor, '0')) { |
bhavk11 | 4:5b088ba4f1f1 | 459 | *ptr = '0'; |
bhavk11 | 4:5b088ba4f1f1 | 460 | ptr++; |
bhavk11 | 4:5b088ba4f1f1 | 461 | } |
bhavk11 | 4:5b088ba4f1f1 | 462 | break; |
bhavk11 | 4:5b088ba4f1f1 | 463 | case 1: |
bhavk11 | 4:5b088ba4f1f1 | 464 | if(displayChar(cursor, '1')) { |
bhavk11 | 4:5b088ba4f1f1 | 465 | *ptr = '1'; |
bhavk11 | 4:5b088ba4f1f1 | 466 | ptr++; |
bhavk11 | 4:5b088ba4f1f1 | 467 | } |
bhavk11 | 4:5b088ba4f1f1 | 468 | break; |
bhavk11 | 4:5b088ba4f1f1 | 469 | case 2: |
bhavk11 | 4:5b088ba4f1f1 | 470 | if(displayChar(cursor, '2')) { |
bhavk11 | 4:5b088ba4f1f1 | 471 | *ptr = '2'; |
bhavk11 | 4:5b088ba4f1f1 | 472 | ptr++; |
bhavk11 | 4:5b088ba4f1f1 | 473 | } |
bhavk11 | 4:5b088ba4f1f1 | 474 | break; |
bhavk11 | 4:5b088ba4f1f1 | 475 | case 3: |
bhavk11 | 4:5b088ba4f1f1 | 476 | if(displayChar(cursor, '3')) { |
bhavk11 | 4:5b088ba4f1f1 | 477 | *ptr = '3'; |
bhavk11 | 4:5b088ba4f1f1 | 478 | ptr++; |
bhavk11 | 4:5b088ba4f1f1 | 479 | } |
bhavk11 | 4:5b088ba4f1f1 | 480 | break; |
bhavk11 | 4:5b088ba4f1f1 | 481 | case 4: |
bhavk11 | 4:5b088ba4f1f1 | 482 | if(displayChar(cursor, '4')) { |
bhavk11 | 4:5b088ba4f1f1 | 483 | *ptr = '4'; |
bhavk11 | 4:5b088ba4f1f1 | 484 | ptr++; |
bhavk11 | 4:5b088ba4f1f1 | 485 | } |
bhavk11 | 4:5b088ba4f1f1 | 486 | break; |
bhavk11 | 4:5b088ba4f1f1 | 487 | case 5: |
bhavk11 | 4:5b088ba4f1f1 | 488 | if(displayChar(cursor, '5')) { |
bhavk11 | 4:5b088ba4f1f1 | 489 | *ptr = '5'; |
bhavk11 | 4:5b088ba4f1f1 | 490 | ptr++; |
bhavk11 | 4:5b088ba4f1f1 | 491 | } |
bhavk11 | 4:5b088ba4f1f1 | 492 | break; |
bhavk11 | 4:5b088ba4f1f1 | 493 | case 6: |
bhavk11 | 4:5b088ba4f1f1 | 494 | if(displayChar(cursor, '6')) { |
bhavk11 | 4:5b088ba4f1f1 | 495 | *ptr = '6'; |
bhavk11 | 4:5b088ba4f1f1 | 496 | ptr++; |
bhavk11 | 4:5b088ba4f1f1 | 497 | } |
bhavk11 | 4:5b088ba4f1f1 | 498 | break; |
bhavk11 | 4:5b088ba4f1f1 | 499 | case 7: |
bhavk11 | 4:5b088ba4f1f1 | 500 | if(displayChar(cursor, '7')) { |
bhavk11 | 4:5b088ba4f1f1 | 501 | *ptr = '7'; |
bhavk11 | 4:5b088ba4f1f1 | 502 | ptr++; |
bhavk11 | 4:5b088ba4f1f1 | 503 | } |
bhavk11 | 4:5b088ba4f1f1 | 504 | break; |
bhavk11 | 4:5b088ba4f1f1 | 505 | case 8: |
bhavk11 | 4:5b088ba4f1f1 | 506 | if(displayChar(cursor, '8')) { |
bhavk11 | 4:5b088ba4f1f1 | 507 | *ptr = '8'; |
bhavk11 | 4:5b088ba4f1f1 | 508 | ptr++; |
bhavk11 | 4:5b088ba4f1f1 | 509 | } |
bhavk11 | 4:5b088ba4f1f1 | 510 | break; |
bhavk11 | 4:5b088ba4f1f1 | 511 | case 9: |
bhavk11 | 4:5b088ba4f1f1 | 512 | if(displayChar(cursor, '9')) { |
bhavk11 | 4:5b088ba4f1f1 | 513 | *ptr = '9'; |
bhavk11 | 4:5b088ba4f1f1 | 514 | ptr++; |
bhavk11 | 4:5b088ba4f1f1 | 515 | } |
bhavk11 | 4:5b088ba4f1f1 | 516 | break; |
bhavk11 | 4:5b088ba4f1f1 | 517 | case 35: |
bhavk11 | 4:5b088ba4f1f1 | 518 | if(displayChar(cursor, '#')) { |
bhavk11 | 4:5b088ba4f1f1 | 519 | *ptr = '#'; |
bhavk11 | 4:5b088ba4f1f1 | 520 | ptr++; |
bhavk11 | 4:5b088ba4f1f1 | 521 | } |
bhavk11 | 4:5b088ba4f1f1 | 522 | break; |
bhavk11 | 4:5b088ba4f1f1 | 523 | case 42: |
bhavk11 | 4:5b088ba4f1f1 | 524 | if(displayChar(cursor, '*')) { |
bhavk11 | 4:5b088ba4f1f1 | 525 | *ptr = '*'; |
bhavk11 | 4:5b088ba4f1f1 | 526 | ptr++; |
bhavk11 | 4:5b088ba4f1f1 | 527 | } |
bhavk11 | 4:5b088ba4f1f1 | 528 | break; |
bhavk11 | 4:5b088ba4f1f1 | 529 | case 43: |
bhavk11 | 6:2a920ec91d2b | 530 | if(isMsg) |
bhavk11 | 6:2a920ec91d2b | 531 | cmd = "Send"; |
bhavk11 | 6:2a920ec91d2b | 532 | else |
bhavk11 | 6:2a920ec91d2b | 533 | cmd = "Make"; |
bhavk11 | 6:2a920ec91d2b | 534 | isMsg = false; |
uswickra | 5:c1af1f8fa026 | 535 | *ptr= '\0'; |
bhavk11 | 4:5b088ba4f1f1 | 536 | break; |
bhavk11 | 4:5b088ba4f1f1 | 537 | case 60: |
bhavk11 | 4:5b088ba4f1f1 | 538 | cmd = "Back"; |
bhavk11 | 6:2a920ec91d2b | 539 | isMsg = false; |
bhavk11 | 4:5b088ba4f1f1 | 540 | break; |
bhavk11 | 4:5b088ba4f1f1 | 541 | case 127: |
bhavk11 | 6:2a920ec91d2b | 542 | if(ptr > numbuffer) |
bhavk11 | 4:5b088ba4f1f1 | 543 | { |
bhavk11 | 4:5b088ba4f1f1 | 544 | ptr--; |
uswickra | 5:c1af1f8fa026 | 545 | if(cursor.x - 12 >= 0) |
uswickra | 5:c1af1f8fa026 | 546 | cursor.x -= 12; |
bhavk11 | 4:5b088ba4f1f1 | 547 | else |
bhavk11 | 4:5b088ba4f1f1 | 548 | { |
uswickra | 5:c1af1f8fa026 | 549 | cursor.x = 240; |
bhavk11 | 4:5b088ba4f1f1 | 550 | if(cursor.y - 21 >= 5 ) |
bhavk11 | 4:5b088ba4f1f1 | 551 | cursor.y -= 21; |
bhavk11 | 4:5b088ba4f1f1 | 552 | } |
bhavk11 | 4:5b088ba4f1f1 | 553 | TFT.locate(cursor.x,cursor.y); |
bhavk11 | 4:5b088ba4f1f1 | 554 | TFT.printf(" "); |
bhavk11 | 4:5b088ba4f1f1 | 555 | } |
bhavk11 | 4:5b088ba4f1f1 | 556 | break; |
bhavk11 | 4:5b088ba4f1f1 | 557 | } |
bhavk11 | 4:5b088ba4f1f1 | 558 | } |
bhavk11 | 4:5b088ba4f1f1 | 559 | if(strcmp(cmd, "Make") == 0) |
bhavk11 | 4:5b088ba4f1f1 | 560 | { |
bhavk11 | 4:5b088ba4f1f1 | 561 | TFT.background(Black); |
bhavk11 | 4:5b088ba4f1f1 | 562 | TFT.foreground(White); |
bhavk11 | 4:5b088ba4f1f1 | 563 | TFT.cls(); |
bhavk11 | 4:5b088ba4f1f1 | 564 | int i=0; |
bhavk11 | 4:5b088ba4f1f1 | 565 | cursor.x = 0; |
bhavk11 | 4:5b088ba4f1f1 | 566 | cursor.y = 5; |
bhavk11 | 4:5b088ba4f1f1 | 567 | TFT.locate(0,0); |
uswickra | 7:5cf5aeae1954 | 568 | int ret = gsm.call_phone(numbuffer); |
bhavk11 | 6:2a920ec91d2b | 569 | while(&numbuffer[i] < ptr) |
bhavk11 | 6:2a920ec91d2b | 570 | displayChar(cursor, numbuffer[i++]); |
bhavk11 | 4:5b088ba4f1f1 | 571 | TFT.line(0,270,240,270,Red); |
bhavk11 | 4:5b088ba4f1f1 | 572 | TFT.foreground(Red); |
bhavk11 | 4:5b088ba4f1f1 | 573 | TFT.locate(60,280); |
bhavk11 | 4:5b088ba4f1f1 | 574 | TFT.printf("Hang Up"); |
uswickra | 11:575dfd388778 | 575 | // int_state = 0 ; |
bhavk11 | 4:5b088ba4f1f1 | 576 | while(strcmp(cmd, "Make") == 0) |
bhavk11 | 4:5b088ba4f1f1 | 577 | { |
uswickra | 5:c1af1f8fa026 | 578 | if(TFT.getTouch(p) == TFT.YES && p.x >= 6300 && p.x <= 7250){ |
uswickra | 5:c1af1f8fa026 | 579 | gsm.hangup_phone(); |
uswickra | 11:575dfd388778 | 580 | // int_state = 1 ; |
uswickra | 11:575dfd388778 | 581 | int_state = false ; |
bhavk11 | 4:5b088ba4f1f1 | 582 | cmd = "Back"; |
uswickra | 5:c1af1f8fa026 | 583 | |
uswickra | 5:c1af1f8fa026 | 584 | } |
bhavk11 | 4:5b088ba4f1f1 | 585 | } |
bhavk11 | 4:5b088ba4f1f1 | 586 | } |
bhavk11 | 6:2a920ec91d2b | 587 | else if(strcmp(cmd,"Send") == 0) |
bhavk11 | 6:2a920ec91d2b | 588 | { |
bhavk11 | 6:2a920ec91d2b | 589 | // numbuffer has number |
bhavk11 | 6:2a920ec91d2b | 590 | // msgbuffer has msg |
bhavk11 | 6:2a920ec91d2b | 591 | TFT.background(Black); |
bhavk11 | 6:2a920ec91d2b | 592 | TFT.foreground(White); |
bhavk11 | 6:2a920ec91d2b | 593 | TFT.cls(); |
bhavk11 | 6:2a920ec91d2b | 594 | TFT.locate(90,60); |
uswickra | 11:575dfd388778 | 595 | TFT.printf("Sending number : %s ", numbuffer, msgbuffer); |
uswickra | 11:575dfd388778 | 596 | // int_state = 0 ; |
uswickra | 11:575dfd388778 | 597 | int_state = true ; |
uswickra | 11:575dfd388778 | 598 | gsm.send_sms(numbuffer, msgbuffer); |
bhavk11 | 6:2a920ec91d2b | 599 | TFT.locate(90,95); |
uswickra | 11:575dfd388778 | 600 | TFT.printf("Done Text... "); |
uswickra | 11:575dfd388778 | 601 | // int_state = 1; |
uswickra | 11:575dfd388778 | 602 | int_state = false ; |
bhavk11 | 6:2a920ec91d2b | 603 | wait(2.5); |
bhavk11 | 6:2a920ec91d2b | 604 | cmd = "Back"; |
bhavk11 | 6:2a920ec91d2b | 605 | } |
bhavk11 | 4:5b088ba4f1f1 | 606 | if(strcmp(cmd, "Back") == 0) |
bhavk11 | 4:5b088ba4f1f1 | 607 | { |
bhavk11 | 4:5b088ba4f1f1 | 608 | //Home screen |
bhavk11 | 4:5b088ba4f1f1 | 609 | } |
bhavk11 | 4:5b088ba4f1f1 | 610 | } |
bhavk11 | 4:5b088ba4f1f1 | 611 | else if(strcmp(cmd, "Text") == 0) |
bhavk11 | 4:5b088ba4f1f1 | 612 | { |
bhavk11 | 4:5b088ba4f1f1 | 613 | initKeypad(); |
bhavk11 | 4:5b088ba4f1f1 | 614 | printKey(130,280,"SEND","" ); |
bhavk11 | 4:5b088ba4f1f1 | 615 | point cursor; |
bhavk11 | 4:5b088ba4f1f1 | 616 | cursor.x = 0; |
bhavk11 | 4:5b088ba4f1f1 | 617 | cursor.y = 5; |
bhavk11 | 6:2a920ec91d2b | 618 | char *ptr = msgbuffer; |
bhavk11 | 4:5b088ba4f1f1 | 619 | //TFT.line(80,100,80,320,Black); |
bhavk11 | 4:5b088ba4f1f1 | 620 | // TFT.line(160,100,160,320,Black); |
bhavk11 | 4:5b088ba4f1f1 | 621 | // TFT.line(0,100,240,100,Black); |
bhavk11 | 4:5b088ba4f1f1 | 622 | // TFT.line(0,150,240,150,Black); |
bhavk11 | 4:5b088ba4f1f1 | 623 | // TFT.line(0,190,240,190,Black); |
bhavk11 | 4:5b088ba4f1f1 | 624 | // TFT.line(0,230,240,230,Black); |
bhavk11 | 4:5b088ba4f1f1 | 625 | // TFT.line(0,270,240,270,Black); |
bhavk11 | 4:5b088ba4f1f1 | 626 | while(strcmp(cmd, "Text") == 0) |
bhavk11 | 4:5b088ba4f1f1 | 627 | { |
uswickra | 5:c1af1f8fa026 | 628 | int key = getAlpha(cursor, &ptr); |
uswickra | 5:c1af1f8fa026 | 629 | |
bhavk11 | 4:5b088ba4f1f1 | 630 | switch(key) |
bhavk11 | 4:5b088ba4f1f1 | 631 | { |
bhavk11 | 4:5b088ba4f1f1 | 632 | case 43: |
bhavk11 | 6:2a920ec91d2b | 633 | isMsg = true; |
bhavk11 | 6:2a920ec91d2b | 634 | cmd = "Call"; |
bhavk11 | 4:5b088ba4f1f1 | 635 | break; |
bhavk11 | 4:5b088ba4f1f1 | 636 | case 60: |
bhavk11 | 4:5b088ba4f1f1 | 637 | cmd = "Back"; |
bhavk11 | 4:5b088ba4f1f1 | 638 | break; |
bhavk11 | 4:5b088ba4f1f1 | 639 | case 127: |
bhavk11 | 6:2a920ec91d2b | 640 | if(ptr > msgbuffer) |
bhavk11 | 4:5b088ba4f1f1 | 641 | { |
bhavk11 | 4:5b088ba4f1f1 | 642 | ptr--; |
uswickra | 5:c1af1f8fa026 | 643 | if(cursor.x - 12 >= 0) |
uswickra | 5:c1af1f8fa026 | 644 | cursor.x -= 12; |
bhavk11 | 4:5b088ba4f1f1 | 645 | else |
bhavk11 | 4:5b088ba4f1f1 | 646 | { |
uswickra | 5:c1af1f8fa026 | 647 | cursor.x = 240; |
bhavk11 | 4:5b088ba4f1f1 | 648 | if(cursor.y - 21 >= 5 ) |
bhavk11 | 4:5b088ba4f1f1 | 649 | cursor.y -= 21; |
bhavk11 | 4:5b088ba4f1f1 | 650 | } |
bhavk11 | 4:5b088ba4f1f1 | 651 | TFT.locate(cursor.x,cursor.y); |
bhavk11 | 4:5b088ba4f1f1 | 652 | TFT.printf(" "); |
bhavk11 | 4:5b088ba4f1f1 | 653 | } |
bhavk11 | 4:5b088ba4f1f1 | 654 | break; |
bhavk11 | 4:5b088ba4f1f1 | 655 | } |
bhavk11 | 4:5b088ba4f1f1 | 656 | } |
bhavk11 | 6:2a920ec91d2b | 657 | } |
bhavk11 | 6:2a920ec91d2b | 658 | else if (strcmp(cmd, "Ring") == 0) |
uswickra | 5:c1af1f8fa026 | 659 | { |
uswickra | 5:c1af1f8fa026 | 660 | TFT.background(Black); |
uswickra | 5:c1af1f8fa026 | 661 | TFT.foreground(White); |
uswickra | 5:c1af1f8fa026 | 662 | TFT.cls(); |
uswickra | 5:c1af1f8fa026 | 663 | TFT.locate(0,0); |
uswickra | 5:c1af1f8fa026 | 664 | TFT.printf("Incoming Call..."); |
uswickra | 5:c1af1f8fa026 | 665 | TFT.foreground(Green); |
uswickra | 5:c1af1f8fa026 | 666 | TFT.set_font((unsigned char*) Arial24x23); |
uswickra | 5:c1af1f8fa026 | 667 | TFT.locate(28,230); |
uswickra | 5:c1af1f8fa026 | 668 | TFT.printf("ANS"); |
bhavk11 | 6:2a920ec91d2b | 669 | TFT.circle(60,240,50,Green); |
uswickra | 5:c1af1f8fa026 | 670 | |
uswickra | 5:c1af1f8fa026 | 671 | TFT.foreground(Red); |
bhavk11 | 6:2a920ec91d2b | 672 | TFT.locate(140,220); |
bhavk11 | 6:2a920ec91d2b | 673 | TFT.printf("HANG"); |
bhavk11 | 6:2a920ec91d2b | 674 | TFT.locate(160,240); |
bhavk11 | 6:2a920ec91d2b | 675 | TFT.printf("UP"); |
bhavk11 | 6:2a920ec91d2b | 676 | TFT.circle(180,240,50,Red); |
bhavk11 | 6:2a920ec91d2b | 677 | while(strcmp(cmd, "Ring") == 0) |
uswickra | 5:c1af1f8fa026 | 678 | { |
bhavk11 | 6:2a920ec91d2b | 679 | if (TFT.getTouch(p) == TFT.YES) |
bhavk11 | 6:2a920ec91d2b | 680 | { |
bhavk11 | 6:2a920ec91d2b | 681 | if(p.x >= 4500 && p.x <= 6600) |
bhavk11 | 6:2a920ec91d2b | 682 | { |
bhavk11 | 6:2a920ec91d2b | 683 | if(p.y >= 1500 && p.y <= 3800) |
bhavk11 | 6:2a920ec91d2b | 684 | { |
bhavk11 | 6:2a920ec91d2b | 685 | //answer cal |
bhavk11 | 6:2a920ec91d2b | 686 | cmd = "Answer"; |
uswickra | 10:5ea126441b8a | 687 | gsm.recv_phone(); |
bhavk11 | 6:2a920ec91d2b | 688 | break; |
bhavk11 | 6:2a920ec91d2b | 689 | } |
bhavk11 | 6:2a920ec91d2b | 690 | else if(p.y >= 4500 && p.y <= 7100) |
bhavk11 | 6:2a920ec91d2b | 691 | { |
bhavk11 | 6:2a920ec91d2b | 692 | //hang up |
bhavk11 | 6:2a920ec91d2b | 693 | cmd = "Back"; |
uswickra | 10:5ea126441b8a | 694 | gsm.hangup_phone(); |
uswickra | 11:575dfd388778 | 695 | // int_state = 1 ; |
uswickra | 11:575dfd388778 | 696 | int_state = false ; |
bhavk11 | 6:2a920ec91d2b | 697 | break; |
bhavk11 | 6:2a920ec91d2b | 698 | } |
bhavk11 | 6:2a920ec91d2b | 699 | |
bhavk11 | 6:2a920ec91d2b | 700 | } |
bhavk11 | 6:2a920ec91d2b | 701 | } |
bhavk11 | 6:2a920ec91d2b | 702 | } |
bhavk11 | 6:2a920ec91d2b | 703 | if(strcmp(cmd, "Answer") == 0) |
bhavk11 | 6:2a920ec91d2b | 704 | { |
bhavk11 | 6:2a920ec91d2b | 705 | TFT.background(Black); |
bhavk11 | 6:2a920ec91d2b | 706 | TFT.foreground(White); |
bhavk11 | 6:2a920ec91d2b | 707 | TFT.cls(); |
bhavk11 | 6:2a920ec91d2b | 708 | TFT.locate(0,0); |
bhavk11 | 6:2a920ec91d2b | 709 | TFT.printf("Call in Progress..."); |
bhavk11 | 6:2a920ec91d2b | 710 | TFT.line(0,270,240,270,Red); |
bhavk11 | 6:2a920ec91d2b | 711 | TFT.foreground(Red); |
bhavk11 | 6:2a920ec91d2b | 712 | TFT.locate(60,280); |
bhavk11 | 6:2a920ec91d2b | 713 | TFT.set_font((unsigned char*) Arial24x23); |
bhavk11 | 6:2a920ec91d2b | 714 | TFT.printf("Hang Up"); |
bhavk11 | 6:2a920ec91d2b | 715 | while(strcmp(cmd, "Answer") == 0) |
bhavk11 | 6:2a920ec91d2b | 716 | { |
uswickra | 10:5ea126441b8a | 717 | if(TFT.getTouch(p) == TFT.YES && p.x >= 6300 && p.x <= 7250){ |
bhavk11 | 6:2a920ec91d2b | 718 | cmd = "Back"; |
uswickra | 10:5ea126441b8a | 719 | gsm.hangup_phone(); |
uswickra | 11:575dfd388778 | 720 | // int_state = 1 ; |
uswickra | 11:575dfd388778 | 721 | int_state = false ; |
uswickra | 10:5ea126441b8a | 722 | } |
uswickra | 10:5ea126441b8a | 723 | |
bhavk11 | 6:2a920ec91d2b | 724 | } |
uswickra | 5:c1af1f8fa026 | 725 | } |
bhavk11 | 4:5b088ba4f1f1 | 726 | } |
bhavk11 | 6:2a920ec91d2b | 727 | else if(strcmp(cmd, "RecvM") == 0) |
uswickra | 11:575dfd388778 | 728 | { |
uswickra | 11:575dfd388778 | 729 | TFT.background(White); |
uswickra | 11:575dfd388778 | 730 | TFT.foreground(Blue); |
uswickra | 11:575dfd388778 | 731 | TFT.cls(); |
uswickra | 11:575dfd388778 | 732 | TFT.set_font((unsigned char*) Arial24x23); |
uswickra | 11:575dfd388778 | 733 | char *start_pos, *end_pos, *msg_pos; |
uswickra | 11:575dfd388778 | 734 | /* |
uswickra | 11:575dfd388778 | 735 | pc.putc('T'); |
uswickra | 11:575dfd388778 | 736 | wait(2); |
uswickra | 11:575dfd388778 | 737 | // pc.puts(gsm.messageBuffer ); |
uswickra | 11:575dfd388778 | 738 | pc.putc('U'); |
uswickra | 11:575dfd388778 | 739 | __disable_irq(); |
uswickra | 11:575dfd388778 | 740 | gsm.copy_msg(); |
uswickra | 11:575dfd388778 | 741 | __enable_irq();*/ |
uswickra | 11:575dfd388778 | 742 | |
uswickra | 11:575dfd388778 | 743 | pc.putc('S'); |
uswickra | 11:575dfd388778 | 744 | pc.printf("[SMS] : %s : \r\n", gsm.messageBuffer); |
uswickra | 11:575dfd388778 | 745 | |
uswickra | 11:575dfd388778 | 746 | start_pos = strstr(gsm.messageBuffer, "+CMT: \""); |
uswickra | 11:575dfd388778 | 747 | |
uswickra | 12:f27b67e10b0c | 748 | // TFT.locate(0,5); |
uswickra | 12:f27b67e10b0c | 749 | // TFT.printf("copyBuf %s \r\n",gsm.messageCopyBuffer); |
uswickra | 11:575dfd388778 | 750 | |
uswickra | 11:575dfd388778 | 751 | char txtnum[20]; |
uswickra | 11:575dfd388778 | 752 | cleanBuffer(txtnum,20); |
uswickra | 11:575dfd388778 | 753 | char recv_msg[140]; |
uswickra | 11:575dfd388778 | 754 | cleanBuffer(recv_msg,140); |
uswickra | 11:575dfd388778 | 755 | start_pos += 7; |
uswickra | 11:575dfd388778 | 756 | if(strstr(start_pos,"\",") != NULL) |
uswickra | 11:575dfd388778 | 757 | { |
uswickra | 11:575dfd388778 | 758 | end_pos = strstr(start_pos,"\","); |
uswickra | 11:575dfd388778 | 759 | strncpy(txtnum,start_pos,(end_pos - start_pos)); |
uswickra | 11:575dfd388778 | 760 | TFT.locate(0,5); |
uswickra | 11:575dfd388778 | 761 | TFT.printf("\r\nFrom: %s \r\n",txtnum); |
uswickra | 11:575dfd388778 | 762 | } |
uswickra | 11:575dfd388778 | 763 | if(strstr(start_pos,"\n") != NULL) |
uswickra | 11:575dfd388778 | 764 | { |
uswickra | 11:575dfd388778 | 765 | msg_pos = strstr(start_pos,"\n"); |
uswickra | 11:575dfd388778 | 766 | if(strstr(msg_pos+1,"\n") != NULL) |
uswickra | 11:575dfd388778 | 767 | { |
uswickra | 11:575dfd388778 | 768 | end_pos = strstr(msg_pos+1,"\n"); |
uswickra | 11:575dfd388778 | 769 | strncpy(recv_msg,msg_pos+1,(end_pos - msg_pos - 1)); |
uswickra | 11:575dfd388778 | 770 | TFT.locate(0,100); |
uswickra | 11:575dfd388778 | 771 | TFT.printf("Message: %s\r\n",recv_msg); |
uswickra | 11:575dfd388778 | 772 | } |
uswickra | 11:575dfd388778 | 773 | } |
uswickra | 11:575dfd388778 | 774 | TFT.line(0,270,240,270,Red); |
uswickra | 11:575dfd388778 | 775 | TFT.foreground(Blue); |
uswickra | 11:575dfd388778 | 776 | TFT.locate(60,280); |
uswickra | 11:575dfd388778 | 777 | TFT.set_font((unsigned char*) Arial24x23); |
uswickra | 11:575dfd388778 | 778 | TFT.printf("OK"); |
uswickra | 11:575dfd388778 | 779 | while(strcmp(cmd, "RecvM") == 0) |
uswickra | 11:575dfd388778 | 780 | { |
uswickra | 11:575dfd388778 | 781 | if(TFT.getTouch(p) == TFT.YES && p.x >= 6300 && p.x <= 7250) |
uswickra | 11:575dfd388778 | 782 | cmd = "Back"; |
uswickra | 11:575dfd388778 | 783 | // int_state = 1 ; |
uswickra | 11:575dfd388778 | 784 | int_state = false ; |
uswickra | 11:575dfd388778 | 785 | } |
uswickra | 11:575dfd388778 | 786 | } |
neilt6 | 0:407dafce805d | 787 | } |
neilt6 | 0:407dafce805d | 788 | } |