From 9b25818a50060f52196c01f9987ad0d083a32b8f Mon Sep 17 00:00:00 2001 From: geeksville Date: Wed, 12 Aug 2020 15:51:57 -0700 Subject: [PATCH] fix #249: report battery levels even if no GPS lock @professr I noticed you added a "newStatus" observable to the GPS class. Do you remember why you didn't remove the old GPS status (which seemed to be dumber). Is it just because you didn't want to risk breaking MeshService? (I assume) In this change I removed the old Observable and all seems well (just using newStatus everywhere). --- src/gps/GPS.h | 3 ++- src/gps/NEMAGPS.cpp | 4 ---- src/gps/UBloxGPS.cpp | 1 - src/mesh/MeshService.cpp | 8 +++++--- src/mesh/MeshService.h | 6 ++++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/gps/GPS.h b/src/gps/GPS.h index 46b4a5c05..409c6da9d 100644 --- a/src/gps/GPS.h +++ b/src/gps/GPS.h @@ -25,7 +25,7 @@ void readFromRTC(); * * When new data is available it will notify observers. */ -class GPS : public Observable +class GPS { protected: bool hasValidLocation = false; // default to false, until we complete our first read @@ -48,6 +48,7 @@ class GPS : public Observable virtual ~GPS() {} + /** We will notify this observable anytime GPS state has changed meaningfully */ Observable newStatus; /** diff --git a/src/gps/NEMAGPS.cpp b/src/gps/NEMAGPS.cpp index 1645a1656..a1d848ad8 100644 --- a/src/gps/NEMAGPS.cpp +++ b/src/gps/NEMAGPS.cpp @@ -66,10 +66,6 @@ void NEMAGPS::loop() // expect gps pos lat=37.520825, lon=-122.309162, alt=158 DEBUG_MSG("new NEMA GPS pos lat=%f, lon=%f, alt=%d, hdop=%f, heading=%f\n", latitude * 1e-7, longitude * 1e-7, altitude, dop * 1e-2, heading * 1e-5); - - hasValidLocation = (latitude != 0) || (longitude != 0); // bogus lat lon is reported as 0,0 - if (hasValidLocation) - notifyObservers(NULL); } // Notify any status instances that are observing us diff --git a/src/gps/UBloxGPS.cpp b/src/gps/UBloxGPS.cpp index 0ed506f64..c7a8501c1 100644 --- a/src/gps/UBloxGPS.cpp +++ b/src/gps/UBloxGPS.cpp @@ -160,7 +160,6 @@ The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of s { if (hasValidLocation) { wantNewLocation = false; - notifyObservers(NULL); // ublox.powerOff(); } } else // we didn't get a location update, go back to sleep and hope the characters show up diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index 38babd904..f5d0ac173 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -68,7 +68,8 @@ void MeshService::init() sendOwnerPeriod.setup(); nodeDB.init(); - gpsObserver.observe(gps); + assert(gps); + gpsObserver.observe(&gps->newStatus); packetReceivedObserver.observe(&router.notifyPacketReceived); } @@ -283,9 +284,8 @@ void MeshService::sendOurPosition(NodeNum dest, bool wantReplies) sendToMesh(p); } -int MeshService::onGPSChanged(void *unused) +int MeshService::onGPSChanged(const meshtastic::GPSStatus *unused) { - // DEBUG_MSG("got gps notify\n"); // Update our local node info with our position (even if we don't decide to update anyone else) MeshPacket *p = router.allocForSending(); @@ -305,6 +305,8 @@ int MeshService::onGPSChanged(void *unused) pos.battery_level = powerStatus->getBatteryChargePercent(); updateBatteryLevel(pos.battery_level); + // DEBUG_MSG("got gps notify time=%u, lat=%d, bat=%d\n", pos.latitude_i, pos.time, pos.battery_level); + // We limit our GPS broadcasts to a max rate static uint32_t lastGpsSend; uint32_t now = timing::millis(); diff --git a/src/mesh/MeshService.h b/src/mesh/MeshService.h index f6e688e19..7e8810778 100644 --- a/src/mesh/MeshService.h +++ b/src/mesh/MeshService.h @@ -4,6 +4,7 @@ #include #include +#include "GPSStatus.h" #include "MemoryPool.h" #include "MeshRadio.h" #include "MeshTypes.h" @@ -17,7 +18,8 @@ */ class MeshService { - CallbackObserver gpsObserver = CallbackObserver(this, &MeshService::onGPSChanged); + CallbackObserver gpsObserver = + CallbackObserver(this, &MeshService::onGPSChanged); CallbackObserver packetReceivedObserver = CallbackObserver(this, &MeshService::handleFromRadio); @@ -85,7 +87,7 @@ class MeshService /// Called when our gps position has changed - updates nodedb and sends Location message out into the mesh /// returns 0 to allow futher processing - int onGPSChanged(void *arg); + int onGPSChanged(const meshtastic::GPSStatus *arg); /// Handle a packet that just arrived from the radio. This method does _not_ free the provided packet. If it needs /// to keep the packet around it makes a copy