Jim Carver
/
GroveGPS-Example
Thread based example
Fork of GroveGPS-Example by
Diff: main.cpp
- Revision:
- 1:b64f47a659a1
- Parent:
- 0:39b09b3d8731
--- 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;