Files
firmware/src/gps/GPS.h

52 lines
1.4 KiB
C
Raw Normal View History

2020-02-06 07:39:21 -08:00
#pragma once
#include "Observer.h"
#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-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-05-04 11:15:05 -07:00
virtual ~GPS() {}
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
/// 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;