aaaa
Dependencies: SeeedStudioTFTv2 TFT_fonts mbed
Fork of Seeed_TFT_Touch_Shield by
Diff: main.cpp
- Revision:
- 5:c1af1f8fa026
- Parent:
- 4:5b088ba4f1f1
- Child:
- 6:2a920ec91d2b
diff -r 5b088ba4f1f1 -r c1af1f8fa026 main.cpp --- a/main.cpp Thu Oct 23 23:13:57 2014 +0000 +++ b/main.cpp Sat Oct 25 20:21:17 2014 +0000 @@ -42,6 +42,33 @@ Timer t; Serial pc(USBTX,USBRX); 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); +#define PHONE_NUMBER "+13174806512" +#include "Modem.h" + +Modem gsm (D10, D2, 19200, PHONE_NUMBER); +DigitalOut modem_power(D9); +char* cmd = NULL; + +void messageHandle(void) +{ + __disable_irq(); + int messageType = gsm.loopHandle(); + if(MESSAGE_RING == messageType) { +// gsm.answer(); + cmd = "Ring"; + pc.printf("recieved call.. \r\n"); + } else if(MESSAGE_SMS == messageType) { + char smsMessage[SMS_MAX_LENGTH]; +// gsm.getSMS(smsMessage); + pc.printf("recieved sms.. \r\n"); + int i = 0 ; + for(i = 0 ; i < SMS_MAX_LENGTH ; i++){ + pc.putc(smsMessage[i]); + } + } + __enable_irq(); +} + void printKey(int x, int y, char* digit, char* alphas) { @@ -153,141 +180,22 @@ return key; } -int getAlpha(int &touchCount) -{ - touchCount = 1; - int key, begin, end; - int prevKey; - do { - prevKey = key = getKey(); - }while(prevKey == -1); - - - t.reset(); - t.start(); - begin = t.read_ms(); - end = t.read_ms(); - while((end - begin) < 2000) - { - key = getKey(); - end = t.read_ms(); - if(key == -1) continue; - - touchCount++; - if(!(prevKey == key)){ - break; - } - pc.printf("ok curr count :%d key : %d prev_key : %d \r\n", touchCount,key, prevKey); - } - t.stop(); - pc.printf("ok count is :%d \r\n", touchCount); - return prevKey; -} +char ip0[] = {' ','0','+'}; +char ip2[] = {'a','b','c','2'}; +char ip3[] = {'d','e','f','3'}; +char ip4[] = {'g','h','i','4'}; +char ip5[] = {'j','k','l','5'}; +char ip6[] = {'m','o','p','6'}; +char ip7[] = {'p','q','r','s','7'}; +char ip8[] = {'t','u','v','8'}; +char ip9[] = {'w','x','y','z','9'}; -int getText(int &touchCount) -{ - int key = -1, prevKey = -1; - point p; - int count = 0; - touchCount = 0; - //int start=0,end=0; - bool firstTouch = false; - if(TFT.getTouch(p) == TFT.YES) - { - t.start(); - while( t.read()< 2 && prevKey == key) - { - //while(TFT.getTouch(p) == TFT.NO || TFT.getTouch(p) == TFT.MAYBE) - // {} - while(TFT.getTouch(p) == TFT.YES || TFT.getTouch(p) == TFT.MAYBE) - { - count++; - } - //TFT.printf("count %d\r\n",count); - if(count > 400) - { - //TFT.foreground(Black); - // TFT.set_font((unsigned char*) Arial12x12); - // TFT.locate(0,0); - // TFT.printf("X:%d, Y:%d\n\r",p.x,p.y); - // TFT.printf("count %d\r\n",count); - if(p.x>2700 && p.x<7250) - { - if(p.x<3750) - { - if(p.y<3000) - key = 1; //1 - else if(p.y<5250) - key = 2; //2 - else - key = 3; //3 - } - else if(p.x<4600) - { - if(p.y<3000) - key = 4; //4 - else if(p.y<5250) - key = 5; //5 - else - key = 6; //6 - } - else if(p.x<5400) - { - if(p.y<3000) - key = 7; //7 - else if(p.y<5250) - key = 8; //8 - else - key = 9; //9 - } - else if(p.x<6300) - { - if(p.y<3000) - key = 42; //* - else if(p.y<5250) - key = 0; //0 - else - key = 35; //# - } - else - { - if(p.y<3000) - key = 60; // back - else - key = 43; // go (call/text) - } - } - if(p.x > 2200 && p.x < 2500 && p.y > 6200 && p.y < 7000) - key = 127; - if(prevKey != -1 && prevKey == key) { - touchCount++; - TFT.printf("\r\ntouchCount %d %d",touchCount,prevKey); - } - if(!firstTouch) - { - firstTouch = true; - prevKey = key; - touchCount++; - } - } - /*if(t.read()>2) { - TFT.locate(20,20); - TFT.printf("Khatam\r\n"); - break; - }*/ - count = 0; - // TFT.printf("jyada ho gaya\r\n"); - } - t.stop(); - } - return prevKey; -} bool displayChar(point& cursor, char letter) { TFT.locate(cursor.x,cursor.y); - if(cursor.x + 16 <= 208) - cursor.x += 16; + if(cursor.x + 12 <= 228) + cursor.x += 12; else { cursor.x = 0; @@ -296,29 +204,160 @@ else return false; } - TFT.set_font((unsigned char*) Arial24x23); + TFT.set_font((unsigned char*) Arial12x12); TFT.printf("%c",letter); return true; } +int getAlpha(point& x, char** pt) +{ + int touchCount = 1, count = 1; + int key, begin, end; + int prevKey; + do { + prevKey = key = getKey(); + }while(prevKey == -1); + + point cursor = x; + char* ptr = *pt; + t.reset(); + t.start(); + begin = t.read_ms(); + end = t.read_ms(); + while((end - begin) < 2000) + { + cursor = x; + ptr = *pt; + touchCount = count; +START: + switch(key) + { + case 0: + touchCount = (touchCount-1)%(sizeof(ip0)/sizeof(ip0[0])); + if(displayChar(cursor, ip0[touchCount])) { + *ptr = ip0[touchCount]; + ptr++; + } + break; + case 1: + if(displayChar(cursor, '1')) { + *ptr = '1'; + ptr++; + } + break; + case 2: + pc.printf("AAYA\r\n"); + touchCount = (touchCount-1)%(sizeof(ip2)/sizeof(ip2[0])); + if(displayChar(cursor, ip2[touchCount])) { + *ptr = ip2[touchCount]; + ptr++; + } + break; + case 3: + touchCount = (touchCount-1)%(sizeof(ip3)/sizeof(ip3[0])); + if(displayChar(cursor, ip3[touchCount])) { + *ptr = ip3[touchCount]; + ptr++; + } + break; + case 4: + touchCount = (touchCount-1)%(sizeof(ip4)/sizeof(ip4[0])); + if(displayChar(cursor, ip4[touchCount])) { + *ptr = ip4[touchCount]; + ptr++; + } + break; + case 5: + touchCount = (touchCount-1)%(sizeof(ip5)/sizeof(ip5[0])); + if(displayChar(cursor, ip5[touchCount])) { + *ptr = ip5[touchCount]; + ptr++; + } + break; + case 6: + touchCount = (touchCount-1)%(sizeof(ip6)/sizeof(ip6[0])); + if(displayChar(cursor, ip6[touchCount])) { + *ptr = ip6[touchCount]; + ptr++; + } + break; + case 7: + touchCount = (touchCount-1)%(sizeof(ip7)/sizeof(ip7[0])); + if(displayChar(cursor, ip7[touchCount])) { + *ptr = ip7[touchCount]; + ptr++; + } + break; + case 8: + touchCount = (touchCount-1)%(sizeof(ip8)/sizeof(ip8[0])); + if(displayChar(cursor, ip8[touchCount])) { + *ptr = ip8[touchCount]; + ptr++; + } + break; + case 9: + touchCount = (touchCount-1)%(sizeof(ip9)/sizeof(ip9[0])); + if(displayChar(cursor, ip9[touchCount])) { + *ptr = ip9[touchCount]; + ptr++; + } + break; + case 35: + if(displayChar(cursor, '#')) { + *ptr = '#'; + ptr++; + } + break; + case 42: + if(displayChar(cursor, '*')) { + *ptr = '*'; + ptr++; + } + break; + } + + key = getKey(); + end = t.read_ms(); + if(key == -1 && ((end - begin) < 2000)) goto START; + + if(!(prevKey == key)){ + break; + } + count++; + + pc.printf("ok curr count :%d key : %d prev_key : %d \r\n", touchCount,key, prevKey); + } + t.stop(); + pc.printf("ok count is :%d \r\n", touchCount); + + x = cursor; + *pt = ptr; + return prevKey; +} + + +void init_modem(){ + modem_power = 1 ; + wait(1); +// gsm.serial_modem.attach(&messageHandle); + while(gsm.init() != 1) { +// TFT.printf("waiting... \r\n"); + wait(1); + } +} + + int main() { point p; - char* cmd = NULL; + //Configure the display driver TFT.background(Black); TFT.foreground(White); TFT.cls(); - char ip0[] = {' ','0','+'}; - char ip2[] = {'a','b','c','2'}; - char ip3[] = {'d','e','f','3'}; - char ip4[] = {'g','h','i','4'}; - char ip5[] = {'j','k','l','5'}; - char ip6[] = {'m','o','p','6'}; - char ip7[] = {'p','q','r','s','7'}; - char ip8[] = {'t','u','v','8'}; - char ip9[] = {'w','x','y','z','9'}; - + //initialize the modem - may take few seconds + init_modem(); + while(true) { //Print a welcome message @@ -326,6 +365,7 @@ TFT.set_font((unsigned char*) Neu42x35); TFT.foreground(Maroon); TFT.cls(); + TFT.locate(100,60); TFT.printf("IU"); @@ -453,6 +493,7 @@ break; case 43: cmd = "Make"; + *ptr= '\0'; break; case 60: cmd = "Back"; @@ -461,11 +502,11 @@ if(ptr > buffer) { ptr--; - if(cursor.x - 16 >= 0) - cursor.x -= 16; + if(cursor.x - 12 >= 0) + cursor.x -= 12; else { - cursor.x = 224; + cursor.x = 240; if(cursor.y - 21 >= 5 ) cursor.y -= 21; } @@ -484,6 +525,7 @@ cursor.x = 0; cursor.y = 5; TFT.locate(0,0); + int ret = gsm.call_phone(buffer); while(&buffer[i] < ptr) displayChar(cursor, buffer[i++]); TFT.line(0,270,240,270,Red); @@ -492,8 +534,11 @@ TFT.printf("Hang Up"); while(strcmp(cmd, "Make") == 0) { - if(TFT.getTouch(p) == TFT.YES && p.x >= 6300 && p.x <= 7250) + if(TFT.getTouch(p) == TFT.YES && p.x >= 6300 && p.x <= 7250){ + gsm.hangup_phone(); cmd = "Back"; + + } } } if(strcmp(cmd, "Back") == 0) @@ -519,91 +564,10 @@ // TFT.line(0,270,240,270,Black); while(strcmp(cmd, "Text") == 0) { - int touchCount=0; - int key = getAlpha(touchCount); + int key = getAlpha(cursor, &ptr); + switch(key) { - case 0: - touchCount = (touchCount-1)%(sizeof(ip0)/sizeof(ip0[0])); - if(displayChar(cursor, ip0[touchCount])) { - *ptr = ip0[touchCount]; - ptr++; - } - break; - case 1: - if(displayChar(cursor, '1')) { - *ptr = '1'; - ptr++; - } - break; - case 2: - touchCount = (touchCount-1)%(sizeof(ip2)/sizeof(ip2[0])); - if(displayChar(cursor, ip2[touchCount])) { - *ptr = ip2[touchCount]; - ptr++; - } - break; - case 3: - touchCount = (touchCount-1)%(sizeof(ip3)/sizeof(ip3[0])); - if(displayChar(cursor, ip3[touchCount])) { - *ptr = ip3[touchCount]; - ptr++; - } - break; - case 4: - touchCount = (touchCount-1)%(sizeof(ip4)/sizeof(ip4[0])); - if(displayChar(cursor, ip4[touchCount])) { - *ptr = ip4[touchCount]; - ptr++; - } - break; - case 5: - touchCount = (touchCount-1)%(sizeof(ip5)/sizeof(ip5[0])); - if(displayChar(cursor, ip5[touchCount])) { - *ptr = ip5[touchCount]; - ptr++; - } - break; - case 6: - touchCount = (touchCount-1)%(sizeof(ip6)/sizeof(ip6[0])); - if(displayChar(cursor, ip6[touchCount])) { - *ptr = ip6[touchCount]; - ptr++; - } - break; - case 7: - touchCount = (touchCount-1)%(sizeof(ip7)/sizeof(ip7[0])); - if(displayChar(cursor, ip7[touchCount])) { - *ptr = ip7[touchCount]; - ptr++; - } - break; - case 8: - touchCount = (touchCount-1)%(sizeof(ip8)/sizeof(ip8[0])); - if(displayChar(cursor, ip8[touchCount])) { - *ptr = ip8[touchCount]; - ptr++; - } - break; - case 9: - touchCount = (touchCount-1)%(sizeof(ip9)/sizeof(ip9[0])); - if(displayChar(cursor, ip9[touchCount])) { - *ptr = ip9[touchCount]; - ptr++; - } - break; - case 35: - if(displayChar(cursor, '#')) { - *ptr = '#'; - ptr++; - } - break; - case 42: - if(displayChar(cursor, '*')) { - *ptr = '*'; - ptr++; - } - break; case 43: cmd = "Send"; break; @@ -614,11 +578,11 @@ if(ptr > buffer) { ptr--; - if(cursor.x - 16 >= 0) - cursor.x -= 16; + if(cursor.x - 12 >= 0) + cursor.x -= 12; else { - cursor.x = 224; + cursor.x = 240; if(cursor.y - 21 >= 5 ) cursor.y -= 21; } @@ -640,6 +604,34 @@ wait(2.5); cmd = "Back"; } + }else if (strcmp(cmd, "Ring") == 0) + { + TFT.background(Black); + TFT.foreground(White); + TFT.cls(); +// int i=0; + //point cursor; +// cursor.x = 0; +// cursor.y = 5; + TFT.locate(0,0); + TFT.printf("Incoming Call..."); + TFT.foreground(Green); + TFT.set_font((unsigned char*) Arial24x23); + TFT.locate(28,230); + TFT.printf("ANS"); + TFT.circle(60,240,50,Maroon); + + TFT.foreground(Red); + TFT.locate(140,230); + TFT.printf("HANG UP"); + TFT.circle(180,240,50,Maroon); + while(strcmp(cmd, "Make") == 0) + { + if(TFT.getTouch(p) == TFT.YES && p.x >= 6300 && p.x <= 7250) + cmd = "Back"; + } } + + } }