example application with TFT display and SMS receive send

Dependencies:   C027 C027_Support SeeedStudioTFTv2 TFT_fonts UbloxUSBModem mbed

Fork of C027_DisplayTest by Michael Ammann

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. /media/uploads/mazgch/c027_display.jpg

Committer:
amwe
Date:
Mon Mar 17 13:15:51 2014 +0000
Revision:
11:5c7f76702799
Parent:
10:2b1e6015e413
Back to rev 9

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mazgch 0:bd6ef6f73032 1 #include "mbed.h"
mazgch 2:fde6fc911c61 2 #include "C027.h"
mazgch 2:fde6fc911c61 3 #include "GPS.h"
mazgch 4:b18b0bc4142f 4 #include "SerialPipe.h"
mazgch 0:bd6ef6f73032 5
amwe 11:5c7f76702799 6 #include "SeeedStudioTFTv2.h"
amwe 11:5c7f76702799 7 #include "Arial12x12.h"
amwe 11:5c7f76702799 8 #include "Arial24x23.h"
amwe 11:5c7f76702799 9 #include "Arial28x28.h"
amwe 11:5c7f76702799 10 #include "font_big.h"
amwe 11:5c7f76702799 11
amwe 11:5c7f76702799 12 #include "UbloxModem.h"
amwe 11:5c7f76702799 13
amwe 11:5c7f76702799 14 void ubxLogo(SPI_TFT_ILI9341* tft, int x0/*160*/, int y0/*160*/, int r)
amwe 11:5c7f76702799 15 {
amwe 11:5c7f76702799 16 int i1=r/8, i1_5=r*3/16, i2=r*2/8, i3=r*3/8,
amwe 11:5c7f76702799 17 i4=r*4/8, i5=r*5/8, i6=r*6/8, i7=r*7/8;
amwe 11:5c7f76702799 18 // the ball
amwe 11:5c7f76702799 19 tft->fillcircle(x0, y0, r, Red);
amwe 11:5c7f76702799 20 // the dot
amwe 11:5c7f76702799 21 tft->fillcircle(x0-i2, y0-i3, i1_5, White);
amwe 11:5c7f76702799 22 // the u
amwe 11:5c7f76702799 23 tft->fillcircle(x0+i4, y0+i3, i3, White);
amwe 11:5c7f76702799 24 tft->fillcircle(x0+i4, y0+i3, i1, Red);
amwe 11:5c7f76702799 25 tft->fillrect( x0+i1, y0-i1, x0+i3, y0+i3, White);
amwe 11:5c7f76702799 26 tft->fillrect( x0+i3, y0-i1, x0+i5, y0+i3, Red);
amwe 11:5c7f76702799 27 tft->fillrect( x0+i5, y0-i1, x0+i7, y0+i6, White);
amwe 11:5c7f76702799 28 }
amwe 11:5c7f76702799 29
amwe 11:5c7f76702799 30 #define info(...) \
amwe 11:5c7f76702799 31 TFT.locate(0,5), \
amwe 11:5c7f76702799 32 TFT.fillrect(0,0,320,35,White), \
amwe 11:5c7f76702799 33 TFT.printf(__VA_ARGS__)
mazgch 2:fde6fc911c61 34
mazgch 0:bd6ef6f73032 35 int main()
mazgch 0:bd6ef6f73032 36 {
amwe 11:5c7f76702799 37 SeeedStudioTFTv2 TFT(A3, A1, A2, A0,
amwe 11:5c7f76702799 38 D11, D12, D13,
amwe 11:5c7f76702799 39 D5/*tft cs*/, D6/*tft dc*/, D7/*backlight*/,
amwe 11:5c7f76702799 40 D4/*sd cs*/);
amwe 11:5c7f76702799 41 TFT.setBacklight(true);
amwe 11:5c7f76702799 42 TFT.set_font((unsigned char*) Arial12x12); // select the font
amwe 11:5c7f76702799 43 TFT.set_orientation(3);
amwe 11:5c7f76702799 44 //TFT.calibrate(); // calibrate the touch
amwe 11:5c7f76702799 45 TFT.background(White); // set background to black
amwe 11:5c7f76702799 46 TFT.foreground(Black); // set chars to white
amwe 11:5c7f76702799 47 TFT.cls(); // clear the screen
amwe 11:5c7f76702799 48 ubxLogo(&TFT, 160, 120, 80);
amwe 11:5c7f76702799 49 TFT.locate(70,220);
amwe 11:5c7f76702799 50 TFT.printf("u-blox C027-C20/U20/G35");
amwe 11:5c7f76702799 51
mazgch 4:b18b0bc4142f 52 C027 c027;
amwe 11:5c7f76702799 53 //c027.mdmUsbEnable(true); // disable this is you plan to use the Serial port on LISA-C
amwe 11:5c7f76702799 54 c027.mdmPower(true);
mazgch 4:b18b0bc4142f 55 c027.gpsPower(true);
mazgch 4:b18b0bc4142f 56
amwe 11:5c7f76702799 57 GPSSerial gps;
amwe 11:5c7f76702799 58 //UbloxUSBModem modem; // LISA-U or LISA-C, don't forget to call the mdmUsbEnable above
amwe 11:5c7f76702799 59 UbloxSerModem modem; // LISA-U, LISA-C or SARA-G
amwe 11:5c7f76702799 60 size_t count;
mazgch 0:bd6ef6f73032 61
amwe 11:5c7f76702799 62 #define MY_IMEI "+41799613242"
amwe 11:5c7f76702799 63 info(" Cellular Modem\n IMEI: %s", MY_IMEI);
amwe 11:5c7f76702799 64
amwe 11:5c7f76702799 65 char num[17] = "", msg[160+1] = "";
amwe 11:5c7f76702799 66 char link[160] = "";
amwe 11:5c7f76702799 67 clock_t c = clock();
mazgch 0:bd6ef6f73032 68 while(true)
mazgch 0:bd6ef6f73032 69 {
amwe 11:5c7f76702799 70 clock_t n = clock();
amwe 11:5c7f76702799 71 if ((n - c) > CLOCKS_PER_SEC) // every 3 seconds
amwe 11:5c7f76702799 72 {
amwe 11:5c7f76702799 73 int rssi;
amwe 11:5c7f76702799 74 LinkMonitor::REGISTRATION_STATE state;
amwe 11:5c7f76702799 75 LinkMonitor::BEARER bearer;
amwe 11:5c7f76702799 76 if (!modem.getLinkState(&rssi, &state, &bearer))
amwe 11:5c7f76702799 77 {
amwe 11:5c7f76702799 78 const char* sState[] =
amwe 11:5c7f76702799 79 { " ",
amwe 11:5c7f76702799 80 "REG. ",
amwe 11:5c7f76702799 81 "DENIED",
amwe 11:5c7f76702799 82 "NO NET",
amwe 11:5c7f76702799 83 "HOME ",
amwe 11:5c7f76702799 84 "ROAM " };
amwe 11:5c7f76702799 85 const char* sBearer[] =
amwe 11:5c7f76702799 86 { " ",
amwe 11:5c7f76702799 87 "GSM 2G ",
amwe 11:5c7f76702799 88 "EDGE 2.5G",
amwe 11:5c7f76702799 89 "UMTS 3G ",
amwe 11:5c7f76702799 90 "HSPA 3G+ ",
amwe 11:5c7f76702799 91 "LTE 4G " };
amwe 11:5c7f76702799 92 TFT.locate(0,175);
amwe 11:5c7f76702799 93 TFT.printf(" %s\n"
amwe 11:5c7f76702799 94 " %s\n"
amwe 11:5c7f76702799 95 " %idBm ", sBearer[bearer],sState[state],rssi);
amwe 11:5c7f76702799 96 }
amwe 11:5c7f76702799 97 if((state >= LinkMonitor::REGISTRATION_STATE_HOME_NETWORK) && !modem.getSMCount(&count) && (count > 0))
amwe 11:5c7f76702799 98 {
amwe 11:5c7f76702799 99 if(!modem.getSM(num, msg, sizeof(msg)))
amwe 11:5c7f76702799 100 {
amwe 11:5c7f76702799 101 info(" From: %s\n SMS:%s", num, msg);
amwe 11:5c7f76702799 102 if (0 == strcmp(msg, "Where are you?") && *link)
amwe 11:5c7f76702799 103 {
amwe 11:5c7f76702799 104 modem.sendSM(num, link);
amwe 11:5c7f76702799 105 }
amwe 11:5c7f76702799 106 }
amwe 11:5c7f76702799 107 }
amwe 11:5c7f76702799 108 c = n;
amwe 11:5c7f76702799 109 }
amwe 11:5c7f76702799 110 point p;
amwe 11:5c7f76702799 111 if (TFT.getPixel(p) && (p.y < 35) && *num)
amwe 11:5c7f76702799 112 {
amwe 11:5c7f76702799 113 const char* txt = "Hello from C027 :)";
amwe 11:5c7f76702799 114 if (OK == modem.sendSM(num, txt))
amwe 11:5c7f76702799 115 {
amwe 11:5c7f76702799 116 info(" To: %s\n SMS:%s", num, txt);
amwe 11:5c7f76702799 117 *num = 0;
amwe 11:5c7f76702799 118 }
amwe 11:5c7f76702799 119 }
mazgch 2:fde6fc911c61 120 int ret;
mazgch 4:b18b0bc4142f 121 while ((ret = gps.getMessage(msg, sizeof(msg))) > 0)
mazgch 2:fde6fc911c61 122 {
mazgch 2:fde6fc911c61 123 int len = LENGTH(ret);
mazgch 2:fde6fc911c61 124 if (PROTOCOL(ret) == NMEA && !strncmp("$GPGLL", msg, 6))
mazgch 2:fde6fc911c61 125 {
mazgch 2:fde6fc911c61 126 double la = 0, lo = 0;
mazgch 2:fde6fc911c61 127 char cLa = 0, cLo = 0, ch = 0;
amwe 11:5c7f76702799 128 TFT.fillrect(220,175,320,210,White);
amwe 11:5c7f76702799 129 TFT.locate(220,175);
amwe 11:5c7f76702799 130 TFT.printf(" GPS");
mazgch 2:fde6fc911c61 131 if (gps.getNmeaItem(1,msg,len,la) && gps.getNmeaItem(2,msg,len,cLa) &&
mazgch 2:fde6fc911c61 132 gps.getNmeaItem(3,msg,len,lo) && gps.getNmeaItem(4,msg,len,cLo) &&
mazgch 2:fde6fc911c61 133 gps.getNmeaItem(6,msg,len,ch) && ch == 'A')
mazgch 2:fde6fc911c61 134 {
mazgch 3:4ec009118465 135 la *= 0.01;
mazgch 3:4ec009118465 136 lo *= 0.01;
mazgch 3:4ec009118465 137 int iLa = (int)la;
mazgch 3:4ec009118465 138 int iLo = (int)lo;
mazgch 3:4ec009118465 139 la = (la - iLa) / 0.6 + iLa;
mazgch 3:4ec009118465 140 lo = (lo - iLo) / 0.6 + iLo;
mazgch 2:fde6fc911c61 141 if (cLa == 'S') la = -la;
amwe 11:5c7f76702799 142 if (cLo == 'N') lo = -lo;
mazgch 3:4ec009118465 143
amwe 11:5c7f76702799 144 TFT.locate(220,187);
amwe 11:5c7f76702799 145 TFT.printf("%11.6f ", la);
amwe 11:5c7f76702799 146 TFT.locate(220,199);
amwe 11:5c7f76702799 147 TFT.printf("%11.6f ", lo);
amwe 11:5c7f76702799 148 sprintf(link, "https://maps.google.com/?q=%.5f,%.5f", la, lo);
mazgch 2:fde6fc911c61 149 }
mazgch 2:fde6fc911c61 150 }
mazgch 2:fde6fc911c61 151 }
mazgch 0:bd6ef6f73032 152 }
mazgch 0:bd6ef6f73032 153 }