gps fix detection enhanced
This commit is contained in:
parent
1414ebd421
commit
acabc8b7d6
@ -17,6 +17,7 @@ extern TaskHandle_t GpsTask;
|
|||||||
|
|
||||||
int gps_init(void);
|
int gps_init(void);
|
||||||
int gps_config();
|
int gps_config();
|
||||||
|
bool gps_hasfix();
|
||||||
void gps_storelocation(gpsStatus_t *gps_store);
|
void gps_storelocation(gpsStatus_t *gps_store);
|
||||||
void gps_loop(void *pvParameters);
|
void gps_loop(void *pvParameters);
|
||||||
time_t fetch_gpsTime(uint16_t *msec);
|
time_t fetch_gpsTime(uint16_t *msec);
|
||||||
|
@ -255,9 +255,9 @@ void draw_page(time_t t, uint8_t page) {
|
|||||||
dp_printf(0, 4, FONT_SMALL, 0, "B:%.2fV", batt_voltage / 1000.0);
|
dp_printf(0, 4, FONT_SMALL, 0, "B:%.2fV", batt_voltage / 1000.0);
|
||||||
#endif
|
#endif
|
||||||
#if (HAS_GPS)
|
#if (HAS_GPS)
|
||||||
if (gps.location.age() < 1500) // if no fix then display Sats value inverse
|
if (gps_hasfix())
|
||||||
dp_printf(48, 4, FONT_SMALL, 0, "Sats:%.2d", gps.satellites.value());
|
dp_printf(48, 4, FONT_SMALL, 0, "Sats:%.2d", gps.satellites.value());
|
||||||
else
|
else // if no fix then display Sats value inverse
|
||||||
dp_printf(48, 4, FONT_SMALL, 1, "Sats:%.2d", gps.satellites.value());
|
dp_printf(48, 4, FONT_SMALL, 1, "Sats:%.2d", gps.satellites.value());
|
||||||
#endif
|
#endif
|
||||||
dp_printf(96, 4, FONT_SMALL, 0, "ch:%02d", channel);
|
dp_printf(96, 4, FONT_SMALL, 0, "ch:%02d", channel);
|
||||||
@ -305,7 +305,7 @@ void draw_page(time_t t, uint8_t page) {
|
|||||||
// page 2: GPS
|
// page 2: GPS
|
||||||
case 2:
|
case 2:
|
||||||
#if (HAS_GPS)
|
#if (HAS_GPS)
|
||||||
if (gps.location.age() < 1500) {
|
if (gps_hasfix()) {
|
||||||
// line 5: clear "No fix"
|
// line 5: clear "No fix"
|
||||||
if (wasnofix) {
|
if (wasnofix) {
|
||||||
dp_printf(16, 5, FONT_STRETCHED, 0, " ");
|
dp_printf(16, 5, FONT_STRETCHED, 0, " ");
|
||||||
|
@ -74,14 +74,27 @@ int gps_config() {
|
|||||||
void gps_storelocation(gpsStatus_t *gps_store) {
|
void gps_storelocation(gpsStatus_t *gps_store) {
|
||||||
if (gps.location.isUpdated() && gps.location.isValid() &&
|
if (gps.location.isUpdated() && gps.location.isValid() &&
|
||||||
(gps.location.age() < 1500)) {
|
(gps.location.age() < 1500)) {
|
||||||
gps_store->latitude = (int32_t)(gps.location.lat() * 1e6);
|
// gps_store->latitude = (int32_t)(gps.location.lat() * 1e6);
|
||||||
gps_store->longitude = (int32_t)(gps.location.lng() * 1e6);
|
// gps_store->longitude = (int32_t)(gps.location.lng() * 1e6);
|
||||||
|
gps_store->latitude =
|
||||||
|
(int32_t)((gps.location.lat() + 90) / 180.0) * 16777215;
|
||||||
|
gps_store->longitude =
|
||||||
|
(int32_t)((gps.location.lng() + 180) / 360.0) * 16777215;
|
||||||
gps_store->satellites = (uint8_t)gps.satellites.value();
|
gps_store->satellites = (uint8_t)gps.satellites.value();
|
||||||
gps_store->hdop = (uint16_t)gps.hdop.value();
|
gps_store->hdop = (uint16_t)gps.hdop.value();
|
||||||
gps_store->altitude = (int16_t)gps.altitude.meters();
|
gps_store->altitude = (int16_t)gps.altitude.meters();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool gps_hasfix() {
|
||||||
|
// adapted from source:
|
||||||
|
// https://github.com/hottimuc/Lora-TTNMapper-T-Beam/blob/master/fromV08/gps.cpp
|
||||||
|
return (gps.location.isValid() && gps.location.age() < 4000 &&
|
||||||
|
gps.hdop.isValid() && gps.hdop.value() <= 600 &&
|
||||||
|
gps.hdop.age() < 4000 && gps.altitude.isValid() &&
|
||||||
|
gps.altitude.age() < 4000);
|
||||||
|
}
|
||||||
|
|
||||||
// function to fetch current time from struct; note: this is costly
|
// function to fetch current time from struct; note: this is costly
|
||||||
time_t fetch_gpsTime(uint16_t *msec) {
|
time_t fetch_gpsTime(uint16_t *msec) {
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ void sendData() {
|
|||||||
#if (HAS_GPS)
|
#if (HAS_GPS)
|
||||||
if (GPSPORT == COUNTERPORT) {
|
if (GPSPORT == COUNTERPORT) {
|
||||||
// send GPS position only if we have a fix
|
// send GPS position only if we have a fix
|
||||||
if (gps.location.isValid()) {
|
if (gps_hasfix()) {
|
||||||
gps_storelocation(&gps_status);
|
gps_storelocation(&gps_status);
|
||||||
payload.addGPS(gps_status);
|
payload.addGPS(gps_status);
|
||||||
} else
|
} else
|
||||||
@ -121,7 +121,7 @@ void sendData() {
|
|||||||
case GPS_DATA:
|
case GPS_DATA:
|
||||||
if (GPSPORT != COUNTERPORT) {
|
if (GPSPORT != COUNTERPORT) {
|
||||||
// send GPS position only if we have a fix
|
// send GPS position only if we have a fix
|
||||||
if (gps.location.isValid()) {
|
if (gps_hasfix()) {
|
||||||
gps_storelocation(&gps_status);
|
gps_storelocation(&gps_status);
|
||||||
payload.reset();
|
payload.reset();
|
||||||
payload.addGPS(gps_status);
|
payload.addGPS(gps_status);
|
||||||
|
Loading…
Reference in New Issue
Block a user