GPS driver

Dependents:   GroveGPS-Example ncu_project

Files at this revision

API Documentation at this revision

Comitter:
c1728p9
Date:
Tue Jun 18 12:14:13 2019 -0500
Parent:
4:0ee729b4a211
Commit message:
Add bool return values for GPS functions to indicate success

Changed in this revision

GroveGPS.h Show annotated file Show diff for this revision Revisions of this file
diff -r 0ee729b4a211 -r 8a5414710483 GroveGPS.h
--- a/GroveGPS.h	Thu Jun 06 21:26:39 2019 -0500
+++ b/GroveGPS.h	Tue Jun 18 12:14:13 2019 -0500
@@ -35,36 +35,49 @@
 		long    diff_ref_station_id;
 	} gps_gga;
 
-	void getTimestamp(char* buffer) {
+	bool getTimestamp(char* buffer) {
         m.lock();
         parseLine();
 
+        bool valid = gps_gga.position_fix != 0;
 		sprintf(buffer, "%f", gps_gga.utc_time);
         m.unlock();
+
+        return valid;
 	}
 
-	void getLatitude(char* buffer) {
+	bool getLatitude(char* buffer) {
         m.lock();
         parseLine();
 
+        bool valid = false;
 		double coordinate = convertGPSToDecimal(gps_gga.latitude);
-		if (gps_gga.position_fix==0)
+		if (gps_gga.position_fix==0) {
 			sprintf(buffer, "N/A");
-		else
+		} else {
 			sprintf(buffer, "%c%f", (gps_gga.ns_indicator == 'N') ? '0' : '-', coordinate);
+			valid = true;
+		}
         m.unlock();
+
+        return valid;
 	}
 
-	void getLongitude(char* buffer) {
+	bool getLongitude(char* buffer) {
         m.lock();
         parseLine();
 
+        bool valid = false;
 		double coordinate = convertGPSToDecimal(gps_gga.longitude);
-		if (gps_gga.position_fix==0)
+		if (gps_gga.position_fix==0) {
 			sprintf(buffer, "N/A");
-		else
-		sprintf(buffer, "%c%f", (gps_gga.ew_indicator == 'E') ? '0' : '-', coordinate);
+		} else {
+		    sprintf(buffer, "%c%f", (gps_gga.ew_indicator == 'E') ? '0' : '-', coordinate);
+		    valid = true;
+		}
         m.unlock();
+
+        return valid;
 	}
 
 private: