forked from UWARG/RC-Car-Bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GPS.c
executable file
·90 lines (83 loc) · 1.74 KB
/
GPS.c
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
/*
* File: GPS.c
* Author: Chris Hajduk
*
* Created on August 24, 2014, 9:09 PM
*/
#include "InterchipDMA.h"
#include "SPI1.h"
#include "GPS.h"
extern GPSData GPS;
long double relativeLatitude = 0;
long double relativeLongitude = 0;
char GPSLock = 0;
static float lastGpsTime = 0.0;
void initGPS(){
init_SPI1();
init_DMA0();
}
long double getLatitude(){
return GPS.latitude;
}
long double getLongitude(){
return GPS.longitude;
}
int getHeading(){
return GPS.heading;
}
float getSpeed(){
return GPS.speed;
}
int getAltitude(){
return GPS.altitude;
}
void getPosition(long double* position){ //must pass in an array[2] to hold position
position[0] = GPS.longitude; // puts lat in [0] and long in [1]
position[1] = GPS.latitude;
}
char isGPSLocked(){ // returns 0 or 1 if locked or not??
return GPS.positionFix;
}
char getSatellites(){
return GPS.satellites;
}
float getUTCTime(){
float localTime = GPS.time;
if (lastGpsTime > localTime) {
localTime = lastGpsTime;
}
else {
lastGpsTime = localTime;
}
return localTime;
}
char getHour(){
float localTime = GPS.time;
if (lastGpsTime > localTime) {
localTime = lastGpsTime;
}
else {
lastGpsTime = localTime;
}
return (char)((int)(localTime/10000) % 100);
}
char getMin(){
float localTime = GPS.time;
if (lastGpsTime > localTime) {
localTime = lastGpsTime;
}
else {
lastGpsTime = localTime;
}
return (char)((int)(localTime/100) % 100);
}
char getSec(){
float localTime = GPS.time;
if (lastGpsTime > localTime) {
localTime = lastGpsTime;
}
else {
lastGpsTime = localTime;
}
return (char)((long)localTime % 100);
}