-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGPS.ino
110 lines (94 loc) · 2.87 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
107
108
109
110
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
// 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()
{
byte DesiredMode;
// 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();
}
else
{
UGPS.Longitude = 0;
UGPS.Latitude = 0;
}
// Altitude
if (gps.altitude.isValid())
UGPS.Altitude = gps.altitude.meters();
else
UGPS.Altitude = 5;
if (UGPS.Altitude < 0)
UGPS.Altitude = 5;
if (gps.speed.isValid())
{
UGPS.Speed = uint8_t(gps.speed.kmph());
}
// Chip temperature
UGPS.Temp = ReadTemp() + tempOffset;
// Chip VCC
UGPS.Internal_VCC = ReadVCC();
}
/*********************************************************************************************************************************/
void printGPSData()
{
#if defined(DEVMODE)
Serial.println();
Serial.println(F("-------GPS DATA-----------"));
Serial.print(F(" Time: ")); Serial.print(UGPS.Hours); Serial.print(":"); Serial.print(UGPS.Minutes); Serial.print(":"); Serial.println(UGPS.Seconds);
Serial.print(F(" Latitude: ")); Serial.println(UGPS.Latitude, 6);
Serial.print(F(" Longitude: ")); Serial.println(UGPS.Longitude, 6);
Serial.print(F(" Altitude (m): ")); Serial.println(UGPS.Altitude);
Serial.print(F(" Satellites: ")); Serial.println(UGPS.Satellites);
Serial.println(F("-------------------------"));
Serial.println();
#endif
}
/*********************************************************************************************************************************/
void SendUBX(unsigned char *Message, int Length)
{
int i;
for (i=0; i<Length; i++)
{
SerialGPS.write(Message[i]);
}
}