mirror of https://github.com/sqfmi/Watchy.git
Moved to multiple watch faces.
parent
4e8f5fc1fb
commit
36e99d8a07
|
@ -1,7 +1,15 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
// Time
|
||||||
|
#include <TimeLib.h>
|
||||||
|
|
||||||
|
// Expanded
|
||||||
|
#include "WatchyExpanded.h"
|
||||||
|
|
||||||
class CWatchFace
|
class CWatchFace
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CWatchFace() = default;
|
CWatchFace() = default;
|
||||||
|
//override this method for different watch faces
|
||||||
|
virtual void Draw(CWatchyExpanded::ADisplay& display, const tmElements_t& time) = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,8 +9,43 @@
|
||||||
// Fonts
|
// Fonts
|
||||||
#include <Fonts/FreeMonoBold9pt7b.h>
|
#include <Fonts/FreeMonoBold9pt7b.h>
|
||||||
|
|
||||||
|
// 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))
|
CWatchyExpanded::CWatchyExpanded() : m_display(GxEPD2_154_D67(wcd::cs, wcd::dc, wcd::reset, wcd::busy))
|
||||||
{
|
{
|
||||||
|
AddWatchFace(new CBasicWatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWatchyExpanded::AddWatchFace(CWatchFace* pFace)
|
void CWatchyExpanded::AddWatchFace(CWatchFace* pFace)
|
||||||
|
@ -25,7 +60,7 @@ void CWatchyExpanded::Init()
|
||||||
m_rtc.init();
|
m_rtc.init();
|
||||||
|
|
||||||
// Init the display here for all cases, if unused, it will do nothing
|
// 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);
|
m_display.epd2.setBusyCallback(DisplayBusyCallback);
|
||||||
|
|
||||||
switch (wakeup_reason)
|
switch (wakeup_reason)
|
||||||
|
@ -34,17 +69,17 @@ void CWatchyExpanded::Init()
|
||||||
if(m_guiState == wc::kWatchFace_State)
|
if(m_guiState == wc::kWatchFace_State)
|
||||||
{
|
{
|
||||||
m_rtc.read(m_currentTime);
|
m_rtc.read(m_currentTime);
|
||||||
UpdateScreen(); //partial updates on tick
|
UpdateScreen(false); //partial updates on tick
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
// case ESP_SLEEP_WAKEUP_EXT1: //button Press
|
// case ESP_SLEEP_WAKEUP_EXT1: //button Press
|
||||||
// handleButtonPress();
|
// handleButtonPress();
|
||||||
// break;
|
// break;
|
||||||
default: //reset
|
default: //reset
|
||||||
//RTC.config(datetime);
|
m_rtc.config("");
|
||||||
//_bmaConfig();
|
//_bmaConfig();
|
||||||
//RTC.read(currentTime);
|
m_rtc.read(m_currentTime);
|
||||||
//showWatchFace(false); //full update on reset
|
UpdateScreen(true); //full update on reset
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
DeepSleep();
|
DeepSleep();
|
||||||
|
@ -57,44 +92,18 @@ void CWatchyExpanded::DisplayBusyCallback(const void*)
|
||||||
esp_light_sleep_start();
|
esp_light_sleep_start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWatchyExpanded::UpdateScreen()
|
void CWatchyExpanded::UpdateScreen(const bool fullUpdate)
|
||||||
{
|
{
|
||||||
m_display.setFullWindow();
|
m_display.setFullWindow();
|
||||||
//drawWatchFace();
|
m_faces[m_face]->Draw(m_display, m_currentTime);
|
||||||
DrawBasicClock(); // Temp
|
m_display.display(fullUpdate); //partial refresh
|
||||||
|
|
||||||
m_display.display(true); //partial refresh
|
|
||||||
m_guiState = wc::kWatchFace_State;
|
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()
|
void CWatchyExpanded::DeepSleep()
|
||||||
{
|
{
|
||||||
m_display.hibernate();
|
m_display.hibernate();
|
||||||
|
g_displayFullInit = false;
|
||||||
m_rtc.clearAlarm(); //resets the alarm flag in the RTC
|
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
|
for(int i=0; i<40; i++) // Set pins 0-39 to input to avoid power leaking out
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
#include "WatchyRTC.h"
|
#include "WatchyRTC.h"
|
||||||
|
|
||||||
// Expanded
|
// Expanded
|
||||||
#include "WatchFace.h"
|
|
||||||
#include "watchy_config.h"
|
#include "watchy_config.h"
|
||||||
|
|
||||||
// Defs
|
// Defs
|
||||||
|
@ -25,21 +24,20 @@ class CWatchyExpanded
|
||||||
CWatchyExpanded();
|
CWatchyExpanded();
|
||||||
|
|
||||||
void AddWatchFace(CWatchFace* pFace);
|
void AddWatchFace(CWatchFace* pFace);
|
||||||
|
|
||||||
void Init();
|
void Init();
|
||||||
|
|
||||||
|
using ADisplay = GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT>;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void DisplayBusyCallback(const void*);
|
static void DisplayBusyCallback(const void*);
|
||||||
|
|
||||||
void UpdateScreen();
|
void UpdateScreen(const bool fullUpdate);
|
||||||
void DeepSleep();
|
void DeepSleep();
|
||||||
|
|
||||||
void DrawBasicClock();
|
|
||||||
|
|
||||||
std::vector<CWatchFace*> m_faces;
|
std::vector<CWatchFace*> m_faces;
|
||||||
std::int8_t m_face = 0;
|
std::int8_t m_face = 0;
|
||||||
|
|
||||||
GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> m_display;
|
ADisplay m_display;
|
||||||
tmElements_t m_currentTime;
|
tmElements_t m_currentTime;
|
||||||
std::int8_t m_guiState = wc::kWatchFace_State;
|
std::int8_t m_guiState = wc::kWatchFace_State;
|
||||||
WatchyRTC m_rtc;
|
WatchyRTC m_rtc;
|
||||||
|
|
Loading…
Reference in New Issue