example application with TFT display and SMS receive send
Dependencies: C027 C027_Support SeeedStudioTFTv2 TFT_fonts UbloxUSBModem mbed
Fork of C027_DisplayTest by
main.cpp
00001 #include "mbed.h" 00002 #include "C027.h" 00003 #include "GPS.h" 00004 #include "SerialPipe.h" 00005 00006 #include "SeeedStudioTFTv2.h" 00007 #include "Arial12x12.h" 00008 #include "Arial24x23.h" 00009 #include "Arial28x28.h" 00010 #include "font_big.h" 00011 00012 #include "UbloxModem.h" 00013 00014 void ubxLogo(SPI_TFT_ILI9341* tft, int x0/*160*/, int y0/*160*/, int r) 00015 { 00016 int i1=r/8, i1_5=r*3/16, i2=r*2/8, i3=r*3/8, 00017 i4=r*4/8, i5=r*5/8, i6=r*6/8, i7=r*7/8; 00018 // the ball 00019 tft->fillcircle(x0, y0, r, Red); 00020 // the dot 00021 tft->fillcircle(x0-i2, y0-i3, i1_5, White); 00022 // the u 00023 tft->fillcircle(x0+i4, y0+i3, i3, White); 00024 tft->fillcircle(x0+i4, y0+i3, i1, Red); 00025 tft->fillrect( x0+i1, y0-i1, x0+i3, y0+i3, White); 00026 tft->fillrect( x0+i3, y0-i1, x0+i5, y0+i3, Red); 00027 tft->fillrect( x0+i5, y0-i1, x0+i7, y0+i6, White); 00028 } 00029 00030 #define info(...) \ 00031 TFT.locate(0,5), \ 00032 TFT.fillrect(0,0,320,35,White), \ 00033 TFT.printf(__VA_ARGS__) 00034 00035 int main() 00036 { 00037 SeeedStudioTFTv2 TFT(A3, A1, A2, A0, 00038 D11, D12, D13, 00039 D5/*tft cs*/, D6/*tft dc*/, D7/*backlight*/, 00040 D4/*sd cs*/); 00041 TFT.setBacklight(true); 00042 TFT.set_font((unsigned char*) Arial12x12); // select the font 00043 TFT.set_orientation(3); 00044 //TFT.calibrate(); // calibrate the touch 00045 TFT.background(White); // set background to black 00046 TFT.foreground(Black); // set chars to white 00047 TFT.cls(); // clear the screen 00048 ubxLogo(&TFT, 160, 120, 80); 00049 TFT.locate(70,220); 00050 TFT.printf("u-blox C027-C20/U20/G35"); 00051 00052 C027 c027; 00053 //c027.mdmUsbEnable(true); // disable this is you plan to use the Serial port on LISA-C 00054 c027.mdmPower(true); 00055 c027.gpsPower(true); 00056 00057 GPSSerial gps; 00058 //UbloxUSBModem modem; // LISA-U or LISA-C, don't forget to call the mdmUsbEnable above 00059 UbloxSerModem modem; // LISA-U, LISA-C or SARA-G 00060 size_t count; 00061 00062 #define MY_IMEI "+41799613242" 00063 info(" Cellular Modem\n IMEI: %s", MY_IMEI); 00064 00065 char num[17] = "", msg[160+1] = ""; 00066 char link[160] = ""; 00067 clock_t c = clock(); 00068 while(true) 00069 { 00070 clock_t n = clock(); 00071 if ((n - c) > CLOCKS_PER_SEC) // every 3 seconds 00072 { 00073 int rssi; 00074 LinkMonitor::REGISTRATION_STATE state; 00075 LinkMonitor::BEARER bearer; 00076 if (!modem.getLinkState(&rssi, &state, &bearer)) 00077 { 00078 const char* sState[] = 00079 { " ", 00080 "REG. ", 00081 "DENIED", 00082 "NO NET", 00083 "HOME ", 00084 "ROAM " }; 00085 const char* sBearer[] = 00086 { " ", 00087 "GSM 2G ", 00088 "EDGE 2.5G", 00089 "UMTS 3G ", 00090 "HSPA 3G+ ", 00091 "LTE 4G " }; 00092 TFT.locate(0,175); 00093 TFT.printf(" %s\n" 00094 " %s\n" 00095 " %idBm ", sBearer[bearer],sState[state],rssi); 00096 } 00097 if((state >= LinkMonitor::REGISTRATION_STATE_HOME_NETWORK) && !modem.getSMCount(&count) && (count > 0)) 00098 { 00099 if(!modem.getSM(num, msg, sizeof(msg))) 00100 { 00101 info(" From: %s\n SMS:%s", num, msg); 00102 if (0 == strcmp(msg, "Where are you?") && *link) 00103 { 00104 modem.sendSM(num, link); 00105 } 00106 } 00107 } 00108 c = n; 00109 } 00110 point p; 00111 if (TFT.getPixel(p) && (p.y < 35) && *num) 00112 { 00113 const char* txt = "Hello from C027 :)"; 00114 if (OK == modem.sendSM(num, txt)) 00115 { 00116 info(" To: %s\n SMS:%s", num, txt); 00117 *num = 0; 00118 } 00119 } 00120 int ret; 00121 while ((ret = gps.getMessage(msg, sizeof(msg))) > 0) 00122 { 00123 int len = LENGTH(ret); 00124 if (PROTOCOL(ret) == NMEA && !strncmp("$GPGLL", msg, 6)) 00125 { 00126 double la = 0, lo = 0; 00127 char cLa = 0, cLo = 0, ch = 0; 00128 TFT.fillrect(220,175,320,210,White); 00129 TFT.locate(220,175); 00130 TFT.printf(" GPS"); 00131 if (gps.getNmeaItem(1,msg,len,la) && gps.getNmeaItem(2,msg,len,cLa) && 00132 gps.getNmeaItem(3,msg,len,lo) && gps.getNmeaItem(4,msg,len,cLo) && 00133 gps.getNmeaItem(6,msg,len,ch) && ch == 'A') 00134 { 00135 la *= 0.01; 00136 lo *= 0.01; 00137 int iLa = (int)la; 00138 int iLo = (int)lo; 00139 la = (la - iLa) / 0.6 + iLa; 00140 lo = (lo - iLo) / 0.6 + iLo; 00141 if (cLa == 'S') la = -la; 00142 if (cLo == 'N') lo = -lo; 00143 00144 TFT.locate(220,187); 00145 TFT.printf("%11.6f ", la); 00146 TFT.locate(220,199); 00147 TFT.printf("%11.6f ", lo); 00148 sprintf(link, "https://maps.google.com/?q=%.5f,%.5f", la, lo); 00149 } 00150 } 00151 } 00152 } 00153 }
Generated on Wed Jul 13 2022 02:43:48 by 1.7.2