Fixed compiler errors/warnings (declaration of _uidx, scope of index variables i)

Dependents:   GPSDevice LogData_UM6-to-SDcard UM6withGPS mbed-cansat-test-GPS ... more

Fork of MODGPS by Andy K

Committer:
AjK
Date:
Sat Nov 20 21:02:06 2010 +0000
Revision:
1:6aec92e77ad2
Parent:
0:db98027c0bbb
Child:
2:8aa059e7d8b1
1.11

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AjK 1:6aec92e77ad2 1 #ifdef COMPILE_EXAMPLE_CODE_MODGPS
AjK 1:6aec92e77ad2 2
AjK 1:6aec92e77ad2 3 #include "mbed.h"
AjK 1:6aec92e77ad2 4 #include "GPS.h"
AjK 1:6aec92e77ad2 5
AjK 1:6aec92e77ad2 6 Serial pc(USBTX, USBRX);
AjK 1:6aec92e77ad2 7 DigitalOut led1(LED1);
AjK 1:6aec92e77ad2 8
AjK 1:6aec92e77ad2 9 // SET THIS.
AjK 1:6aec92e77ad2 10 // Create an instance of the GPS object. You will need to
AjK 1:6aec92e77ad2 11 // set p25 to whichever Serial RX pin you have connected
AjK 1:6aec92e77ad2 12 // your GPS module to.
AjK 1:6aec92e77ad2 13 GPS gps(NC, GPSRX);
AjK 1:6aec92e77ad2 14
AjK 1:6aec92e77ad2 15 // 0.1 second flash of LED2
AjK 1:6aec92e77ad2 16 DigitalOut led2(LED2);
AjK 1:6aec92e77ad2 17 Timeout t2;
AjK 1:6aec92e77ad2 18 void t2out(void) { led2 = 0; }
AjK 1:6aec92e77ad2 19 void blip2(void) { led2 = 1; t2.attach(&t2out, 0.1); }
AjK 1:6aec92e77ad2 20
AjK 1:6aec92e77ad2 21 // 0.1 second flash of LED3
AjK 1:6aec92e77ad2 22 DigitalOut led3(LED3);
AjK 1:6aec92e77ad2 23 Timeout t3;
AjK 1:6aec92e77ad2 24 void t3out(void) { led3 = 0; }
AjK 1:6aec92e77ad2 25 void blip3(void) { led3 = 1; t3.attach(&t3out, 0.1); }
AjK 1:6aec92e77ad2 26
AjK 1:6aec92e77ad2 27 // 0.1 second flash of LED4
AjK 1:6aec92e77ad2 28 DigitalOut led4(LED4);
AjK 1:6aec92e77ad2 29
AjK 1:6aec92e77ad2 30 Timeout t4;
AjK 1:6aec92e77ad2 31 void t4out(void) { led4 = 0; }
AjK 1:6aec92e77ad2 32 void blip4(void) { led4 = 1; t4.attach(&t4out, 0.1); }
AjK 1:6aec92e77ad2 33
AjK 1:6aec92e77ad2 34 int main() {
AjK 1:6aec92e77ad2 35 GPS_Time q1;
AjK 1:6aec92e77ad2 36
AjK 1:6aec92e77ad2 37 // SET THIS.
AjK 1:6aec92e77ad2 38 // Ensure you set the baud rate to match your serial
AjK 1:6aec92e77ad2 39 // communications to your PC/Max/Linux host so you
AjK 1:6aec92e77ad2 40 // can read the messages.
AjK 1:6aec92e77ad2 41 pc.baud(PCBAUD);
AjK 1:6aec92e77ad2 42
AjK 1:6aec92e77ad2 43 // SET THIS.
AjK 1:6aec92e77ad2 44 // Most GPS modules use 9600,8,n,1 so that's what
AjK 1:6aec92e77ad2 45 // we default to here. Ensure your GPS module matches
AjK 1:6aec92e77ad2 46 // this, otherwise set it to match.
AjK 1:6aec92e77ad2 47 gps.baud(GPSBUAD);
AjK 1:6aec92e77ad2 48 gps.format(8, GPS::None, 1);
AjK 1:6aec92e77ad2 49
AjK 1:6aec92e77ad2 50 // OPTIONAL
AjK 1:6aec92e77ad2 51 // If you GPS has a 1 pulse per second output you can
AjK 1:6aec92e77ad2 52 // connect it to an Mbed pin. Here you specify what pin
AjK 1:6aec92e77ad2 53 // and on what "edge" teh signal is active. If your GPS
AjK 1:6aec92e77ad2 54 // module has a rising edge at the one second point then
AjK 1:6aec92e77ad2 55 // use GPS::ppsRise
AjK 1:6aec92e77ad2 56 #ifdef PPSPIN
AjK 1:6aec92e77ad2 57 gps.ppsAttach(PPSPIN, GPS::ppsFall);
AjK 1:6aec92e77ad2 58 #endif
AjK 1:6aec92e77ad2 59
AjK 1:6aec92e77ad2 60 // Sample of a callback to a function when the 1PPS activates.
AjK 1:6aec92e77ad2 61 // For this example, we flash LED2 for 0.1 second.
AjK 1:6aec92e77ad2 62 gps.attach_pps(&blip2);
AjK 1:6aec92e77ad2 63
AjK 1:6aec92e77ad2 64 // Sample of a callback to a function when a NMEA GGA message is recieved.
AjK 1:6aec92e77ad2 65 // For this example, we flash LED2 for 0.1 second.
AjK 1:6aec92e77ad2 66 gps.attach_gga(&blip3);
AjK 1:6aec92e77ad2 67
AjK 1:6aec92e77ad2 68 // Sample of a callback to a function when a NMEA RMC message is recieved.
AjK 1:6aec92e77ad2 69 // For this example, we flash LED2 for 0.1 second.
AjK 1:6aec92e77ad2 70 gps.attach_rmc(&blip4);
AjK 1:6aec92e77ad2 71
AjK 1:6aec92e77ad2 72 while(1) {
AjK 1:6aec92e77ad2 73 // Every 3 seconds, flip LED1 and print the basic GPS info.
AjK 1:6aec92e77ad2 74 wait(3);
AjK 1:6aec92e77ad2 75 led1 = 1;
AjK 1:6aec92e77ad2 76
AjK 1:6aec92e77ad2 77 // Demonstrate how to find out the GPS location co-ords.
AjK 1:6aec92e77ad2 78 pc.printf("Method 1. Lat = %.4f ", gps.latitude());
AjK 1:6aec92e77ad2 79 pc.printf("Lon = %.4f ", gps.longitude());
AjK 1:6aec92e77ad2 80 pc.printf("Alt = %.4f ", gps.altitude());
AjK 1:6aec92e77ad2 81
AjK 1:6aec92e77ad2 82 // Gran a snapshot of the current time.
AjK 1:6aec92e77ad2 83 gps.timeNow(&q1);
AjK 1:6aec92e77ad2 84 pc.printf("%02d:%02d:%02d %02d/%02d/%04d\r\n",
AjK 1:6aec92e77ad2 85 q1.hour, q1.minute, q1.second, q1.day, q1.month, q1.year);
AjK 1:6aec92e77ad2 86
AjK 1:6aec92e77ad2 87 // Alternative method that does the same thing.
AjK 1:6aec92e77ad2 88 pc.printf("Method 2. Lat = %.4f ", gps.latitude());
AjK 1:6aec92e77ad2 89 pc.printf("Lon = %.4f ", gps.longitude());
AjK 1:6aec92e77ad2 90 pc.printf("Alt = %.4f ", gps.altitude());
AjK 1:6aec92e77ad2 91
AjK 1:6aec92e77ad2 92 GPS_Time *q2 = gps.timeNow();
AjK 1:6aec92e77ad2 93 pc.printf("%02d:%02d:%02d %02d/%02d/%04d\r\n\n",
AjK 1:6aec92e77ad2 94 q2->hour, q2->minute, q2->second, q2->day, q2->month, q2->year);
AjK 1:6aec92e77ad2 95 delete(q2);
AjK 1:6aec92e77ad2 96 led1 = 0;
AjK 1:6aec92e77ad2 97 }
AjK 1:6aec92e77ad2 98 }
AjK 1:6aec92e77ad2 99
AjK 1:6aec92e77ad2 100 #endif