example application with TFT display and SMS receive send
Dependencies: C027 C027_Support SeeedStudioTFTv2 TFT_fonts UbloxUSBModem mbed
Fork of C027_DisplayTest by
This is an application that combines several libraries together and demonstartes the use of cellular, GPS and a Touch enabled TFT on the u-blox C027 board.
Diff: main.cpp
- Revision:
- 2:fde6fc911c61
- Parent:
- 0:bd6ef6f73032
- Child:
- 3:4ec009118465
--- a/main.cpp Fri Oct 18 18:31:33 2013 +0000 +++ b/main.cpp Mon Oct 21 19:46:57 2013 +0000 @@ -1,29 +1,38 @@ #include "mbed.h" -#include "C027_PinNames.h" +#include "C027.h" +#include "GPS.h" -#include "SPI_TFT_ILI9341.h" +#include "SeeedStudioTFTv2.h" #include "Arial12x12.h" #include "Arial24x23.h" #include "Arial28x28.h" #include "font_big.h" -#include "UbloxUSBGSMModem.h" -void ubxLogo(SPI_TFT_ILI9341* tft, int x0/*120*/, int y0/*160*/, int r) +#include "UbloxUSBGSMModem.h" +#include "UbloxUSBCDMAModem.h" +#include "UbloxGSMModem.h" + +void ubxLogo(SPI_TFT_ILI9341* tft, int x0/*160*/, int y0/*160*/, int r) { int i1=r/8, i1_5=r*3/16, i2=r*2/8, i3=r*3/8, i4=r*4/8, i5=r*5/8, i6=r*6/8, i7=r*7/8; // the ball tft->fillcircle(x0, y0, r, Red); // the dot - tft->fillcircle(x0-i3, y0+i2, i1_5, White); + tft->fillcircle(x0-i2, y0-i3, i1_5, White); // the u - tft->fillcircle(x0+i3, y0-i4, i3, White); - tft->fillcircle(x0+i3, y0-i4, i1, Red); - tft->fillrect( x0-i1, y0-i3, x0+i3, y0-i1, White); - tft->fillrect( x0-i1, y0-i5, x0+i3, y0-i3, Red); - tft->fillrect( x0-i1, y0-i7, x0+i6, y0-i5, White); + tft->fillcircle(x0+i4, y0+i3, i3, White); + tft->fillcircle(x0+i4, y0+i3, i1, Red); + tft->fillrect( x0+i1, y0-i1, x0+i3, y0+i3, White); + tft->fillrect( x0+i3, y0-i1, x0+i5, y0+i3, Red); + tft->fillrect( x0+i5, y0-i1, x0+i7, y0+i6, White); } +#define info(...) \ + TFT.locate(0,5), \ + TFT.fillrect(0,0,320,35,White), \ + TFT.printf(__VA_ARGS__) + void initC027(void) { DigitalOut mdmEn(MDMEN); @@ -41,46 +50,107 @@ mdmRst = 1; // RESET: 1=operating,0=reset Thread::wait(3000);// modem will be ready after 3 seconds } + int main() { - DigitalOut cs(D4); // sd card cs - DigitalOut bl(D7); // backlight - cs = 1; - bl = 1; - - SPI_TFT_ILI9341 TFT(D11, D12, D13, D5, D3/*dummy*/, D6, "TFT"); // mosi, miso, sclk, cs, reset + SeeedStudioTFTv2 TFT(A3, A1, A2, A0, + D11, D12, D13, + D5/*tft cs*/, D6/*tft dc*/, D7/*backlight*/, + D4/*sd cs*/); + TFT.setBacklight(true); + TFT.set_font((unsigned char*) Arial12x12); // select the font + TFT.set_orientation(3); + //TFT.calibrate(); // calibrate the touch TFT.background(White); // set background to black TFT.foreground(Black); // set chars to white TFT.cls(); // clear the screen - ubxLogo(&TFT, 120, 160, 80); - TFT.set_font((unsigned char*) Arial12x12); // select the font - TFT.set_orientation(3); + ubxLogo(&TFT, 160, 120, 80); TFT.locate(70,220); TFT.printf("u-blox C027-C20/U20/G35"); initC027(); + //C027 c027; + //c027.mdmPower(true); + GPS gps; UbloxUSBGSMModem modem; + size_t count; -//#define MY_PHONE_NUMBER "+41765858801" -#ifdef MY_PHONE_NUMBER - printf("Sending the SMS to\r\n" MY_PHONE_NUMBER "\r\n"); - modem.sendSM(MY_PHONE_NUMBER, "Hello from mbed:)"); -#endif + #define MY_IMEI "+41799613242" + info(" Cellular Modem\n IMEI: %s", MY_IMEI); + + char num[17] = "", msg[160+1] = ""; + clock_t c = clock(); while(true) { - size_t count; - if(!modem.getSMCount(&count) && (count > 0)) + clock_t n = clock(); + if ((n - c) > CLOCKS_PER_SEC) // every 3 seconds { - char num[17], msg[64]; - printf("%d SMS to read\n", count); - if(!modem.getSM(num, msg, sizeof(msg))) + int rssi; + LinkMonitor::REGISTRATION_STATE state; + LinkMonitor::BEARER bearer; + if (!modem.getLinkState(&rssi, &state, &bearer)) { - printf("%s : %s\r\n", num, msg); - TFT.fillrect(0,0,320,35,White); - TFT.locate(0,5); - TFT.printf("Phone: %s\nSMS:%s", num, msg); + const char* sState[] = + { " ", + "REG. ", + "DENIED", + "NO NET", + "HOME ", + "ROAM " }; + const char* sBearer[] = + { " ", + "GSM 2G ", + "EDGE 2.5G", + "UMTS 3G ", + "HSPA 3G+ ", + "LTE 4G " }; + TFT.locate(0,175); + TFT.printf(" %s\n" + " %s\n" + " %idBm ", sBearer[bearer],sState[state],rssi); + } + if((state >= LinkMonitor::REGISTRATION_STATE_HOME_NETWORK) && !modem.getSMCount(&count) && (count > 0)) + { + if(!modem.getSM(num, msg, sizeof(msg))) + { + info(" From: %s\n SMS:%s", num, msg); + } + } + c = n; + } + point p; + if (TFT.getPixel(p) && (p.y < 35) && *num) + { + const char* txt = "Hello from C027 :)"; + if (OK == modem.sendSM(num, txt)) + { + info(" To: %s\n SMS:%s", num, txt); + *num = 0; } } - Thread::wait(3000); + int ret; + while ((ret = gps.getGPS(msg, sizeof(msg))) > 0) + { + int len = LENGTH(ret); + if (PROTOCOL(ret) == NMEA && !strncmp("$GPGLL", msg, 6)) + { + double la = 0, lo = 0; + char cLa = 0, cLo = 0, ch = 0; + TFT.fillrect(220,175,320,210,White); + if (gps.getNmeaItem(1,msg,len,la) && gps.getNmeaItem(2,msg,len,cLa) && + gps.getNmeaItem(3,msg,len,lo) && gps.getNmeaItem(4,msg,len,cLo) && + gps.getNmeaItem(6,msg,len,ch) && ch == 'A') + { + if (cLa == 'S') la = -la; + if (cLo == 'N') lo = -lo; + TFT.locate(220,175); + TFT.printf(" GPS"); + TFT.locate(220,187); + TFT.printf("%11.4f ", la); + TFT.locate(220,199); + TFT.printf("%11.4f ", lo); + } + } + } } }