added internet time which is shown in the main first screen

This commit is contained in:
2026-06-24 20:57:07 +03:00
parent 6f6ea0e0fd
commit 4917f57d16
6 changed files with 230 additions and 5 deletions
+36
View File
@@ -0,0 +1,36 @@
#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
+3 -1
View File
@@ -4,9 +4,11 @@
#include <U8g2lib.h>
#include "am2302_sensor.h"
#include "internet_time.h"
#include "wifi_connection.h"
void drawScreen1(U8G2 &u8g2);
void setInternetTimeInfo(InternetTimeInfo timeInfo);
void drawTimeScreen(U8G2 &u8g2);
void drawHelloWorldScreen(U8G2 &u8g2);
void drawInternetConnectionScreen(U8G2 &u8g2, WifiConnectionInfo wifiInfo);
void setEnvironmentReading(Am2302Reading reading);
+3
View File
@@ -4,4 +4,7 @@
const char WIFI_SSID[] = "your-wifi-name";
const char WIFI_PASSWORD[] = "your-wifi-password";
// Offset from UTC in seconds. Examples: Finland winter 7200, Finland summer 10800.
#define TIME_UTC_OFFSET_SECONDS 0
#endif