forked from kilianweigand/e-bikes-solartracker-gps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gps.ino
57 lines (50 loc) · 1.22 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
#include <TinyGPSPlus.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#define RXPin 3
#define TXPin 4
#define GPSBaud 9600
// The TinyGPSPlus object
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
int validGPSData = false;
float getGPSAzimuth(){
return gps.course.deg();
}
double getGPSSpeed(){
return gps.speed.kmph();
}
int getGPSHour(){
int hour = gps.time.hour()+timezone;
if(hour>=24) hour-= 24;
return hour;
}
int getGPSMinute(){
return gps.time.minute();
}
void initGPS(){
ss.begin(GPSBaud);
if (LOG_GPS) Serial.println("initButtons done");
}
bool isGPSReady(){
if (LOG_GPS){
Serial.print("isGPSReady - location:"+String(gps.location.isValid()));
Serial.print(" time:"+String(gps.time.isValid()));
Serial.println(" course:"+String(gps.course.isValid()));
}
return gps.location.isValid() && gps.time.isValid() && gps.course.isValid();
}
void updateGPS(){
while (ss.available() > 0) {
char cc = ss.read();
if (LOG_GPS) Serial.write(cc);
gps.encode(cc);
}
//beep if it changes
bool check = isGPSReady();
if(check!=validGPSData){
beep();
validGPSData = check;
}
}