Skip to content

Commit 9100f15

Browse files
committed
Initial commit
0 parents  commit 9100f15

File tree

10 files changed

+831
-0
lines changed

10 files changed

+831
-0
lines changed

examples/Basic/Basic.ino

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
GP20U7 GPS Library - Basic
3+
Demonstrates the use of the GP20U7 GPS unit by retrieving the latitude
4+
and longitude of your current position.
5+
6+
The circuit:
7+
* GP20U7 TX pin to digital pin 0/RX
8+
* GP20U7 VCC pin to 3.3V
9+
* GP20U7 GND pin to ground
10+
*/
11+
12+
// include the library code:
13+
#include <gp20u7.h>
14+
15+
// initialize the library with the serial port to which the device is
16+
// connected
17+
GP20U7 gps = GP20U7(Serial);
18+
19+
// Set up a Geolocation variable to track your current Location
20+
Geolocation currentLocation;
21+
22+
void setup() {
23+
// Start the GPS module
24+
gps.begin();
25+
}
26+
27+
void loop() {
28+
// The call to read() checks for new location information and returns 1
29+
// if new data is available and 0 if it isn't. It should be called
30+
// repeatedly.
31+
if(gps.read()){
32+
currentLocation = gps.getGeolocation();
33+
Serial.println("Your current location is:");
34+
Serial.print(" Latitude: ");
35+
Serial.println(currentLocation.latitude,5);
36+
Serial.print(" Longitude: ");
37+
Serial.println(currentLocation.longitude,5);
38+
}
39+
}

keywords.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#######################################
2+
# Syntax Coloring Map For GP20U7
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
9+
GP20U7 KEYWORD1 GP20U7
10+
Geolocation KEYWORD1 Geolocation
11+
12+
#######################################
13+
# Methods and Functions (KEYWORD2)
14+
#######################################
15+
16+
getGeolocation KEYWORD2
17+
read KEYWORD2
18+
19+
#######################################
20+
# Constants (LITERAL1)
21+
#######################################

library.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=GP20U7 GPS Library
2+
version=1.0.0
3+
author=Kevin Sidwar
4+
maintainer=Kevin Sidwar <kevin@sidwar.com>
5+
sentence=A simple library for the GP20U7 GPS unit
6+
paragraph=A simple library for the GP20U7 GPS unit
7+
category=Sensors
8+
url=
9+
architectures=*

src/api/gps.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef TOI_API_GPS
2+
#define TOI_API_GPS
3+
4+
typedef struct _Geolocation
5+
{
6+
double latitude;
7+
double longitude;
8+
} Geolocation, *PGeolocation;
9+
10+
class GeolocationDevice{
11+
public:
12+
virtual ~GeolocationDevice(){}
13+
virtual Geolocation getGeolocation(void) = 0;
14+
virtual int read(void) = 0; // used for polling only
15+
virtual void begin(void) = 0;
16+
17+
protected:
18+
Geolocation _currentLocation;
19+
};
20+
21+
#endif

src/devices/gps/gp20u7.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include "gp20u7.h"
2+
// TODO: Handle uninitialized _currentLocation
3+
4+
GP20U7::GP20U7(PlatformStream &s){
5+
_stream = &s;
6+
}
7+
8+
GP20U7::GP20U7(PlatformStream *s){
9+
_stream = s;
10+
}
11+
12+
Geolocation GP20U7::getGeolocation(){
13+
return _currentLocation;
14+
}
15+
16+
int GP20U7::read(){
17+
long lat, lon;
18+
unsigned long fix_age;
19+
20+
while(_stream->available()){
21+
int c = _stream->read();
22+
if(_gps.encode(c)){
23+
_gps.get_position(&lat, &lon, &fix_age);
24+
25+
// Map tinygps values into Geolocation struct
26+
_currentLocation.latitude = lat / 1000000.0;
27+
_currentLocation.longitude = lon / 1000000.0;
28+
return 1;
29+
}
30+
}
31+
32+
return 0;
33+
}
34+
35+
void GP20U7::begin(){
36+
#if defined (ARDUINO_PLATFORM)
37+
reinterpret_cast<HardwareSerial *>(_stream)->begin(9600);
38+
#endif
39+
}

src/devices/gps/gp20u7.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef TOI_GP20U7
2+
#define TOI_GP20U7
3+
4+
#ifndef SPARK
5+
#include "../../platforms/platform.h"
6+
#include "../../api/gps.h"
7+
#include "tinygps.h"
8+
#else
9+
#include "platform.h"
10+
#include "gps.h"
11+
#include "tinygps.h"
12+
#endif
13+
14+
class GP20U7 : public GeolocationDevice
15+
{
16+
private:
17+
PlatformStream *_stream;
18+
TinyGPS _gps;
19+
20+
public:
21+
GP20U7(PlatformStream &s);
22+
GP20U7(PlatformStream *s);
23+
Geolocation getGeolocation(void);
24+
int read(void);
25+
void begin(void);
26+
};
27+
28+
#endif

0 commit comments

Comments
 (0)