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.
|
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
|
@brief Constructor when using I2C
|
||||||
|
|
@ -246,6 +257,7 @@ void Adafruit_GPS::common_init(void) {
|
||||||
gpsSwSerial = NULL; // Set both to NULL, then override correct
|
gpsSwSerial = NULL; // Set both to NULL, then override correct
|
||||||
#endif
|
#endif
|
||||||
gpsHwSerial = NULL; // port pointer in corresponding constructor
|
gpsHwSerial = NULL; // port pointer in corresponding constructor
|
||||||
|
gpsStream = NULL; // port pointer in corresponding constructor
|
||||||
gpsI2C = NULL;
|
gpsI2C = NULL;
|
||||||
gpsSPI = NULL;
|
gpsSPI = NULL;
|
||||||
recvdflag = false;
|
recvdflag = false;
|
||||||
|
|
@ -298,6 +310,9 @@ size_t Adafruit_GPS::available(void) {
|
||||||
if (gpsHwSerial) {
|
if (gpsHwSerial) {
|
||||||
return gpsHwSerial->available();
|
return gpsHwSerial->available();
|
||||||
}
|
}
|
||||||
|
if (gpsStream) {
|
||||||
|
return gpsStream->available();
|
||||||
|
}
|
||||||
if (gpsI2C || gpsSPI) {
|
if (gpsI2C || gpsSPI) {
|
||||||
return 1; // I2C/SPI doesnt have 'availability' so always has a byte at
|
return 1; // I2C/SPI doesnt have 'availability' so always has a byte at
|
||||||
// least to read!
|
// least to read!
|
||||||
|
|
@ -322,6 +337,9 @@ size_t Adafruit_GPS::write(uint8_t c) {
|
||||||
if (gpsHwSerial) {
|
if (gpsHwSerial) {
|
||||||
return gpsHwSerial->write(c);
|
return gpsHwSerial->write(c);
|
||||||
}
|
}
|
||||||
|
if (gpsStream) {
|
||||||
|
return gpsStream->write(c);
|
||||||
|
}
|
||||||
if (gpsI2C) {
|
if (gpsI2C) {
|
||||||
gpsI2C->beginTransmission(_i2caddr);
|
gpsI2C->beginTransmission(_i2caddr);
|
||||||
if (gpsI2C->write(c) != 1) {
|
if (gpsI2C->write(c) != 1) {
|
||||||
|
|
@ -379,6 +397,11 @@ char Adafruit_GPS::read(void) {
|
||||||
return c;
|
return c;
|
||||||
c = gpsHwSerial->read();
|
c = gpsHwSerial->read();
|
||||||
}
|
}
|
||||||
|
if (gpsStream) {
|
||||||
|
if (!gpsStream->available())
|
||||||
|
return c;
|
||||||
|
c = gpsStream->read();
|
||||||
|
}
|
||||||
if (gpsI2C) {
|
if (gpsI2C) {
|
||||||
if (_buff_idx <= _buff_max) {
|
if (_buff_idx <= _buff_max) {
|
||||||
c = _i2cbuffer[_buff_idx];
|
c = _i2cbuffer[_buff_idx];
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,7 @@ public:
|
||||||
Adafruit_GPS(SoftwareSerial *ser); // Constructor when using SoftwareSerial
|
Adafruit_GPS(SoftwareSerial *ser); // Constructor when using SoftwareSerial
|
||||||
#endif
|
#endif
|
||||||
Adafruit_GPS(HardwareSerial *ser); // Constructor when using HardwareSerial
|
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(TwoWire *theWire); // Constructor when using I2C
|
||||||
Adafruit_GPS(SPIClass *theSPI, int8_t cspin); // Constructor when using SPI
|
Adafruit_GPS(SPIClass *theSPI, int8_t cspin); // Constructor when using SPI
|
||||||
Adafruit_GPS(); // Constructor for no communications, just data storage
|
Adafruit_GPS(); // Constructor for no communications, just data storage
|
||||||
|
|
@ -288,6 +289,7 @@ private:
|
||||||
#endif
|
#endif
|
||||||
bool noComms = false;
|
bool noComms = false;
|
||||||
HardwareSerial *gpsHwSerial;
|
HardwareSerial *gpsHwSerial;
|
||||||
|
Stream *gpsStream;
|
||||||
TwoWire *gpsI2C;
|
TwoWire *gpsI2C;
|
||||||
SPIClass *gpsSPI;
|
SPIClass *gpsSPI;
|
||||||
int8_t gpsSPI_cs = -1;
|
int8_t gpsSPI_cs = -1;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue