gps fix detection enhanced

This commit is contained in:
Verkehrsrot 2020-01-03 09:59:10 +01:00
parent 1414ebd421
commit acabc8b7d6
4 changed files with 23 additions and 9 deletions

View File

@ -17,6 +17,7 @@ extern TaskHandle_t GpsTask;
int gps_init(void);
int gps_config();
bool gps_hasfix();
void gps_storelocation(gpsStatus_t *gps_store);
void gps_loop(void *pvParameters);
time_t fetch_gpsTime(uint16_t *msec);

View File

@ -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);
#endif
#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());
else
else // if no fix then display Sats value inverse
dp_printf(48, 4, FONT_SMALL, 1, "Sats:%.2d", gps.satellites.value());
#endif
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
case 2:
#if (HAS_GPS)
if (gps.location.age() < 1500) {
if (gps_hasfix()) {
// line 5: clear "No fix"
if (wasnofix) {
dp_printf(16, 5, FONT_STRETCHED, 0, " ");
@ -343,7 +343,7 @@ void draw_page(time_t t, uint8_t page) {
#ifdef HAS_BME680
// line 6-7: IAQ
dp_printf(0, 6, FONT_STRETCHED, 0, "IAQ:%-3.0f", bme_status.iaq);
#else // is BME280 or BMP180
#else // is BME280 or BMP180
// line 6-7: Pre
dp_printf(0, 6, FONT_STRETCHED, 0, "PRE:%-2.1f", bme_status.pressure);
#endif // HAS_BME

View File

@ -74,14 +74,27 @@ int gps_config() {
void gps_storelocation(gpsStatus_t *gps_store) {
if (gps.location.isUpdated() && gps.location.isValid() &&
(gps.location.age() < 1500)) {
gps_store->latitude = (int32_t)(gps.location.lat() * 1e6);
gps_store->longitude = (int32_t)(gps.location.lng() * 1e6);
// gps_store->latitude = (int32_t)(gps.location.lat() * 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->hdop = (uint16_t)gps.hdop.value();
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
time_t fetch_gpsTime(uint16_t *msec) {
@ -154,7 +167,7 @@ void gps_loop(void *pvParameters) {
} // if
// show NMEA data in verbose mode, useful for debugging GPS, bu tvery noisy
//ESP_LOGV(TAG, "GPS NMEA data: passed %u / failed: %u / with fix: %u",
// ESP_LOGV(TAG, "GPS NMEA data: passed %u / failed: %u / with fix: %u",
// gps.passedChecksum(), gps.failedChecksum(),
// gps.sentencesWithFix());

View File

@ -82,7 +82,7 @@ void sendData() {
#if (HAS_GPS)
if (GPSPORT == COUNTERPORT) {
// send GPS position only if we have a fix
if (gps.location.isValid()) {
if (gps_hasfix()) {
gps_storelocation(&gps_status);
payload.addGPS(gps_status);
} else
@ -121,7 +121,7 @@ void sendData() {
case GPS_DATA:
if (GPSPORT != COUNTERPORT) {
// send GPS position only if we have a fix
if (gps.location.isValid()) {
if (gps_hasfix()) {
gps_storelocation(&gps_status);
payload.reset();
payload.addGPS(gps_status);