Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of GroveGPS-Example by
main.cpp@1:7239f4aa1605, 2018-05-31 (annotated)
- Committer:
- JimCarver
- Date:
- Thu May 31 16:29:40 2018 +0000
- Revision:
- 1:7239f4aa1605
- Parent:
- 0:39b09b3d8731
bug
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:7239f4aa1605 | 23 | extern int GPS_init(); |
| JimCarver | 1:7239f4aa1605 | 24 | extern GroveGPS gps; |
| JimCarver | 1:7239f4aa1605 | 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:7239f4aa1605 | 30 | int tt, hours, minutes, seconds, tday; |
| JimCarver | 1:7239f4aa1605 | 31 | int months[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; |
| JimCarver | 1:7239f4aa1605 | 32 | printf("Thread Initialized\r\n"); |
| Michael Ray |
0:39b09b3d8731 | 33 | while(true) { |
| Michael Ray |
0:39b09b3d8731 | 34 | char latBuffer[16], lonBuffer[16]; |
| Michael Ray |
0:39b09b3d8731 | 35 | gps.getLatitude(latBuffer); |
| Michael Ray |
0:39b09b3d8731 | 36 | gps.getLongitude(lonBuffer); |
| Michael Ray |
0:39b09b3d8731 | 37 | |
| Michael Ray |
0:39b09b3d8731 | 38 | // Utilize latitude and longitude values here |
| JimCarver | 1:7239f4aa1605 | 39 | printf("\r\nLa=%s Lo=%s\r\n", latBuffer, lonBuffer); |
| JimCarver | 1:7239f4aa1605 | 40 | tt = gps.gps_zda.utc_time; |
| JimCarver | 1:7239f4aa1605 | 41 | hours = tt / 10000; |
| JimCarver | 1:7239f4aa1605 | 42 | tt = tt - (hours*10000); |
| JimCarver | 1:7239f4aa1605 | 43 | minutes = tt / 100; |
| JimCarver | 1:7239f4aa1605 | 44 | seconds = tt - (minutes*100); |
| JimCarver | 1:7239f4aa1605 | 45 | // Correct UTC to PAcific time |
| JimCarver | 1:7239f4aa1605 | 46 | hours -= 7; |
| JimCarver | 1:7239f4aa1605 | 47 | tday = gps.gps_zda.day; |
| JimCarver | 1:7239f4aa1605 | 48 | if(hours < 0) { // UTC Correct |
| JimCarver | 1:7239f4aa1605 | 49 | hours += 24; |
| JimCarver | 1:7239f4aa1605 | 50 | tday -= 1; |
| JimCarver | 1:7239f4aa1605 | 51 | if(!tday) { |
| JimCarver | 1:7239f4aa1605 | 52 | tday = months[gps.gps_zda.month]; |
| JimCarver | 1:7239f4aa1605 | 53 | } |
| JimCarver | 1:7239f4aa1605 | 54 | } |
| JimCarver | 1:7239f4aa1605 | 55 | printf("\r\n%02d", seconds); |
| Michael Ray |
0:39b09b3d8731 | 56 | wait(1); |
| Michael Ray |
0:39b09b3d8731 | 57 | } |
| Michael Ray |
0:39b09b3d8731 | 58 | } |
| Michael Ray |
0:39b09b3d8731 | 59 | |
| Michael Ray |
0:39b09b3d8731 | 60 | int main() { |
| JimCarver | 1:7239f4aa1605 | 61 | GPS_init(); |
| JimCarver | 1:7239f4aa1605 | 62 | printf("GPS Initialized\r\n"); |
| Michael Ray |
0:39b09b3d8731 | 63 | // Start a thread to get updated GPS values |
| JimCarver | 1:7239f4aa1605 | 64 | gpsThread.start(callback(gps_updater_thread)); |
| Michael Ray |
0:39b09b3d8731 | 65 | |
| JimCarver | 1:7239f4aa1605 | 66 | // do nothing while the library does all the work |
| Michael Ray |
0:39b09b3d8731 | 67 | while (true) { |
| JimCarver | 1:7239f4aa1605 | 68 | |
| Michael Ray |
0:39b09b3d8731 | 69 | } |
| Michael Ray |
0:39b09b3d8731 | 70 | |
| Michael Ray |
0:39b09b3d8731 | 71 | return 0; |
| Michael Ray |
0:39b09b3d8731 | 72 | } |
