Thread based example

Dependencies:   GroveGPS

Fork of GroveGPS-Example by Michael Ray

Files at this revision

API Documentation at this revision

Comitter:
JimCarver
Date:
Thu May 31 17:22:09 2018 +0000
Parent:
0:39b09b3d8731
Commit message:
Thread based example

Changed in this revision

GroveGPS.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 39b09b3d8731 -r b64f47a659a1 GroveGPS.lib
--- a/GroveGPS.lib	Tue Jan 30 13:47:17 2018 -0600
+++ b/GroveGPS.lib	Thu May 31 17:22:09 2018 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/michaelray/code/GroveGPS/#56d6407653a7
+https://os.mbed.com/users/JimCarver/code/GroveGPS/#4615d6e99bb4
diff -r 39b09b3d8731 -r b64f47a659a1 main.cpp
--- a/main.cpp	Tue Jan 30 13:47:17 2018 -0600
+++ b/main.cpp	Thu May 31 17:22:09 2018 +0000
@@ -20,34 +20,35 @@
 
 #include "GroveGPS.h"
 
-Serial gps_serial(D1, D0, 9600);
+extern int GPS_init();
+extern GroveGPS gps;
+Thread gpsThread(osPriorityNormal);
 
-Thread gpsThread;
-GroveGPS gps;
 
 // Runs at 1Hz and updates the GPS location every second
 void gps_updater_thread() {
+    printf("Thread Initialized\r\n");
     while(true) {
         char latBuffer[16], lonBuffer[16];
         gps.getLatitude(latBuffer);
         gps.getLongitude(lonBuffer);
 
         // Utilize latitude and longitude values here
-        printf("Latitude: %f\n, Longitude: %f\n", latBuffer, lonBuffer);
+        printf("\r\nLa=%s Lo=%s\r\n", latBuffer, lonBuffer);
         wait(1);
     }
 }
 
 int main() {
-
+    GPS_init();
+    printf("GPS Initialized\r\n");
     // Start a thread to get updated GPS values
-    gpsThread.start(gps_updater_thread);
+    gpsThread.start(callback(gps_updater_thread));
 
-    // Read the serial bus to get NMEA GPS details
+    // do nothing while the library does all the work
     while (true) {
-        if (gps_serial.readable()) {
-            gps.readCharacter(gps_serial.getc());
-        }
+        // Include a long wait to unblock the threads
+        wait(100000);
     }
 
     return 0;