Eric Leal
/
GPS_sample_os6
Sample code to show the outputs of my GPS library for mbed6 using serial interrupt
main.cpp@0:932beb312ff9, 2021-09-15 (annotated)
- Committer:
- ericleal
- Date:
- Wed Sep 15 23:21:46 2021 +0000
- Revision:
- 0:932beb312ff9
initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ericleal | 0:932beb312ff9 | 1 | /* mbed Microcontroller Library |
ericleal | 0:932beb312ff9 | 2 | * Copyright (c) 2019 ARM Limited |
ericleal | 0:932beb312ff9 | 3 | * SPDX-License-Identifier: Apache-2.0 |
ericleal | 0:932beb312ff9 | 4 | */ |
ericleal | 0:932beb312ff9 | 5 | |
ericleal | 0:932beb312ff9 | 6 | #include "mbed.h" |
ericleal | 0:932beb312ff9 | 7 | #include "GPS.h" |
ericleal | 0:932beb312ff9 | 8 | |
ericleal | 0:932beb312ff9 | 9 | |
ericleal | 0:932beb312ff9 | 10 | GPS gps(PG_14, PG_9); |
ericleal | 0:932beb312ff9 | 11 | |
ericleal | 0:932beb312ff9 | 12 | |
ericleal | 0:932beb312ff9 | 13 | int main() |
ericleal | 0:932beb312ff9 | 14 | { |
ericleal | 0:932beb312ff9 | 15 | // Initialise the digital pin LED1 as an output |
ericleal | 0:932beb312ff9 | 16 | DigitalOut led(LED1); |
ericleal | 0:932beb312ff9 | 17 | |
ericleal | 0:932beb312ff9 | 18 | |
ericleal | 0:932beb312ff9 | 19 | while (true) { |
ericleal | 0:932beb312ff9 | 20 | |
ericleal | 0:932beb312ff9 | 21 | bool update = gps.updateCheck(); |
ericleal | 0:932beb312ff9 | 22 | if (update) { |
ericleal | 0:932beb312ff9 | 23 | int time = gps.getTime(); |
ericleal | 0:932beb312ff9 | 24 | int latitude = static_cast<int>(gps.getLat() * 100000.0f); |
ericleal | 0:932beb312ff9 | 25 | int longitude = static_cast<int>(gps.getLong() * 100000.0f); |
ericleal | 0:932beb312ff9 | 26 | int speed = static_cast<int>(gps.getSpeed() * 100.0f); |
ericleal | 0:932beb312ff9 | 27 | int hdop = static_cast<int>(gps.getHDOP() * 10.0f); |
ericleal | 0:932beb312ff9 | 28 | int sats = gps.getSats(); |
ericleal | 0:932beb312ff9 | 29 | |
ericleal | 0:932beb312ff9 | 30 | printf("time:%d lat:%d long:%d speed:%d hdop:%d sats:%d\r\n", time, latitude, longitude, speed, hdop, sats); |
ericleal | 0:932beb312ff9 | 31 | led = !led; |
ericleal | 0:932beb312ff9 | 32 | } |
ericleal | 0:932beb312ff9 | 33 | ThisThread::sleep_for(100ms); |
ericleal | 0:932beb312ff9 | 34 | |
ericleal | 0:932beb312ff9 | 35 | } |
ericleal | 0:932beb312ff9 | 36 | } |