sforkowany z mirror/meshtastic-firmware
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).1.2-legacy
rodzic
55dafcbecb
commit
9b25818a50
|
@ -25,7 +25,7 @@ void readFromRTC();
|
|||
*
|
||||
* When new data is available it will notify observers.
|
||||
*/
|
||||
class GPS : public Observable<void *>
|
||||
class GPS
|
||||
{
|
||||
protected:
|
||||
bool hasValidLocation = false; // default to false, until we complete our first read
|
||||
|
@ -48,6 +48,7 @@ class GPS : public Observable<void *>
|
|||
|
||||
virtual ~GPS() {}
|
||||
|
||||
/** We will notify this observable anytime GPS state has changed meaningfully */
|
||||
Observable<const meshtastic::GPSStatus *> newStatus;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <assert.h>
|
||||
#include <string>
|
||||
|
||||
#include "GPSStatus.h"
|
||||
#include "MemoryPool.h"
|
||||
#include "MeshRadio.h"
|
||||
#include "MeshTypes.h"
|
||||
|
@ -17,7 +18,8 @@
|
|||
*/
|
||||
class MeshService
|
||||
{
|
||||
CallbackObserver<MeshService, void *> gpsObserver = CallbackObserver<MeshService, void *>(this, &MeshService::onGPSChanged);
|
||||
CallbackObserver<MeshService, const meshtastic::GPSStatus *> gpsObserver =
|
||||
CallbackObserver<MeshService, const meshtastic::GPSStatus *>(this, &MeshService::onGPSChanged);
|
||||
CallbackObserver<MeshService, const MeshPacket *> packetReceivedObserver =
|
||||
CallbackObserver<MeshService, const MeshPacket *>(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
|
||||
|
|
Ładowanie…
Reference in New Issue