Example application that utilizes the GroveGPS library

Committer:
Michael Ray
Date:
Tue Jan 30 13:47:17 2018 -0600
Revision:
0:39b09b3d8731
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Michael Ray 0:39b09b3d8731 1 // ----------------------------------------------------------------------------
Michael Ray 0:39b09b3d8731 2 // Copyright 2016-2017 ARM Ltd.
Michael Ray 0:39b09b3d8731 3 //
Michael Ray 0:39b09b3d8731 4 // SPDX-License-Identifier: Apache-2.0
Michael Ray 0:39b09b3d8731 5 //
Michael Ray 0:39b09b3d8731 6 // Licensed under the Apache License, Version 2.0 (the "License");
Michael Ray 0:39b09b3d8731 7 // you may not use this file except in compliance with the License.
Michael Ray 0:39b09b3d8731 8 // You may obtain a copy of the License at
Michael Ray 0:39b09b3d8731 9 //
Michael Ray 0:39b09b3d8731 10 // http://www.apache.org/licenses/LICENSE-2.0
Michael Ray 0:39b09b3d8731 11 //
Michael Ray 0:39b09b3d8731 12 // Unless required by applicable law or agreed to in writing, software
Michael Ray 0:39b09b3d8731 13 // distributed under the License is distributed on an "AS IS" BASIS,
Michael Ray 0:39b09b3d8731 14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Michael Ray 0:39b09b3d8731 15 // See the License for the specific language governing permissions and
Michael Ray 0:39b09b3d8731 16 // limitations under the License.
Michael Ray 0:39b09b3d8731 17 // ----------------------------------------------------------------------------
Michael Ray 0:39b09b3d8731 18
Michael Ray 0:39b09b3d8731 19 #include "mbed.h"
Michael Ray 0:39b09b3d8731 20
Michael Ray 0:39b09b3d8731 21 #include "GroveGPS.h"
Michael Ray 0:39b09b3d8731 22
Michael Ray 0:39b09b3d8731 23 Serial gps_serial(D1, D0, 9600);
Michael Ray 0:39b09b3d8731 24
Michael Ray 0:39b09b3d8731 25 Thread gpsThread;
Michael Ray 0:39b09b3d8731 26 GroveGPS gps;
Michael Ray 0:39b09b3d8731 27
Michael Ray 0:39b09b3d8731 28 // Runs at 1Hz and updates the GPS location every second
Michael Ray 0:39b09b3d8731 29 void gps_updater_thread() {
Michael Ray 0:39b09b3d8731 30 while(true) {
Michael Ray 0:39b09b3d8731 31 char latBuffer[16], lonBuffer[16];
Michael Ray 0:39b09b3d8731 32 gps.getLatitude(latBuffer);
Michael Ray 0:39b09b3d8731 33 gps.getLongitude(lonBuffer);
Michael Ray 0:39b09b3d8731 34
Michael Ray 0:39b09b3d8731 35 // Utilize latitude and longitude values here
Michael Ray 0:39b09b3d8731 36 printf("Latitude: %f\n, Longitude: %f\n", latBuffer, lonBuffer);
Michael Ray 0:39b09b3d8731 37 wait(1);
Michael Ray 0:39b09b3d8731 38 }
Michael Ray 0:39b09b3d8731 39 }
Michael Ray 0:39b09b3d8731 40
Michael Ray 0:39b09b3d8731 41 int main() {
Michael Ray 0:39b09b3d8731 42
Michael Ray 0:39b09b3d8731 43 // Start a thread to get updated GPS values
Michael Ray 0:39b09b3d8731 44 gpsThread.start(gps_updater_thread);
Michael Ray 0:39b09b3d8731 45
Michael Ray 0:39b09b3d8731 46 // Read the serial bus to get NMEA GPS details
Michael Ray 0:39b09b3d8731 47 while (true) {
Michael Ray 0:39b09b3d8731 48 if (gps_serial.readable()) {
Michael Ray 0:39b09b3d8731 49 gps.readCharacter(gps_serial.getc());
Michael Ray 0:39b09b3d8731 50 }
Michael Ray 0:39b09b3d8731 51 }
Michael Ray 0:39b09b3d8731 52
Michael Ray 0:39b09b3d8731 53 return 0;
Michael Ray 0:39b09b3d8731 54 }