2020-02-06 07:39:21 -08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "Observer.h"
|
2020-03-18 19:15:51 -07:00
|
|
|
#include "PeriodicTask.h"
|
|
|
|
|
#include "sys/time.h"
|
2020-02-06 07:39:21 -08:00
|
|
|
|
2020-05-04 11:15:05 -07:00
|
|
|
/// 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();
|
|
|
|
|
|
2020-02-06 07:39:21 -08:00
|
|
|
/**
|
|
|
|
|
* A gps class that only reads from the GPS periodically (and FIXME - eventually keeps the gps powered down except when reading)
|
2020-03-18 19:15:51 -07:00
|
|
|
*
|
2020-02-06 07:39:21 -08:00
|
|
|
* When new data is available it will notify observers.
|
|
|
|
|
*/
|
2020-05-04 11:15:05 -07:00
|
|
|
class GPS : public Observable<void *>
|
2020-02-06 07:39:21 -08:00
|
|
|
{
|
2020-05-04 11:15:05 -07:00
|
|
|
protected:
|
|
|
|
|
bool hasValidLocation = false; // default to false, until we complete our first read
|
2020-02-19 08:17:28 -08:00
|
|
|
|
2020-05-04 11:15:05 -07:00
|
|
|
static HardwareSerial &_serial_gps;
|
2020-02-19 10:53:09 -08:00
|
|
|
|
2020-05-04 11:15:05 -07:00
|
|
|
public:
|
2020-05-04 11:21:24 -07:00
|
|
|
int32_t latitude = 0, longitude = 0; // as an int mult by 1e-7 to get value as double
|
|
|
|
|
int32_t altitude = 0;
|
2020-05-04 11:15:05 -07:00
|
|
|
bool isConnected = false; // Do we have a GPS we are talking to
|
2020-02-21 12:24:35 -08:00
|
|
|
|
2020-05-04 11:15:05 -07:00
|
|
|
virtual ~GPS() {}
|
2020-02-21 12:24:35 -08:00
|
|
|
|
2020-05-04 11:15:05 -07:00
|
|
|
/**
|
|
|
|
|
* Returns true if we succeeded
|
|
|
|
|
*/
|
|
|
|
|
virtual bool setup() = 0;
|
2020-02-22 13:14:10 -08:00
|
|
|
|
2020-03-26 09:24:53 -07:00
|
|
|
/// Returns ture if we have acquired GPS lock.
|
|
|
|
|
bool hasLock() const { return hasValidLocation; }
|
|
|
|
|
|
2020-05-04 11:15:05 -07:00
|
|
|
/**
|
|
|
|
|
* 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() {}
|
2020-02-06 07:39:21 -08:00
|
|
|
};
|
|
|
|
|
|
2020-05-04 11:15:05 -07:00
|
|
|
extern GPS *gps;
|