Jim Carver
/
GroveGPS-Example
Thread based example
Fork of GroveGPS-Example by
main.cpp@1:b64f47a659a1, 2018-05-31 (annotated)
- Committer:
- JimCarver
- Date:
- Thu May 31 17:22:09 2018 +0000
- Revision:
- 1:b64f47a659a1
- Parent:
- 0:39b09b3d8731
Thread based example
Who changed what in which revision?
User | Revision | Line number | New 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 | |
JimCarver | 1:b64f47a659a1 | 23 | extern int GPS_init(); |
JimCarver | 1:b64f47a659a1 | 24 | extern GroveGPS gps; |
JimCarver | 1:b64f47a659a1 | 25 | Thread gpsThread(osPriorityNormal); |
Michael Ray |
0:39b09b3d8731 | 26 | |
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() { |
JimCarver | 1:b64f47a659a1 | 30 | printf("Thread Initialized\r\n"); |
Michael Ray |
0:39b09b3d8731 | 31 | while(true) { |
Michael Ray |
0:39b09b3d8731 | 32 | char latBuffer[16], lonBuffer[16]; |
Michael Ray |
0:39b09b3d8731 | 33 | gps.getLatitude(latBuffer); |
Michael Ray |
0:39b09b3d8731 | 34 | gps.getLongitude(lonBuffer); |
Michael Ray |
0:39b09b3d8731 | 35 | |
Michael Ray |
0:39b09b3d8731 | 36 | // Utilize latitude and longitude values here |
JimCarver | 1:b64f47a659a1 | 37 | printf("\r\nLa=%s Lo=%s\r\n", latBuffer, lonBuffer); |
Michael Ray |
0:39b09b3d8731 | 38 | wait(1); |
Michael Ray |
0:39b09b3d8731 | 39 | } |
Michael Ray |
0:39b09b3d8731 | 40 | } |
Michael Ray |
0:39b09b3d8731 | 41 | |
Michael Ray |
0:39b09b3d8731 | 42 | int main() { |
JimCarver | 1:b64f47a659a1 | 43 | GPS_init(); |
JimCarver | 1:b64f47a659a1 | 44 | printf("GPS Initialized\r\n"); |
Michael Ray |
0:39b09b3d8731 | 45 | // Start a thread to get updated GPS values |
JimCarver | 1:b64f47a659a1 | 46 | gpsThread.start(callback(gps_updater_thread)); |
Michael Ray |
0:39b09b3d8731 | 47 | |
JimCarver | 1:b64f47a659a1 | 48 | // do nothing while the library does all the work |
Michael Ray |
0:39b09b3d8731 | 49 | while (true) { |
JimCarver | 1:b64f47a659a1 | 50 | // Include a long wait to unblock the threads |
JimCarver | 1:b64f47a659a1 | 51 | wait(100000); |
Michael Ray |
0:39b09b3d8731 | 52 | } |
Michael Ray |
0:39b09b3d8731 | 53 | |
Michael Ray |
0:39b09b3d8731 | 54 | return 0; |
Michael Ray |
0:39b09b3d8731 | 55 | } |