Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Adafruit_FONA_Library by
Diff: Adafruit_FONA.h
- Revision:
- 1:89299f09929c
- Parent:
- 0:d567815b7a5f
- Child:
- 2:a47b72e3654e
--- a/Adafruit_FONA.h Sat Jun 27 09:25:38 2015 +0000 +++ b/Adafruit_FONA.h Sat Jun 27 15:03:10 2015 +0000 @@ -49,13 +49,39 @@ #define FONA_HTTP_POST 1 #define FONA_HTTP_HEAD 2 -class Adafruit_FONA { +#define RX_BUFFER_SIZE 255 + +class Adafruit_FONA : public Stream { public: - Adafruit_FONA(PinName rst, PinName ringIndicator) : + /** + * Listener for FONA events. + */ + class EventListener { + public: + /** + * Method called when somebody call the FONA. + */ + virtual void onRing() = 0; + + /** + * Method called when the calling person stop his call. + */ + virtual void onNoCarrier() = 0; + }; + + public: + Adafruit_FONA(PinName tx, PinName rx, PinName rst, PinName ringIndicator) : _rstpin(rst, false), _ringIndicatorInterruptIn(ringIndicator), apn("FONAnet"), apnusername(NULL), apnpassword(NULL), httpsredirect(false), useragent("FONA"), - _incomingCall(false), mySerial(NULL) {} - bool begin(Serial &port); + _incomingCall(false), eventListener(NULL), mySerial(tx, rx), rxBufferInIndex(0), rxBufferOutIndex(0), + currentReceivedLineSize(0) {} + bool begin(int baudrate); + void setEventListener(EventListener *eventListener); + + // Stream + virtual int _putc(int value); + virtual int _getc(); + int readable(); // RTC bool enableRTC(uint8_t i); // i = 0 <=> disable, i = 1 <=> enable @@ -171,6 +197,38 @@ bool httpsredirect; char* useragent; + volatile bool _incomingCall; + EventListener *eventListener; + Serial mySerial; + + // Circular buffer used to receive serial data from an interruption + int rxBuffer[RX_BUFFER_SIZE + 1]; + volatile int rxBufferInIndex; // Index where new data is added to the buffer + volatile int rxBufferOutIndex; // Index where data is removed from the buffer + char currentReceivedLine[RX_BUFFER_SIZE]; // Array containing the current received line + int currentReceivedLineSize; + + inline bool isRxBufferFull() { + return ((rxBufferInIndex + 1) % RX_BUFFER_SIZE) == rxBufferOutIndex; + } + + inline bool isRxBufferEmpty() { + return rxBufferInIndex == rxBufferOutIndex; + } + + inline void incrementRxBufferInIndex() { + rxBufferInIndex = (rxBufferInIndex + 1) % RX_BUFFER_SIZE; + } + + inline void incrementRxBufferOutIndex() { + rxBufferOutIndex = (rxBufferOutIndex + 1) % RX_BUFFER_SIZE; + } + + /** + * Method called when Serial data is received (interrupt routine). + */ + void onSerialDataReceived(); + // HTTP helpers bool HTTP_setup(char *url); @@ -195,10 +253,7 @@ bool sendParseReply(const char* tosend, const char* toreply, uint16_t *v, char divider = ',', uint8_t index = 0); - volatile bool _incomingCall; void onIncomingCall(); - - Serial *mySerial; }; #endif \ No newline at end of file