-
Notifications
You must be signed in to change notification settings - Fork 11
/
GPS.ino
106 lines (89 loc) · 2.59 KB
/
GPS.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#define PEDESTRIAN 3
#define AIRBORNE 6
// The TinyGPS++ object
TinyGPSPlus gps;
/*********************************************************************************************************************************/
void CheckGPS()
{
processGPSData();
printGPSData();
}
/*********************************************************************************************************************************/
// This custom version of delay() ensures that the gps object is being "fed".
static void smartDelay(unsigned long ms)
{
unsigned long start = millis();
do
{
while (SerialGPS.available())
gps.encode(SerialGPS.read());
} while (millis() - start < ms);
}
/*********************************************************************************************************************************/
static void processGPSData()
{
// Number of Satellites
if (gps.satellites.isValid())
UGPS.Satellites = gps.satellites.value();
else
UGPS.Satellites = 0;
// Time
if (gps.time.isValid())
{
UGPS.Hours = gps.time.hour();
UGPS.Minutes = gps.time.minute();
UGPS.Seconds = gps.time.second();
}
else
{
UGPS.Hours = 0;
UGPS.Minutes = 0;
UGPS.Seconds = 0;
}
// Position
if (gps.location.isValid())
{
UGPS.Longitude = gps.location.lng();
UGPS.Latitude = gps.location.lat();
UGPS.Heading = gps.course.deg();
}
else
{
UGPS.Longitude = 0;
UGPS.Latitude = 0;
UGPS.Heading = 0;
//UGPS.Longitude = 5.1645;
//UGPS.Latitude = 52.2179;
//UGPS.Heading = 10;
}
// Altitude
if (gps.altitude.isValid())
UGPS.Altitude = gps.altitude.meters();
else
UGPS.Altitude = 0;
if (UGPS.Altitude < 0)
UGPS.Altitude = 0;
}
/*********************************************************************************************************************************/
void printGPSData()
{
#if defined(DEVMODE)
Serial.print(F("Time: ")); Serial.print(UGPS.Hours); Serial.print(":"); Serial.print(UGPS.Minutes); Serial.print(":"); Serial.println(UGPS.Seconds);
Serial.print(F(" Lat: ")); Serial.println(UGPS.Latitude, 6);
Serial.print(F(" Lon: ")); Serial.println(UGPS.Longitude, 6);
Serial.print(F(" Alt: ")); Serial.println(UGPS.Altitude);
Serial.print(F("Sats: ")); Serial.println(UGPS.Satellites);
Serial.println("------");
#endif
}
/*********************************************************************************************************************************/
void SendUBX(unsigned char *Message, int Length)
{
int i;
for (i=0; i<Length; i++)
{
SerialGPS.write(Message[i]);
}
}