From 36e99d8a07c31183997000187e1dd05a5fa3456c Mon Sep 17 00:00:00 2001 From: Michael-Paul Moore Date: Mon, 11 Apr 2022 14:53:05 -0700 Subject: [PATCH] Moved to multiple watch faces. --- src/WatchFace.h | 8 +++++ src/WatchyExpanded.cpp | 79 +++++++++++++++++++++++------------------- src/WatchyExpanded.h | 10 +++--- 3 files changed, 56 insertions(+), 41 deletions(-) diff --git a/src/WatchFace.h b/src/WatchFace.h index 326999f..68d1a7c 100644 --- a/src/WatchFace.h +++ b/src/WatchFace.h @@ -1,7 +1,15 @@ #pragma once +// Time +#include + +// Expanded +#include "WatchyExpanded.h" + class CWatchFace { public: CWatchFace() = default; + //override this method for different watch faces + virtual void Draw(CWatchyExpanded::ADisplay& display, const tmElements_t& time) = 0; }; diff --git a/src/WatchyExpanded.cpp b/src/WatchyExpanded.cpp index 9302d12..7ca412c 100644 --- a/src/WatchyExpanded.cpp +++ b/src/WatchyExpanded.cpp @@ -9,8 +9,43 @@ // Fonts #include +// Expanded +#include "WatchFace.h" + +RTC_DATA_ATTR bool g_displayFullInit = true; + +class CBasicWatch : public CWatchFace +{ + public: + void Draw(CWatchyExpanded::ADisplay& display, const tmElements_t& time) override + { + display.setFullWindow(); + display.fillScreen(GxEPD_BLACK); + display.setFont(&FreeMonoBold9pt7b); + display.setCursor(0, 15); + + tm currentLocalTime; + currentLocalTime.tm_wday = time.Wday - 1; + currentLocalTime.tm_year = time.Year + 1970 - 1900; + currentLocalTime.tm_mon = time.Month - 1; + currentLocalTime.tm_mday = time.Day; + currentLocalTime.tm_hour = time.Hour; + currentLocalTime.tm_min = time.Minute; + currentLocalTime.tm_sec = time.Second; + + display.print("Time: "); + char buffer[20]; + strftime(buffer, sizeof(buffer), " %I:%M %p", ¤tLocalTime); + display.println(buffer); + + strftime(buffer, sizeof(buffer), "%a %b %d, %Y", ¤tLocalTime); + display.print(buffer); + }; +}; + CWatchyExpanded::CWatchyExpanded() : m_display(GxEPD2_154_D67(wcd::cs, wcd::dc, wcd::reset, wcd::busy)) { + AddWatchFace(new CBasicWatch); } void CWatchyExpanded::AddWatchFace(CWatchFace* pFace) @@ -25,7 +60,7 @@ void CWatchyExpanded::Init() m_rtc.init(); // Init the display here for all cases, if unused, it will do nothing - m_display.init(0, true, 10, true); // 10ms by spec, and fast pulldown reset + m_display.init(0, g_displayFullInit, 10, true); // 10ms by spec, and fast pulldown reset m_display.epd2.setBusyCallback(DisplayBusyCallback); switch (wakeup_reason) @@ -34,17 +69,17 @@ void CWatchyExpanded::Init() if(m_guiState == wc::kWatchFace_State) { m_rtc.read(m_currentTime); - UpdateScreen(); //partial updates on tick + UpdateScreen(false); //partial updates on tick } break; // case ESP_SLEEP_WAKEUP_EXT1: //button Press // handleButtonPress(); // break; default: //reset - //RTC.config(datetime); + m_rtc.config(""); //_bmaConfig(); - //RTC.read(currentTime); - //showWatchFace(false); //full update on reset + m_rtc.read(m_currentTime); + UpdateScreen(true); //full update on reset break; } DeepSleep(); @@ -57,44 +92,18 @@ void CWatchyExpanded::DisplayBusyCallback(const void*) esp_light_sleep_start(); } -void CWatchyExpanded::UpdateScreen() +void CWatchyExpanded::UpdateScreen(const bool fullUpdate) { m_display.setFullWindow(); - //drawWatchFace(); - DrawBasicClock(); // Temp - - m_display.display(true); //partial refresh + m_faces[m_face]->Draw(m_display, m_currentTime); + m_display.display(fullUpdate); //partial refresh m_guiState = wc::kWatchFace_State; } -void CWatchyExpanded::DrawBasicClock() -{ - m_display.setFullWindow(); - m_display.fillScreen(GxEPD_BLACK); - m_display.setFont(&FreeMonoBold9pt7b); - m_display.setCursor(0, 17); - - tm currentLocalTime; - currentLocalTime.tm_wday = m_currentTime.Wday - 1; - currentLocalTime.tm_year = m_currentTime.Year + 1970 - 1900; - currentLocalTime.tm_mon = m_currentTime.Month - 1; - currentLocalTime.tm_mday = m_currentTime.Day; - currentLocalTime.tm_hour = m_currentTime.Hour; - currentLocalTime.tm_min = m_currentTime.Minute; - currentLocalTime.tm_sec = m_currentTime.Second; - - m_display.print("Time: "); - char buffer[20]; - strftime(buffer, sizeof(buffer), " %I:%M %p", ¤tLocalTime); - m_display.println(buffer); - - strftime(buffer, sizeof(buffer), "%a %b %d, %Y", ¤tLocalTime); - m_display.print(buffer); -} - void CWatchyExpanded::DeepSleep() { m_display.hibernate(); + g_displayFullInit = false; m_rtc.clearAlarm(); //resets the alarm flag in the RTC for(int i=0; i<40; i++) // Set pins 0-39 to input to avoid power leaking out diff --git a/src/WatchyExpanded.h b/src/WatchyExpanded.h index 639fe18..c9e650f 100644 --- a/src/WatchyExpanded.h +++ b/src/WatchyExpanded.h @@ -13,7 +13,6 @@ #include "WatchyRTC.h" // Expanded -#include "WatchFace.h" #include "watchy_config.h" // Defs @@ -25,21 +24,20 @@ class CWatchyExpanded CWatchyExpanded(); void AddWatchFace(CWatchFace* pFace); - void Init(); + using ADisplay = GxEPD2_BW; + private: static void DisplayBusyCallback(const void*); - void UpdateScreen(); + void UpdateScreen(const bool fullUpdate); void DeepSleep(); - void DrawBasicClock(); - std::vector m_faces; std::int8_t m_face = 0; - GxEPD2_BW m_display; + ADisplay m_display; tmElements_t m_currentTime; std::int8_t m_guiState = wc::kWatchFace_State; WatchyRTC m_rtc;