abstract out the UBlox GPS driver

This commit is contained in:
geeksville
2020-05-04 11:15:05 -07:00
parent ecf528f9b6
commit 933d5424da
13 changed files with 263 additions and 226 deletions

View File

@@ -2,54 +2,50 @@
#include "Observer.h"
#include "PeriodicTask.h"
#include "SparkFun_Ublox_Arduino_Library.h"
#include "sys/time.h"
/// If we haven't yet set our RTC this boot, set it from a GPS derived time
void perhapsSetRTC(const struct timeval *tv);
/// Return time since 1970 in secs. Until we have a GPS lock we will be returning time based at zero
uint32_t getTime();
/// Return time since 1970 in secs. If we don't have a GPS lock return zero
uint32_t getValidTime();
void readFromRTC();
/**
* A gps class that only reads from the GPS periodically (and FIXME - eventually keeps the gps powered down except when reading)
*
* When new data is available it will notify observers.
*/
class GPS : public PeriodicTask, public Observable<void *>
class GPS : public Observable<void *>
{
SFE_UBLOX_GPS ublox;
protected:
bool hasValidLocation = false; // default to false, until we complete our first read
static HardwareSerial &_serial_gps;
public:
uint32_t latitude, longitude; // as an int mult by 1e-7 to get value as double
uint32_t altitude;
bool isConnected; // Do we have a GPS we are talking to
uint32_t latitude = 0, longitude = 0; // as an int mult by 1e-7 to get value as double
uint32_t altitude = 0;
bool isConnected = false; // Do we have a GPS we are talking to
GPS();
virtual ~GPS() {}
/// Return time since 1970 in secs. Until we have a GPS lock we will be returning time based at zero
uint32_t getTime();
/// Return time since 1970 in secs. If we don't have a GPS lock return zero
uint32_t getValidTime();
void setup();
virtual void doTask();
/// If we haven't yet set our RTC this boot, set it from a GPS derived time
void perhapsSetRTC(const struct timeval *tv);
/// Returns true if we think the board can enter deep or light sleep now (we might be trying to get a GPS lock)
bool canSleep();
/// Prepare the GPS for the cpu entering deep or light sleep, expect to be gone for at least 100s of msecs
void prepareSleep();
/// Restart our lock attempt - try to get and broadcast a GPS reading ASAP
void startLock();
/**
* Returns true if we succeeded
*/
virtual bool setup() = 0;
/// Returns ture if we have acquired GPS lock.
bool hasLock() const { return hasValidLocation; }
private:
void readFromRTC();
bool hasValidLocation = false; // default to false, until we complete our first read
/**
* Restart our lock attempt - try to get and broadcast a GPS reading ASAP
* called after the CPU wakes from light-sleep state */
virtual void startLock() {}
};
extern GPS gps;
extern GPS *gps;