Update to work with latest mBed
Fork of FONA_CellPhone by
Diff: main.cpp
- Revision:
- 18:d52017f1d087
- Parent:
- 17:b01377595122
diff -r b01377595122 -r d52017f1d087 main.cpp --- a/main.cpp Wed Mar 30 16:19:51 2016 +0000 +++ b/main.cpp Wed Jan 25 12:56:31 2017 +0000 @@ -1,53 +1,27 @@ -/*************************************************** - This is an example for our Adafruit FONA Cellular Module - - Designed specifically to work with the Adafruit FONA - ----> http://www.adafruit.com/products/1946 - ----> http://www.adafruit.com/products/1963 - ----> http://www.adafruit.com/products/2468 - ----> http://www.adafruit.com/products/2542 - - These cellular modules use TTL Serial to communicate, 2 pins are - required to interface - Adafruit invests time and resources providing this open source code, - please support Adafruit and open-source hardware by purchasing - products from Adafruit! +#include "mbed.h" +#include <ctype.h> +#include "Adafruit_FONA.h" - Written by Limor Fried/Ladyada for Adafruit Industries. - BSD license, all text above must be included in any redistribution - ****************************************************/ - - /* - * Modified by Jesse Baker & George Tzintzarov 03/30/2016 for use in mbed LPC1768 - */ +#define BAUD_RATE 115200 +#define FONA_RST D4 +#define FONA_TX PC_10 +#define FONA_RX PC_11 +#define FONA_RI D6 -/* -THIS CODE IS STILL IN PROGRESS! - -Open up the serial console on the Arduino at 4800 baud to interact with FONA - -Note that if you need to set a GPRS APN, username, and password scroll down to -the commented section below just before the main "while (true)" loop. -*/ +#define APN "epc.tmobile.com" +#define USERNAME "" +#define PASSWORD "" -#include <ctype.h> -//#include "SoftSerial.h" I dont think we need this -#include "Adafruit_FONA.h" - -#define FONA_RST p12 -#define FONA_TX p13 -#define FONA_RX p14 -#define FONA_RI p11 - + // this is a large buffer for replies char replybuffer[255]; - - + + Serial pcSerial(USBTX, USBRX); Adafruit_FONA fona(FONA_TX, FONA_RX, FONA_RST, FONA_RI); //uLCD_4DGL uLCD(p28,p27,p30); - + // Turn on a LED when somebody call the FONA DigitalOut led1(LED1); class FonaEventListener : public Adafruit_FONA::EventListener { @@ -60,7 +34,7 @@ } }; FonaEventListener fonaEventListener; - + // Functions defined after main() uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0); void printMenu(void); @@ -68,9 +42,9 @@ char readBlocking(); uint16_t readnumber(); long map(long x, long in_min, long in_max, long out_min, long out_max); - + int main() { - pcSerial.baud(9600); + pcSerial.baud(BAUD_RATE); wait(1); pcSerial.printf("\r\n"); @@ -78,7 +52,7 @@ pcSerial.printf("Initializing....(May take 3 seconds)\r\n"); // See if the FONA is responding - if (! fona.begin(9600)) { + if (! fona.begin(BAUD_RATE)) { pcSerial.printf("Couldn't find FONA\r\n"); while (1); } @@ -91,7 +65,7 @@ if (imeiLen > 0) { pcSerial.printf("SIM card IMEI: %s\r\n", imei); } - + fona.setGPRSNetworkSettings(APN, USERNAME, PASSWORD); // Optionally configure a GPRS APN, username, and password. // You might need to do this to access your network's GPRS/data // network. Contact your provider for the exact APN, username, @@ -104,7 +78,7 @@ // Default is not to follow SSL redirects, however if you uncomment // the following line then redirects over SSL will be followed. //fona.setHTTPSRedirect(true); - + printMenu(); while (true) { @@ -653,13 +627,13 @@ case 'S': { pcSerial.printf("Creating SERIAL TUBE\r\n"); while (1) { - while (pcSerial.readable()) { - wait_ms(1); - fona.putc(pcSerial.getc()); - } - if (fona.readable()) { - pcSerial.putc(fona.getc()); - } + while(pcSerial.readable() ){ + fona._putc(pcSerial.getc() ); + } + while(fona.readable() ){ + pcSerial.putc(fona._getc() ); + } + } } @@ -676,7 +650,7 @@ } } } - + void printMenu(void) { pcSerial.printf("-------------------------------------\r\n"); pcSerial.printf("[?] Print this menu\r\n"); @@ -735,17 +709,17 @@ pcSerial.printf("-------------------------------------\r\n"); pcSerial.printf("\r\n"); } - + void flushSerial() { while (pcSerial.readable()) pcSerial.getc(); } - + char readBlocking() { while (!pcSerial.readable()); return pcSerial.getc(); } - + uint16_t readnumber() { uint16_t x = 0; char c; @@ -800,8 +774,11 @@ buff[buffidx] = 0; // null term return buffidx; } - + long map(long x, long in_min, long in_max, long out_min, long out_max) { return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; } + + +