Library for the Adafruit FONA. This is a port of the original Arduino library available at: https://github.com/adafruit/Adafruit_FONA_Library . - Modified by Marc PLOUHINEC 27/06/2015 for use in mbed - Modified by lionel VOIRIN 05/08/2018 for use Adafruit FONA 3

Dependents:   Adafruit_FONA_3G_Library_Test

Revision:
5:79e4c91f2b73
Parent:
4:05c32425d2da
Child:
6:8fdb30dc3108
--- a/Adafruit_FONA.cpp	Sat Aug 11 09:44:50 2018 +0000
+++ b/Adafruit_FONA.cpp	Wed Sep 05 20:26:07 2018 +0000
@@ -25,8 +25,8 @@
 #define HIGH 1
 #define LOW 0
 
-Adafruit_FONA::Adafruit_FONA(PinName tx, PinName rx, PinName rst) :
-    _rstpin(rst, false), mySerial(tx, rx)
+Adafruit_FONA::Adafruit_FONA(PinName tx, PinName rx, PinName rst, PinName key) :
+    _keypin(key, false), _rstpin(rst, false), mySerial(tx, rx)
 {
     apn = "FONAnet";
     apnusername = 0;
@@ -51,42 +51,7 @@
     mySerial.baud(baudrate);
     mySerial.attach(this, &Adafruit_FONA::onSerialDataReceived, Serial::RxIrq);
 
-    _rstpin = HIGH;
-    wait_ms(10);
-    _rstpin = LOW;
-    wait_ms(100);
-    _rstpin = HIGH;
-
-#ifdef ADAFRUIT_FONA_DEBUG
-    printf("Attempting to open comm with ATs\r\n");
-#endif
-
-    // give 3 seconds to reboot
-    int16_t timeout = 7000;
-
-    while (timeout > 0) {
-        while (readable()) getc();
-        if (sendCheckReply("AT", ok_reply))
-            break;
-        while (readable()) getc();
-        if (sendCheckReply("AT", "AT"))
-            break;
-        wait_ms(500);
-        timeout -= 500;
-    }
-
-    if (timeout <= 0) {
-#ifdef ADAFRUIT_FONA_DEBUG
-        printf("Timeout: No response to AT... last ditch attempt.\r\n");
-#endif
-
-        sendCheckReply("AT", ok_reply);
-        wait_ms(100);
-        sendCheckReply("AT", ok_reply);
-        wait_ms(100);
-        sendCheckReply("AT", ok_reply);
-        wait_ms(100);
-    }
+    powerOn();
 
     // turn off Echo!
     sendCheckReply("ATE0", ok_reply);
@@ -146,6 +111,55 @@
     return true;
 }
 
+void Adafruit_FONA::powerOn()
+{
+    _keypin = LOW;
+    _rstpin = HIGH;
+    wait_ms(10);
+    _rstpin = LOW;
+    wait_ms(100);
+    _rstpin = HIGH;
+
+#ifdef ADAFRUIT_FONA_DEBUG
+    printf("Attempting to open comm with ATs\r\n");
+#endif
+
+    // give 3 seconds to reboot
+    int16_t timeout = 7000;
+
+    while (timeout > 0) {
+        while (readable()) getc();
+        if (sendCheckReply("AT", ok_reply))
+            break;
+        while (readable()) getc();
+        if (sendCheckReply("AT", "AT"))
+            break;
+        wait_ms(500);
+        timeout -= 500;
+    }
+
+    if (timeout <= 0) {
+#ifdef ADAFRUIT_FONA_DEBUG
+        printf("Timeout: No response to AT... last ditch attempt.\r\n");
+#endif
+
+        sendCheckReply("AT", ok_reply);
+        wait_ms(100);
+        sendCheckReply("AT", ok_reply);
+        wait_ms(100);
+        sendCheckReply("AT", ok_reply);
+        wait_ms(100);
+    }
+    _keypin = HIGH;
+}
+
+void Adafruit_FONA::powerOff()
+{
+    _keypin = LOW;
+    wait(5);
+    _keypin = HIGH;
+}
+
 void Adafruit_FONA::setEventListener(EventListener *eventListener)
 {
     this->eventListener = eventListener;