firmware/src/GPS.h

54 lines
1.4 KiB
C
Raw Normal View History

2020-02-06 15:39:21 +00:00
#pragma once
#include "PeriodicTask.h"
#include "Observer.h"
2020-02-19 18:53:09 +00:00
#include "sys/time.h"
#include "SparkFun_Ublox_Arduino_Library.h"
2020-02-06 15:39:21 +00:00
/**
* 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
2020-02-06 15:39:21 +00:00
{
SFE_UBLOX_GPS ublox;
2020-02-06 15:39:21 +00:00
public:
double latitude, longitude;
uint32_t altitude;
2020-03-14 03:30:48 +00:00
bool isConnected; // Do we have a GPS we are talking to
2020-02-06 15:39:21 +00:00
GPS();
2020-02-19 18:53:09 +00:00
/// 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();
2020-02-06 16:18:20 +00:00
2020-02-06 15:39:21 +00:00
void setup();
virtual void loop();
2020-02-21 18:20:47 +00:00
virtual void doTask();
2020-02-19 16:17:28 +00:00
2020-02-19 18:53:09 +00:00
/// 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();
2020-02-22 21:14:10 +00:00
/// Restart our lock attempt - try to get and broadcast a GPS reading ASAP
void startLock();
2020-02-19 16:17:28 +00:00
private:
void readFromRTC();
2020-02-06 15:39:21 +00:00
};
extern GPS gps;