From 1414ebd421e5df2ef04654085b1b9e3760acab5c Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Thu, 2 Jan 2020 15:44:09 +0100 Subject: [PATCH 1/2] Show pressure with BMP180/BME280 (issue 519) --- src/display.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/display.cpp b/src/display.cpp index 3262f290..e1f5f496 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -343,7 +343,10 @@ 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); -#endif +#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 #else dp_printf(16, 5, FONT_STRETCHED, 1, "No BME"); From acabc8b7d6b21c10bb5102c11a94067e911bf3dd Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Fri, 3 Jan 2020 09:59:10 +0100 Subject: [PATCH 2/2] gps fix detection enhanced --- include/gpsread.h | 1 + src/display.cpp | 8 ++++---- src/gpsread.cpp | 19 ++++++++++++++++--- src/senddata.cpp | 4 ++-- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/include/gpsread.h b/include/gpsread.h index d8728b7d..edabf8a4 100644 --- a/include/gpsread.h +++ b/include/gpsread.h @@ -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); diff --git a/src/display.cpp b/src/display.cpp index e1f5f496..2ea84393 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -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 diff --git a/src/gpsread.cpp b/src/gpsread.cpp index eab3b3b3..99d4de77 100644 --- a/src/gpsread.cpp +++ b/src/gpsread.cpp @@ -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()); diff --git a/src/senddata.cpp b/src/senddata.cpp index cf4922a9..f4f6b085 100644 --- a/src/senddata.cpp +++ b/src/senddata.cpp @@ -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);