-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtmGPS.cpp
78 lines (60 loc) · 1.61 KB
/
tmGPS.cpp
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
#include "tmgps.h"
static const char TAG[] = __FILE__;
HardwareSerial GPS(1); // use UART #1
tmGPS::tmGPS() {
ESP_LOGD(TAG, "GPS constructor");
}
void tmGPS::init() {
GPS.begin(9600, SERIAL_8N1, 34, 12);
ESP_LOGD(TAG, "GPS init done.");
}
void tmGPS::gpsTest() {
ESP_LOGI(TAG, "gps test");
}
void tmGPS::wifiHome() {
static uint32_t wifiHomeLastStatus = WIFI_HOME_OFF;
uint32_t wifiHomeStatus = WIFI_HOME_OFF;
double distanceKm =
TinyGPSPlus::distanceBetween(
gps.location.lat(),
gps.location.lng(),
HOME_LAT,
HOME_LNG) / 1000.0;
if (distanceKm < HOME_DISTANCE_THRES) {
wifiHomeStatus = WIFI_HOME_ON;
}
if (wifiHomeStatus != wifiHomeLastStatus) {
ESP_LOGD(TAG, "Distance (km) to Home: %.3f%Km, wifi change", distanceKm);
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
xTaskNotifyFromISR(TaskWifiHomeHandler, wifiHomeStatus, eSetBits,
&xHigherPriorityTaskWoken);
if (xHigherPriorityTaskWoken)
portYIELD_FROM_ISR();
wifiHomeLastStatus = wifiHomeStatus;
}
}
void tmGPS::readGPS() {
while (GPS.available()) {
gps.encode(GPS.read());
}
}
bool tmGPS::isFixed() {
static bool lastStatus = false;
if (gps.location.isValid() &&
gps.location.age() < 2000 &&
gps.hdop.isValid() &&
gps.hdop.value() <= 300 &&
gps.hdop.age() < 2000 &&
gps.altitude.isValid() &&
gps.altitude.age() < 2000 )
{
if (!lastStatus)
ESP_LOGI(TAG, "Valid gps Fix.");
lastStatus = true;
} else {
if (lastStatus)
ESP_LOGI(TAG, "gps not fix");
lastStatus = false;
}
return lastStatus;
}