aaaa
Dependencies: SeeedStudioTFTv2 TFT_fonts mbed
Fork of Seeed_TFT_Touch_Shield by
Diff: main.cpp
- Revision:
- 11:575dfd388778
- Parent:
- 10:5ea126441b8a
- Child:
- 12:f27b67e10b0c
--- a/main.cpp Sat Oct 25 23:43:01 2014 +0000 +++ b/main.cpp Sun Oct 26 08:41:39 2014 +0000 @@ -40,23 +40,29 @@ #define PIN_CS_SD D4 Timer t; -Serial pc(USBTX,USBRX); +//Serial pc(USBTX,USBRX); +Serial pc(SERIAL_TX, SERIAL_RX); + 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" +#define PHONE_NUMBER "+12246781239" #include "Modem.h" +void cleanBuffer(char *buffer, int count); + Modem gsm (D10, D2, 19200, PHONE_NUMBER); DigitalOut modem_power(D9); char* cmd = NULL; -int type = 0 ; -int int_state = 1 ; +volatile int type = 0 ; +volatile int disable = 0 ; +volatile int int_state = 0 ; +/* void rxCallback() { //__disable_irq(); if(gsm.serial_modem.readable()){ char c = gsm.serial_modem.getc(); type = gsm.updateBuffer(c); -// pc.putc(c); + pc.putc(c); if(int_state == 1 && type == MESSAGE_RING){ // pc.putc('R'); cmd = "Ring" ; @@ -65,6 +71,30 @@ } if(int_state == 1 && type == MESSAGE_SMS){ // pc.putc('S'); + cmd = "RecvM" ; + pc.putc('S'); + int_state = 0 ; + } + + } +//__enable_irq(); +}*/ + +void rxCallback() { +//__disable_irq(); + if(!int_state && gsm.serial_modem.readable()){ + char c = gsm.serial_modem.getc(); + type = gsm.updateBuffer(c); +// pc.putc(c); + if(type == MESSAGE_RING){ +// pc.putc('R'); + cmd = "Ring" ; + int_state = true; + } + if(type == MESSAGE_SMS){ +// pc.putc('S'); + cmd = "RecvM" ; + int_state = true; } } @@ -338,6 +368,8 @@ void init_modem(){ + modem_power = 0 ; + wait(5); modem_power = 1 ; wait(1); // gsm.serial_modem.attach(&messageHandle); @@ -352,6 +384,7 @@ int main() { point p; +// pc.baud(115200); bool isMsg = false; char numbuffer[140]; char msgbuffer[140]; @@ -362,6 +395,7 @@ TFT.cls(); //initialize the modem - may take few seconds init_modem(); + pc.printf("\r\n start \r\n"); while(true) { @@ -538,12 +572,13 @@ TFT.foreground(Red); TFT.locate(60,280); TFT.printf("Hang Up"); - int_state = 0 ; +// int_state = 0 ; while(strcmp(cmd, "Make") == 0) { if(TFT.getTouch(p) == TFT.YES && p.x >= 6300 && p.x <= 7250){ gsm.hangup_phone(); - int_state = 1 ; +// int_state = 1 ; + int_state = false ; cmd = "Back"; } @@ -557,9 +592,14 @@ TFT.foreground(White); TFT.cls(); TFT.locate(90,60); - TFT.printf("Text %s",msgbuffer); + TFT.printf("Sending number : %s ", numbuffer, msgbuffer); +// int_state = 0 ; + int_state = true ; + gsm.send_sms(numbuffer, msgbuffer); TFT.locate(90,95); - TFT.printf("Sent to %s!",numbuffer); + TFT.printf("Done Text... "); +// int_state = 1; + int_state = false ; wait(2.5); cmd = "Back"; } @@ -652,7 +692,8 @@ //hang up cmd = "Back"; gsm.hangup_phone(); - int_state = 1 ; +// int_state = 1 ; + int_state = false ; break; } @@ -676,13 +717,72 @@ if(TFT.getTouch(p) == TFT.YES && p.x >= 6300 && p.x <= 7250){ cmd = "Back"; gsm.hangup_phone(); - int_state = 1 ; +// int_state = 1 ; + int_state = false ; } } } } else if(strcmp(cmd, "RecvM") == 0) - {} + { + TFT.background(White); + TFT.foreground(Blue); + TFT.cls(); + TFT.set_font((unsigned char*) Arial24x23); + char *start_pos, *end_pos, *msg_pos; + /* + pc.putc('T'); + wait(2); +// pc.puts(gsm.messageBuffer ); + pc.putc('U'); + __disable_irq(); + gsm.copy_msg(); + __enable_irq();*/ + + pc.putc('S'); + pc.printf("[SMS] : %s : \r\n", gsm.messageBuffer); + + start_pos = strstr(gsm.messageBuffer, "+CMT: \""); + + TFT.locate(0,5); + TFT.printf("copyBuf %s \r\n",gsm.messageCopyBuffer); + + char txtnum[20]; + cleanBuffer(txtnum,20); + char recv_msg[140]; + cleanBuffer(recv_msg,140); + start_pos += 7; + if(strstr(start_pos,"\",") != NULL) + { + end_pos = strstr(start_pos,"\","); + strncpy(txtnum,start_pos,(end_pos - start_pos)); + TFT.locate(0,5); + TFT.printf("\r\nFrom: %s \r\n",txtnum); + } + if(strstr(start_pos,"\n") != NULL) + { + msg_pos = strstr(start_pos,"\n"); + if(strstr(msg_pos+1,"\n") != NULL) + { + end_pos = strstr(msg_pos+1,"\n"); + strncpy(recv_msg,msg_pos+1,(end_pos - msg_pos - 1)); + TFT.locate(0,100); + TFT.printf("Message: %s\r\n",recv_msg); + } + } + TFT.line(0,270,240,270,Red); + TFT.foreground(Blue); + TFT.locate(60,280); + TFT.set_font((unsigned char*) Arial24x23); + TFT.printf("OK"); + while(strcmp(cmd, "RecvM") == 0) + { + if(TFT.getTouch(p) == TFT.YES && p.x >= 6300 && p.x <= 7250) + cmd = "Back"; +// int_state = 1 ; + int_state = false ; + } + } } }