Add WIP weather stuff

This commit is contained in:
Lewis Jackson 2023-06-01 17:22:37 +03:00
parent 07e83e7557
commit 23b1328cba
5 changed files with 42 additions and 18 deletions

View file

@ -5,6 +5,8 @@
#include <Fonts/FreeMonoBold9pt7b.h> #include <Fonts/FreeMonoBold9pt7b.h>
#include <Fonts/FreeMonoBold12pt7b.h> #include <Fonts/FreeMonoBold12pt7b.h>
RTC_DATA_ATTR uint64_t WatchFacePages::Weather::m_lastSyncTime = 0;
WatchFacePages::Weather::Weather(WatchyDisplay & display, WatchFeatures::WatchFeatures & features) WatchFacePages::Weather::Weather(WatchyDisplay & display, WatchFeatures::WatchFeatures & features)
: m_display(display), m_features(features) : m_display(display), m_features(features)
{ {
@ -24,3 +26,16 @@ void WatchFacePages::Weather::DrawPage(bool partialRefresh)
m_display.fillScreen(GxEPD_WHITE); m_display.fillScreen(GxEPD_WHITE);
m_display.display(partialRefresh); m_display.display(partialRefresh);
} }
void WatchFacePages::Weather::Resync()
{
// if(!m_features.wifi.Connect()) {
// return;
// }
// uint64_t currentTime = m_features.rtc.GetTimestamp();
// if(m_lastSyncTime == 0 || m_lastSyncTime + 60 * 60 * 1000 < millis()) {
// m_lastSyncTime = millis();
// }
}

View file

@ -20,7 +20,9 @@ public:
void DrawPage(bool partialRefresh = false) override; void DrawPage(bool partialRefresh = false) override;
private: private:
void Resync();
WatchyDisplay & m_display; WatchyDisplay & m_display;
WatchFeatures::WatchFeatures & m_features; WatchFeatures::WatchFeatures & m_features;
static RTC_DATA_ATTR uint64_t m_lastSyncTime;
}; };

View file

@ -10,14 +10,14 @@ RTC_DATA_ATTR bool WatchFeatures::RTC::m_initialTimer = true;
void WatchFeatures::RTC::Get(tmElements_t & tm) void WatchFeatures::RTC::Get(tmElements_t & tm)
{ {
rtc_pcf.getDateTime(); m_rtcPcf.getDateTime();
tm.Year = y2kYearToTm(rtc_pcf.getYear()); tm.Year = y2kYearToTm(m_rtcPcf.getYear());
tm.Month = rtc_pcf.getMonth(); tm.Month = m_rtcPcf.getMonth();
tm.Day = rtc_pcf.getDay(); tm.Day = m_rtcPcf.getDay();
tm.Wday = rtc_pcf.getWeekday() + 1; // TimeLib has Wday range of 1-7, but PCF8563 stores day of week in 0-6 range tm.Wday = m_rtcPcf.getWeekday() + 1; // TimeLib has Wday range of 1-7, but PCF8563 stores day of week in 0-6 range
tm.Hour = rtc_pcf.getHour(); tm.Hour = m_rtcPcf.getHour();
tm.Minute = rtc_pcf.getMinute(); tm.Minute = m_rtcPcf.getMinute();
tm.Second = rtc_pcf.getSecond(); tm.Second = m_rtcPcf.getSecond();
} }
void WatchFeatures::RTC::Set(tmElements_t tm) void WatchFeatures::RTC::Set(tmElements_t tm)
@ -25,7 +25,12 @@ void WatchFeatures::RTC::Set(tmElements_t tm)
time_t t = makeTime(tm); // make and break to calculate tm.Wday time_t t = makeTime(tm); // make and break to calculate tm.Wday
breakTime(t, tm); breakTime(t, tm);
// day, weekday, month, century(1=1900, 0=2000), year(0-99) // day, weekday, month, century(1=1900, 0=2000), year(0-99)
rtc_pcf.setDateTime(tm.Day, tm.Wday - 1, tm.Month, 0, tmYearToY2k(tm.Year), tm.Hour, tm.Minute, tm.Second); m_rtcPcf.setDateTime(tm.Day, tm.Wday - 1, tm.Month, 0, tmYearToY2k(tm.Year), tm.Hour, tm.Minute, tm.Second);
}
uint64_t WatchFeatures::RTC::GetTimestamp()
{
return m_rtcPcf.getTimestamp64();
} }
void WatchFeatures::RTC::SetTimer() void WatchFeatures::RTC::SetTimer()
@ -115,8 +120,8 @@ bool WatchFeatures::RTC::CheckWakeup()
} }
// Timer doesn't work reliably unless it's cleared first // Timer doesn't work reliably unless it's cleared first
rtc_pcf.clearTimer(); m_rtcPcf.clearTimer();
rtc_pcf.setTimer(interval, frequency, true); m_rtcPcf.setTimer(interval, frequency, true);
return true; return true;
} }
@ -126,16 +131,16 @@ bool WatchFeatures::RTC::CheckWakeup()
void WatchFeatures::RTC::Resync() void WatchFeatures::RTC::Resync()
{ {
rtc_pcf.getDateTime(); m_rtcPcf.getDateTime();
// Sleep just long enough to get to a multiple of the update interval, makes updates happen on exact turn of the minute // Sleep just long enough to get to a multiple of the update interval, makes updates happen on exact turn of the minute
int seconds = UPDATE_INTERVAL - (rtc_pcf.getSecond() % UPDATE_INTERVAL); int seconds = UPDATE_INTERVAL - (m_rtcPcf.getSecond() % UPDATE_INTERVAL);
if (seconds < 0) { if (seconds < 0) {
seconds = 0; seconds = 0;
} }
// Timer doesn't work reliably unless it's cleared first // Timer doesn't work reliably unless it's cleared first
rtc_pcf.clearTimer(); m_rtcPcf.clearTimer();
if (seconds == 0) { if (seconds == 0) {
// If there's no time to wait, just call CheckWakeup() immediately and it'll set the repeating timer // If there's no time to wait, just call CheckWakeup() immediately and it'll set the repeating timer
@ -143,7 +148,7 @@ void WatchFeatures::RTC::Resync()
m_initialTimer = true; m_initialTimer = true;
CheckWakeup(); CheckWakeup();
} else { } else {
rtc_pcf.setTimer(seconds, TMR_1Hz, false); m_rtcPcf.setTimer(seconds, TMR_1Hz, false);
m_timerSet = true; m_timerSet = true;
m_initialTimer = true; m_initialTimer = true;

View file

@ -12,12 +12,10 @@ namespace WatchFeatures
} }
class WatchFeatures::RTC { class WatchFeatures::RTC {
public:
Rtc_Pcf8563 rtc_pcf;
public: public:
void Get(tmElements_t & tm); void Get(tmElements_t & tm);
void Set(tmElements_t tm); void Set(tmElements_t tm);
uint64_t GetTimestamp();
void SetTimer(); void SetTimer();
bool CheckWakeup(); // Checks to really wake up or not, also resets the timer after the initial sleep bool CheckWakeup(); // Checks to really wake up or not, also resets the timer after the initial sleep
void Resync(); // Resync the timer cycle, both initially and after RTC resync void Resync(); // Resync the timer cycle, both initially and after RTC resync
@ -25,6 +23,7 @@ public:
static void OffsetTime(tmElements_t & tm, int offsetInSeconds); static void OffsetTime(tmElements_t & tm, int offsetInSeconds);
private: private:
Rtc_Pcf8563 m_rtcPcf;
static RTC_DATA_ATTR bool m_timerSet, m_initialTimer; static RTC_DATA_ATTR bool m_timerSet, m_initialTimer;
}; };

View file

@ -34,6 +34,7 @@
#define EEPROM_MAGIC2 0x0d #define EEPROM_MAGIC2 0x0d
#define EEPROM_VERSION 1 #define EEPROM_VERSION 1
#define OPENWEATHERMAP_API_KEY ""
#include "secrets.h" #include "secrets.h"
#if !defined(WIFI_SSID) || !defined(WIFI_PASS) #if !defined(WIFI_SSID) || !defined(WIFI_PASS)
#error "Please define WIFI_SSID and WIFI_PASS in secrets.h" #error "Please define WIFI_SSID and WIFI_PASS in secrets.h"
@ -45,3 +46,5 @@
#define UPDATE_INTERVAL 60 // seconds #define UPDATE_INTERVAL 60 // seconds
#define WAKE_ON_ACCEL_EVENTS false // useful if saving battery by not updating every minute #define WAKE_ON_ACCEL_EVENTS false // useful if saving battery by not updating every minute
#define WEATHER_UPDATE_INTERVAL 3600 // seconds