Demo for the Adafruit_FONA_Library. This is a port of the FONAtest available here: https://github.com/adafruit/Adafruit_FONA_Library/tree/master/examples/FONAtest .
Dependencies: Adafruit_FONA_Library BLE_API SoftSerial mbed nRF51822
Demo for the Adafruit_FONA_Library. This is a port of the FONAtest available here: https://github.com/adafruit/Adafruit_FONA_Library/tree/master/examples/FONAtest .
Diff: main.cpp
- Revision:
- 2:6cdaadf03837
- Parent:
- 0:8230b1071cc9
diff -r 4bbc4e224d8d -r 6cdaadf03837 main.cpp --- a/main.cpp Sat Jun 27 09:31:47 2015 +0000 +++ b/main.cpp Sat Jun 27 15:04:49 2015 +0000 @@ -42,9 +42,22 @@ // this is a large buffer for replies char replybuffer[255]; -Serial fonaSerial(FONA_TX, FONA_RX); +// Note: there is only one hardware serial on the "nRF51 DK" board, so the SoftSerial is used instead. However it doesn't 100% work. SoftSerial pcSerial(USBTX, USBRX); -Adafruit_FONA fona(FONA_RST, FONA_RI); +Adafruit_FONA fona(FONA_TX, FONA_RX, FONA_RST, FONA_RI); + +// Turn on a LED when somebody call the FONA +DigitalOut led1(LED1, 1); // 1 = LED OFF on the "nRF51 DK" board +class FonaEventListener : public Adafruit_FONA::EventListener { + virtual void onRing() { + led1 = 0; // 0 = LED ON on the "nRF51 DK" board + } + + virtual void onNoCarrier() { + led1 = 1; // 1 = LED OFF on the "nRF51 DK" board + } +}; +FonaEventListener fonaEventListener; // Functions defined after main() uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0); @@ -62,14 +75,12 @@ pcSerial.printf("FONA basic test\r\n"); pcSerial.printf("Initializing....(May take 3 seconds)\r\n"); - // make it slow so its easy to read! - fonaSerial.baud(9600); - // See if the FONA is responding - if (! fona.begin(fonaSerial)) { + if (! fona.begin(9600)) { pcSerial.printf("Couldn't find FONA\r\n"); while (1); } + fona.setEventListener(&fonaEventListener); pcSerial.printf("FONA is OK\r\n"); // Print SIM card IMEI number. @@ -97,8 +108,8 @@ while (true) { pcSerial.printf("FONA> "); while (! pcSerial.readable() ) { - if (fonaSerial.readable()) { - pcSerial.putc(fonaSerial.getc()); + if (fona.readable()) { + pcSerial.putc(fona.getc()); } } @@ -113,7 +124,7 @@ } case 'a': { - // read the ADC + // read the ADC uint16_t adc; if (! fona.getADCVoltage(&adc)) { pcSerial.printf("Failed to read ADC\r\n"); @@ -588,8 +599,8 @@ break; } while (length > 0) { - while (fonaSerial.readable()) { - char c = fonaSerial.getc(); + while (fona.readable()) { + char c = fona.getc(); pcSerial.putc(c); length--; if (! length) break; @@ -622,8 +633,8 @@ break; } while (length > 0) { - while (fonaSerial.readable()) { - char c = fonaSerial.getc(); + while (fona.readable()) { + char c = fona.getc(); pcSerial.putc(c); length--; if (! length) break; @@ -640,10 +651,10 @@ while (1) { while (pcSerial.readable()) { wait_ms(1); - fonaSerial.putc(pcSerial.getc()); + fona.putc(pcSerial.getc()); } - if (fonaSerial.readable()) { - pcSerial.putc(fonaSerial.getc()); + if (fona.readable()) { + pcSerial.putc(fona.getc()); } } } @@ -656,8 +667,8 @@ } // flush input flushSerial(); - while (fonaSerial.readable()) { - pcSerial.putc(fonaSerial.getc()); + while (fona.readable()) { + pcSerial.putc(fona.getc()); } } }