Merge pull request #125 from petrkr/pk/stream-support
Added support for generic Stream class
This commit is contained in:
commit
8e252802d7
|
|
@ -202,6 +202,17 @@ Adafruit_GPS::Adafruit_GPS(HardwareSerial *ser) {
|
|||
gpsHwSerial = ser; // ...override gpsHwSerial with value passed.
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Constructor when using Stream
|
||||
@param data Pointer to a Stream object
|
||||
*/
|
||||
/**************************************************************************/
|
||||
Adafruit_GPS::Adafruit_GPS(Stream *data) {
|
||||
common_init(); // Set everything to common state, then...
|
||||
gpsStream = data; // ...override gpsStream with value passed.
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Constructor when using I2C
|
||||
|
|
@ -246,6 +257,7 @@ void Adafruit_GPS::common_init(void) {
|
|||
gpsSwSerial = NULL; // Set both to NULL, then override correct
|
||||
#endif
|
||||
gpsHwSerial = NULL; // port pointer in corresponding constructor
|
||||
gpsStream = NULL; // port pointer in corresponding constructor
|
||||
gpsI2C = NULL;
|
||||
gpsSPI = NULL;
|
||||
recvdflag = false;
|
||||
|
|
@ -298,6 +310,9 @@ size_t Adafruit_GPS::available(void) {
|
|||
if (gpsHwSerial) {
|
||||
return gpsHwSerial->available();
|
||||
}
|
||||
if (gpsStream) {
|
||||
return gpsStream->available();
|
||||
}
|
||||
if (gpsI2C || gpsSPI) {
|
||||
return 1; // I2C/SPI doesnt have 'availability' so always has a byte at
|
||||
// least to read!
|
||||
|
|
@ -322,6 +337,9 @@ size_t Adafruit_GPS::write(uint8_t c) {
|
|||
if (gpsHwSerial) {
|
||||
return gpsHwSerial->write(c);
|
||||
}
|
||||
if (gpsStream) {
|
||||
return gpsStream->write(c);
|
||||
}
|
||||
if (gpsI2C) {
|
||||
gpsI2C->beginTransmission(_i2caddr);
|
||||
if (gpsI2C->write(c) != 1) {
|
||||
|
|
@ -379,6 +397,11 @@ char Adafruit_GPS::read(void) {
|
|||
return c;
|
||||
c = gpsHwSerial->read();
|
||||
}
|
||||
if (gpsStream) {
|
||||
if (!gpsStream->available())
|
||||
return c;
|
||||
c = gpsStream->read();
|
||||
}
|
||||
if (gpsI2C) {
|
||||
if (_buff_idx <= _buff_max) {
|
||||
c = _i2cbuffer[_buff_idx];
|
||||
|
|
|
|||
|
|
@ -89,6 +89,7 @@ public:
|
|||
Adafruit_GPS(SoftwareSerial *ser); // Constructor when using SoftwareSerial
|
||||
#endif
|
||||
Adafruit_GPS(HardwareSerial *ser); // Constructor when using HardwareSerial
|
||||
Adafruit_GPS(Stream *data); // Constructor when using Stream
|
||||
Adafruit_GPS(TwoWire *theWire); // Constructor when using I2C
|
||||
Adafruit_GPS(SPIClass *theSPI, int8_t cspin); // Constructor when using SPI
|
||||
Adafruit_GPS(); // Constructor for no communications, just data storage
|
||||
|
|
@ -288,6 +289,7 @@ private:
|
|||
#endif
|
||||
bool noComms = false;
|
||||
HardwareSerial *gpsHwSerial;
|
||||
Stream *gpsStream;
|
||||
TwoWire *gpsI2C;
|
||||
SPIClass *gpsSPI;
|
||||
int8_t gpsSPI_cs = -1;
|
||||
|
|
|
|||
Loading…
Reference in New Issue