From 27d5ac00d3572b8c0a5547c37995578b3f4c1240 Mon Sep 17 00:00:00 2001 From: Vido Date: Fri, 20 Nov 2015 18:58:56 -0200 Subject: [PATCH] AltSoftSerial support --- ESP8266.cpp | 7 +++++++ ESP8266.h | 18 ++++++++++++++++++ README.md | 14 ++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/ESP8266.cpp b/ESP8266.cpp index 47bcc7c..0fe3b99 100644 --- a/ESP8266.cpp +++ b/ESP8266.cpp @@ -47,6 +47,13 @@ ESP8266::ESP8266(SoftwareSerial &uart, uint32_t baud): m_puart(&uart) m_puart->begin(baud); rx_empty(); } +#elif defined(ESP8266_USE_ALTSOFT_SERIAL) +ESP8266::ESP8266(AltSoftSerial &uart, uint32_t baud): m_puart(&uart) +{ + m_puart->begin(baud); + rx_empty(); +} + #else ESP8266::ESP8266(HardwareSerial &uart, uint32_t baud): m_puart(&uart) { diff --git a/ESP8266.h b/ESP8266.h index bf82755..d07755e 100644 --- a/ESP8266.h +++ b/ESP8266.h @@ -25,12 +25,16 @@ //#define ESP8266_USE_SOFTWARE_SERIAL +//#define ESP8266_USE_ALTSOFT_SERIAL #ifdef ESP8266_USE_SOFTWARE_SERIAL #include "SoftwareSerial.h" #endif +#ifdef ESP8266_USE_ALTSOFT_SERIAL +#include "AltSoftSerial.h" +#endif /** * Provide an easy-to-use way to manipulate ESP8266. @@ -48,6 +52,18 @@ class ESP8266 { * @warning parameter baud depends on the AT firmware. 9600 is an common value. */ ESP8266(SoftwareSerial &uart, uint32_t baud = 9600); + +#elif defined(ESP8266_USE_ALTSOFT_SERIAL) + /* + * Constuctor. + * + * @param uart - an reference of AltSoftSerial object. + * @param baud - the buad rate to communicate with ESP8266(default:9600). + * + * @warning parameter baud depends on the AT firmware. 9600 is an common value. + */ + ESP8266(AltSoftSerial &uart, uint32_t baud = 9600); + #else /* HardwareSerial */ /* * Constuctor. @@ -459,6 +475,8 @@ class ESP8266 { #ifdef ESP8266_USE_SOFTWARE_SERIAL SoftwareSerial *m_puart; /* The UART to communicate with ESP8266 */ +#elif defined(ESP8266_USE_ALTSOFT_SERIAL) + AltSoftSerial *m_puart; /* The UART to communicate with ESP8266 */ #else HardwareSerial *m_puart; /* The UART to communicate with ESP8266 */ #endif diff --git a/README.md b/README.md index 3ae5326..93a2802 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,20 @@ After modification, it should be: #define ESP8266_USE_SOFTWARE_SERIAL +# Using AltSoftSerial + +There is a alternative to SoftwareSerial (a.k.a NewSoftSerial). +AltSoftSerial is particularly useful when simultaneous data flows are needed. +https://www.pjrc.com/teensy/td_libs_AltSoftSerial.html + +If you want to use AltSoftSerial to communicate with ESP8266, you need to modify +the line in file `ESP8266.h`: + + //#define ESP8266_USE_ALTSOFT_SERIAL + +After modification, it should be: + + #define ESP8266_USE_ALTSOFT_SERIAL # Hardware Connection