]> git.piffa.net Git - arduino/blob - books/pdummies/Libraries/Adafruit_GPS/Adafruit_GPS.h
first commit
[arduino] / books / pdummies / Libraries / Adafruit_GPS / Adafruit_GPS.h
1 /***********************************
2 This is the Adafruit GPS library - the ultimate GPS library
3 for the ultimate GPS module!
4
5 Tested and works great with the Adafruit Ultimate GPS module
6 using MTK33x9 chipset
7     ------> http://www.adafruit.com/products/746
8 Pick one up today at the Adafruit electronics shop 
9 and help support open source hardware & software! -ada
10
11 Adafruit invests time and resources providing this open source code, 
12 please support Adafruit and open-source hardware by purchasing 
13 products from Adafruit!
14
15 Written by Limor Fried/Ladyada  for Adafruit Industries.  
16 BSD license, check license.txt for more information
17 All text above must be included in any redistribution
18 ****************************************/
19
20 #ifndef _ADAFRUIT_GPS_H
21 #define _ADAFRUIT_GPS_H
22
23 #if ARDUINO >= 100
24  #include <SoftwareSerial.h>
25 #else
26  #include <NewSoftSerial.h>
27 #endif
28
29 // different commands to set the update rate from once a second (1 Hz) to 10 times a second (10Hz)
30 #define PMTK_SET_NMEA_UPDATE_1HZ  "$PMTK220,1000*1F"
31 #define PMTK_SET_NMEA_UPDATE_5HZ  "$PMTK220,200*2C"
32 #define PMTK_SET_NMEA_UPDATE_10HZ "$PMTK220,100*2F"
33
34
35 #define PMTK_SET_BAUD_57600 "$PMTK251,57600*2C"
36 #define PMTK_SET_BAUD_9600 "$PMTK251,9600*17"
37
38 // turn on only the second sentence (GPRMC)
39 #define PMTK_SET_NMEA_OUTPUT_RMCONLY "$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29"
40 // turn on GPRMC and GGA
41 #define PMTK_SET_NMEA_OUTPUT_RMCGGA "$PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28"
42 // turn on ALL THE DATA
43 #define PMTK_SET_NMEA_OUTPUT_ALLDATA "$PMTK314,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0*28"
44 // turn off output
45 #define PMTK_SET_NMEA_OUTPUT_OFF "$PMTK314,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28"
46
47 // to generate your own sentences, check out the MTK command datasheet and use a checksum calculator
48 // such as the awesome http://www.hhhh.org/wiml/proj/nmeaxor.html
49
50 #define PMTK_LOCUS_STARTLOG  "$PMTK185,0*22"
51 #define PMTK_LOCUS_LOGSTARTED "$PMTK001,185,3*3C"
52 #define PMTK_LOCUS_QUERY_STATUS "$PMTK183*38"
53 #define PMTK_LOCUS_ERASE_FLASH "$PMTK184,1*22"
54 #define LOCUS_OVERLAP 0
55 #define LOCUS_FULLSTOP 1
56
57 // standby command & boot successful message
58 #define PMTK_STANDBY "$PMTK161,0*28"
59 #define PMTK_STANDBY_SUCCESS "$PMTK001,161,3*3"  // Not needed currently
60 #define PMTK_AWAKE "$PMTK010,002*2D"
61
62 // ask for the release and version
63 #define PMTK_Q_RELEASE "$PMTK605*31"
64
65 // request for updates on antenna status 
66 #define PGCMD_ANTENNA "$PGCMD,33,1*6C" 
67 #define PGCMD_NOANTENNA "$PGCMD,33,0*6C" 
68
69 // how long to wait when we're looking for a response
70 #define MAXWAITSENTENCE 5
71
72 #if ARDUINO >= 100
73  #include "Arduino.h"
74 #if !defined(__AVR_ATmega32U4__)
75  #include "SoftwareSerial.h"
76 #endif
77 #else
78  #include "WProgram.h"
79  #include "NewSoftSerial.h"
80 #endif
81
82
83 class Adafruit_GPS {
84  public:
85   void begin(uint16_t baud); 
86
87 #if ARDUINO >= 100 
88   Adafruit_GPS(SoftwareSerial *ser); // Constructor when using SoftwareSerial
89 #else
90   Adafruit_GPS(NewSoftSerial  *ser); // Constructor when using NewSoftSerial
91 #endif
92   Adafruit_GPS(HardwareSerial *ser); // Constructor when using HardwareSerial
93
94   char *lastNMEA(void);
95   boolean newNMEAreceived();
96   void common_init(void);
97   void sendCommand(char *);
98   void pause(boolean b);
99
100   boolean parseNMEA(char *response);
101   uint8_t parseHex(char c);
102
103   char read(void);
104   boolean parse(char *);
105   void interruptReads(boolean r);
106
107   boolean wakeup(void);
108  boolean standby(void);
109
110   uint8_t hour, minute, seconds, year, month, day;
111   uint16_t milliseconds;
112   float latitude, longitude, geoidheight, altitude;
113   float speed, angle, magvariation, HDOP;
114   char lat, lon, mag;
115   boolean fix;
116   uint8_t fixquality, satellites;
117
118   boolean waitForSentence(char *wait, uint8_t max = MAXWAITSENTENCE);
119   boolean LOCUS_StartLogger(void);
120   boolean LOCUS_ReadStatus(void);
121
122   uint16_t LOCUS_serial, LOCUS_records;
123   uint8_t LOCUS_type, LOCUS_mode, LOCUS_config, LOCUS_interval, LOCUS_distance, LOCUS_speed, LOCUS_status, LOCUS_percent;
124  private:
125   boolean paused;
126   
127   uint8_t parseResponse(char *response);
128 #if ARDUINO >= 100
129   SoftwareSerial *gpsSwSerial;
130 #else
131   NewSoftSerial  *gpsSwSerial;
132 #endif
133   HardwareSerial *gpsHwSerial;
134 };
135
136
137 #endif