Add WIP weather stuff
This commit is contained in:
parent
07e83e7557
commit
23b1328cba
5 changed files with 42 additions and 18 deletions
|
@ -5,6 +5,8 @@
|
|||
#include <Fonts/FreeMonoBold9pt7b.h>
|
||||
#include <Fonts/FreeMonoBold12pt7b.h>
|
||||
|
||||
RTC_DATA_ATTR uint64_t WatchFacePages::Weather::m_lastSyncTime = 0;
|
||||
|
||||
WatchFacePages::Weather::Weather(WatchyDisplay & display, WatchFeatures::WatchFeatures & features)
|
||||
: m_display(display), m_features(features)
|
||||
{
|
||||
|
@ -24,3 +26,16 @@ void WatchFacePages::Weather::DrawPage(bool partialRefresh)
|
|||
m_display.fillScreen(GxEPD_WHITE);
|
||||
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();
|
||||
// }
|
||||
}
|
|
@ -20,7 +20,9 @@ public:
|
|||
void DrawPage(bool partialRefresh = false) override;
|
||||
|
||||
private:
|
||||
void Resync();
|
||||
|
||||
WatchyDisplay & m_display;
|
||||
WatchFeatures::WatchFeatures & m_features;
|
||||
static RTC_DATA_ATTR uint64_t m_lastSyncTime;
|
||||
};
|
|
@ -10,14 +10,14 @@ RTC_DATA_ATTR bool WatchFeatures::RTC::m_initialTimer = true;
|
|||
|
||||
void WatchFeatures::RTC::Get(tmElements_t & tm)
|
||||
{
|
||||
rtc_pcf.getDateTime();
|
||||
tm.Year = y2kYearToTm(rtc_pcf.getYear());
|
||||
tm.Month = rtc_pcf.getMonth();
|
||||
tm.Day = rtc_pcf.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.Hour = rtc_pcf.getHour();
|
||||
tm.Minute = rtc_pcf.getMinute();
|
||||
tm.Second = rtc_pcf.getSecond();
|
||||
m_rtcPcf.getDateTime();
|
||||
tm.Year = y2kYearToTm(m_rtcPcf.getYear());
|
||||
tm.Month = m_rtcPcf.getMonth();
|
||||
tm.Day = m_rtcPcf.getDay();
|
||||
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 = m_rtcPcf.getHour();
|
||||
tm.Minute = m_rtcPcf.getMinute();
|
||||
tm.Second = m_rtcPcf.getSecond();
|
||||
}
|
||||
|
||||
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
|
||||
breakTime(t, tm);
|
||||
// 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()
|
||||
|
@ -115,8 +120,8 @@ bool WatchFeatures::RTC::CheckWakeup()
|
|||
}
|
||||
|
||||
// Timer doesn't work reliably unless it's cleared first
|
||||
rtc_pcf.clearTimer();
|
||||
rtc_pcf.setTimer(interval, frequency, true);
|
||||
m_rtcPcf.clearTimer();
|
||||
m_rtcPcf.setTimer(interval, frequency, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -126,16 +131,16 @@ bool WatchFeatures::RTC::CheckWakeup()
|
|||
|
||||
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
|
||||
int seconds = UPDATE_INTERVAL - (rtc_pcf.getSecond() % UPDATE_INTERVAL);
|
||||
int seconds = UPDATE_INTERVAL - (m_rtcPcf.getSecond() % UPDATE_INTERVAL);
|
||||
|
||||
if (seconds < 0) {
|
||||
seconds = 0;
|
||||
}
|
||||
|
||||
// Timer doesn't work reliably unless it's cleared first
|
||||
rtc_pcf.clearTimer();
|
||||
m_rtcPcf.clearTimer();
|
||||
|
||||
if (seconds == 0) {
|
||||
// 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;
|
||||
CheckWakeup();
|
||||
} else {
|
||||
rtc_pcf.setTimer(seconds, TMR_1Hz, false);
|
||||
m_rtcPcf.setTimer(seconds, TMR_1Hz, false);
|
||||
|
||||
m_timerSet = true;
|
||||
m_initialTimer = true;
|
||||
|
|
|
@ -12,12 +12,10 @@ namespace WatchFeatures
|
|||
}
|
||||
|
||||
class WatchFeatures::RTC {
|
||||
public:
|
||||
Rtc_Pcf8563 rtc_pcf;
|
||||
|
||||
public:
|
||||
void Get(tmElements_t & tm);
|
||||
void Set(tmElements_t tm);
|
||||
uint64_t GetTimestamp();
|
||||
void SetTimer();
|
||||
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
|
||||
|
@ -25,6 +23,7 @@ public:
|
|||
static void OffsetTime(tmElements_t & tm, int offsetInSeconds);
|
||||
|
||||
private:
|
||||
Rtc_Pcf8563 m_rtcPcf;
|
||||
static RTC_DATA_ATTR bool m_timerSet, m_initialTimer;
|
||||
};
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#define EEPROM_MAGIC2 0x0d
|
||||
#define EEPROM_VERSION 1
|
||||
|
||||
#define OPENWEATHERMAP_API_KEY ""
|
||||
#include "secrets.h"
|
||||
#if !defined(WIFI_SSID) || !defined(WIFI_PASS)
|
||||
#error "Please define WIFI_SSID and WIFI_PASS in secrets.h"
|
||||
|
@ -45,3 +46,5 @@
|
|||
|
||||
#define UPDATE_INTERVAL 60 // seconds
|
||||
#define WAKE_ON_ACCEL_EVENTS false // useful if saving battery by not updating every minute
|
||||
|
||||
#define WEATHER_UPDATE_INTERVAL 3600 // seconds
|
Loading…
Reference in a new issue