-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTinyGPSPlusAdapter.cpp
More file actions
76 lines (63 loc) · 2.21 KB
/
TinyGPSPlusAdapter.cpp
File metadata and controls
76 lines (63 loc) · 2.21 KB
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
#include <TinyGPSPlusAdapter.h>
TinyGPSPlusAdapter::TinyGPSPlusAdapter(SoftwareSerial* swserial) {
this->swserial = swserial;
}
void TinyGPSPlusAdapter::begin() {
this->swserial->begin(kGPSBaudRate);
this->swserial->println(PMTK_CMD_HOT_START);
this->swserial->println(PMTK_ENABLE_WAAS);
this->swserial->println(PMTK_SET_NMEA_OUTPUT_RMCGGA);
this->swserial->println(PMTK_SET_NMEA_UPDATE_1HZ);
this->swserial->println(PMTK_API_SET_FIX_CTL_1HZ);
delay(1000);
Serial.println(F("tinygps plus ready"));
}
void TinyGPSPlusAdapter::latlng(float* lat, float* lng) {
*lat = this->gps.location.lat();
*lng = this->gps.location.lng();
}
float TinyGPSPlusAdapter::speed() {
return (this->gps.speed.isValid() ? this->gps.speed.kmph() : 0);
}
float TinyGPSPlusAdapter::altitude() {
return (this->gps.altitude.isValid() ? this->gps.altitude.meters() : 0);
}
float TinyGPSPlusAdapter::hdop() {
return (this->fix() ? this->gps.hdop.value() / 100.0 : 9999);
}
bool TinyGPSPlusAdapter::fix() {
return this->gps.location.isValid();
}
float TinyGPSPlusAdapter::course() {
return (this->gps.course.isValid() ? this->gps.course.deg() : 0);
}
void TinyGPSPlusAdapter::datetime(int* year, byte* month, byte* day, byte* hour, byte* minute, byte* second) {
*year = this->gps.date.year();
*month = this->gps.date.month();
*day = this->gps.date.day();
*hour = this->gps.time.hour();
*minute = this->gps.time.minute();
*second = this->gps.time.second();
}
bool TinyGPSPlusAdapter::read() {
if (!this->swserial->available()) {
return 0;
}
byte data = this->swserial->read();
return this->gps.encode(data);
}
void TinyGPSPlusAdapter::dump() {
}
void TinyGPSPlusAdapter::query(float* lat, float* lng, float* speed, float* altitude, float* hdop, int* year, uint8_t* month, uint8_t* day, uint8_t* hour, uint8_t* minute, uint8_t* second) {
*lat = this->gps.location.lat();
*lng = this->gps.location.lng();
*speed = this->gps.speed.kmph();
*altitude = this->gps.altitude.meters();
*hdop = this->gps.hdop.value();
*year = this->gps.date.year();
*month = this->gps.date.month();
*day = this->gps.date.day();
*hour = this->gps.time.hour();
*minute = this->gps.time.minute();
*second = this->gps.time.second();
}