37 lines
651 B
C++
37 lines
651 B
C++
#ifndef INTERNET_TIME_H
|
|
#define INTERNET_TIME_H
|
|
|
|
#include <Arduino.h>
|
|
|
|
struct InternetTimeInfo
|
|
{
|
|
bool valid;
|
|
uint16_t year;
|
|
uint8_t month;
|
|
uint8_t day;
|
|
uint8_t hour;
|
|
uint8_t minute;
|
|
};
|
|
|
|
class InternetTime
|
|
{
|
|
public:
|
|
InternetTime();
|
|
void update(unsigned long now, bool wifiConnected);
|
|
InternetTimeInfo info() const;
|
|
bool consumeDirty();
|
|
|
|
private:
|
|
void fetch(unsigned long now);
|
|
void updateCurrentTime(unsigned long now);
|
|
InternetTimeInfo infoFromEpoch(unsigned long epoch) const;
|
|
|
|
unsigned long lastEpoch_;
|
|
unsigned long lastSyncMillis_;
|
|
unsigned long nextAttempt_;
|
|
InternetTimeInfo current_;
|
|
bool dirty_;
|
|
};
|
|
|
|
#endif
|