Improved, thread compatible. Adds new features

Dependents:   GroveGPS-Example

Fork of GroveGPS by Michael Ray

Revision:
4:4615d6e99bb4
Parent:
3:cc5c9faa1cc6
--- a/GroveGPS.h	Sun Apr 22 00:06:53 2018 +0000
+++ b/GroveGPS.h	Thu May 31 17:21:40 2018 +0000
@@ -5,21 +5,17 @@
 #include <stdlib.h>
 #include <string>
 
+
 class GroveGPS {
 
 public:
 
-	GroveGPS() : _last_line("") {}
+	GroveGPS() : _last_line("") {
 
-	void readCharacter(char newCharacter) {
-		if (newCharacter == '\n') {
-			parseLine();
-			_last_line = "";
-		} else {
-			_last_line += newCharacter;
-		}
 	}
 
+	std::string _last_line;
+	
 	struct GGA {
 		double  utc_time; 		// Format: hhmmss.sss
 		double  latitude; 		// Format: ddmm.mmmm
@@ -102,7 +98,8 @@
 		if (gps_gga.position_fix==0) {
 			sprintf(buffer, "N/A");
 		} else {	
-		sprintf(buffer, "%c%f", (gps_gga.ns_indicator == 'N') ? '0' : '-', coordinate);
+		if(gps_gga.ns_indicator == 'S') coordinate *= -1.000;
+		sprintf(buffer, "%f", coordinate);
 		}
 	}
 
@@ -110,13 +107,12 @@
 		double coordinate = convertGPSToDecimal(gps_gga.longitude);
 		if (gps_gga.position_fix==0)
 			sprintf(buffer, "N/A");
-		else
-		sprintf(buffer, "%c%f", (gps_gga.ew_indicator == 'E') ? '0' : '-', coordinate);
+		else {
+		if(gps_gga.ew_indicator == 'W') coordinate *= -1.0000;
+		sprintf(buffer, "%f", coordinate);
+		}
 	}
 
-private:
-	std::string _last_line;
-
 
 	double convertGPSToDecimal(double coordinate) {
 		int degrees = coordinate/100.0;
@@ -126,18 +122,6 @@
 
 	}
 
-	void parseLine() {
-		if (_last_line.find("GPGGA") != std::string::npos) {
-			parseGGA();
-		}
-		if (_last_line.find("GPZDA") != std::string::npos) {
-			parseZDA();
-		}
-		if (_last_line.find("GPVTG") != std::string::npos) {
-			parseVTG();
-		}
-	}
-	
 void parseVTG() {
   		char* pEnd;
 		for (int i=0; i<5; i++) {