Add define to use Software Serial

Added a #define to enable software serial.  Comment it out to not
include software serial.  Forum user request for ability to eliminate
software serial.
https://forums.adafruit.com/viewtopic.php?f=51&t=103611#p519211
This commit is contained in:
driverblock 2016-09-25 10:26:05 -04:00
parent 0ffa9bce67
commit c12e424439
3 changed files with 13 additions and 10 deletions

View File

@ -9,7 +9,7 @@ Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, check license.txt for more information
All text above must be included in any redistribution
****************************************/
#ifdef __AVR__
#if defined(__AVR__) && defined(USE_SW_SERIAL)
// Only include software serial on AVR platforms (i.e. not on Due).
#include <SoftwareSerial.h>
#endif
@ -268,7 +268,7 @@ char Adafruit_GPS::read(void) {
if (paused) return c;
#ifdef __AVR__
#if defined(__AVR__) && defined(USE_SW_SERIAL)
if(gpsSwSerial) {
if(!gpsSwSerial->available()) return c;
c = gpsSwSerial->read();
@ -310,7 +310,7 @@ char Adafruit_GPS::read(void) {
return c;
}
#ifdef __AVR__
#if defined(__AVR__) && defined(USE_SW_SERIAL)
// Constructor when using SoftwareSerial or NewSoftSerial
#if ARDUINO >= 100
Adafruit_GPS::Adafruit_GPS(SoftwareSerial *ser)
@ -331,7 +331,7 @@ Adafruit_GPS::Adafruit_GPS(HardwareSerial *ser) {
// Initialization code used by all constructor types
void Adafruit_GPS::common_init(void) {
#ifdef __AVR__
#if defined(__AVR__) && defined(USE_SW_SERIAL)
gpsSwSerial = NULL; // Set both to NULL, then override correct
#endif
gpsHwSerial = NULL; // port pointer in corresponding constructor
@ -352,7 +352,7 @@ void Adafruit_GPS::common_init(void) {
void Adafruit_GPS::begin(uint32_t baud)
{
#ifdef __AVR__
#if defined(__AVR__) && defined(USE_SW_SERIAL)
if(gpsSwSerial)
gpsSwSerial->begin(baud);
else
@ -363,7 +363,7 @@ void Adafruit_GPS::begin(uint32_t baud)
}
void Adafruit_GPS::sendCommand(const char *str) {
#ifdef __AVR__
#if defined(__AVR__) && defined(USE_SW_SERIAL)
if(gpsSwSerial)
gpsSwSerial->println(str);
else

View File

@ -21,7 +21,10 @@ All text above must be included in any redistribution
#ifndef _ADAFRUIT_GPS_H
#define _ADAFRUIT_GPS_H
#ifdef __AVR__
//comment this out if you don't want to include software serial in the library
#define USE_SW_SERIAL
#if defined(__AVR__) && defined(USE_SW_SERIAL)
#if ARDUINO >= 100
#include <SoftwareSerial.h>
#else
@ -101,7 +104,7 @@ class Adafruit_GPS {
public:
void begin(uint32_t baud);
#ifdef __AVR__
#if defined(__AVR__) && defined(USE_SW_SERIAL)
#if ARDUINO >= 100
Adafruit_GPS(SoftwareSerial *ser); // Constructor when using SoftwareSerial
#else
@ -154,7 +157,7 @@ class Adafruit_GPS {
boolean paused;
uint8_t parseResponse(char *response);
#ifdef __AVR__
#if defined(__AVR__) && defined(USE_SW_SERIAL)
#if ARDUINO >= 100
SoftwareSerial *gpsSwSerial;
#else

View File

@ -1,5 +1,5 @@
name=Adafruit GPS Library
version=1.0.1
version=1.0.2
author=Adafruit
maintainer=Adafruit <info@adafruit.com>
sentence=An interrupt-based GPS library for no-parsing-required use