Add date/day to clock, proportional fonts
All checks were successful
Compile / Compile (push) Successful in 1m23s

This commit is contained in:
Lewis Jackson 2023-06-01 18:16:20 +03:00
parent 23b1328cba
commit f718c01d80
4 changed files with 56 additions and 21 deletions

View file

@ -2,8 +2,8 @@
#include "../SevenSegment.h"
#include "../Icons.h"
#include <Fonts/FreeSans9pt7b.h>
#include <Fonts/FreeMonoBold9pt7b.h>
#include <Fonts/FreeMonoBold12pt7b.h>
#include <Fonts/FreeSans12pt7b.h>
#include <sstream>
WatchFacePages::Clock::Clock(WatchyDisplay & display, WatchFeatures::WatchFeatures & features)
: m_display(display), m_features(features)
@ -28,6 +28,7 @@ void WatchFacePages::Clock::DrawPage(bool partialRefresh)
// Get current time and offset by timezone
tmElements_t currentTime;
m_features.rtc.Get(currentTime);
std::string date = m_features.rtc.GetDateString();
int tzOffset = m_features.storage.GetTzOffset();
m_features.rtc.OffsetTime(currentTime, tzOffset);
@ -35,23 +36,48 @@ void WatchFacePages::Clock::DrawPage(bool partialRefresh)
SevenSegment sevenSegment(30, 60, 6, 5, 5);
if (currentTime.Hour < 10) {
sevenSegment.DrawDigit(m_display, 0, 15, 75, GxEPD_BLACK);
sevenSegment.DrawDigit(m_display, 0, 15, 65, GxEPD_BLACK);
} else {
sevenSegment.DrawDigit(m_display, currentTime.Hour / 10, 20, 75, GxEPD_BLACK);
sevenSegment.DrawDigit(m_display, currentTime.Hour / 10, 20, 65, GxEPD_BLACK);
}
sevenSegment.DrawDigit(m_display, currentTime.Hour % 10, 60, 75, GxEPD_BLACK);
sevenSegment.DrawDigit(m_display, currentTime.Hour % 10, 60, 65, GxEPD_BLACK);
if (currentTime.Minute < 10) {
sevenSegment.DrawDigit(m_display, 0, 110, 75, GxEPD_BLACK);
sevenSegment.DrawDigit(m_display, 0, 110, 65, GxEPD_BLACK);
} else {
sevenSegment.DrawDigit(m_display, currentTime.Minute / 10, 110, 75, GxEPD_BLACK);
sevenSegment.DrawDigit(m_display, currentTime.Minute / 10, 110, 65, GxEPD_BLACK);
}
sevenSegment.DrawDigit(m_display, currentTime.Minute % 10, 150, 75, GxEPD_BLACK);
sevenSegment.DrawDigit(m_display, currentTime.Minute % 10, 150, 65, GxEPD_BLACK);
m_display.fillRect(97, 90, 5, 5, GxEPD_BLACK);
m_display.fillRect(97, 110, 5, 5, GxEPD_BLACK);
m_display.fillRect(97, 80, 5, 5, GxEPD_BLACK);
m_display.fillRect(97, 100, 5, 5, GxEPD_BLACK);
// Print day and date
const char * weekDays[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
const char * dow = weekDays[currentTime.Wday - 1];
m_display.setFont(&FreeSans9pt7b);
m_display.setTextColor(GxEPD_BLACK);
m_display.setCursor(15, 150);
m_display.print(dow);
int16_t x, y;
uint16_t w, h;
m_display.getTextBounds(date.c_str(), 0, 0, &x, &y, &w, &h);
m_display.setCursor(180 - w, 150);
m_display.print(m_features.rtc.GetDateString().c_str());
// Seperator
m_display.fillRect(15, 127, 170, 2, GxEPD_BLACK);
// Steps
m_display.setFont(&FreeSans12pt7b);
m_display.setTextColor(GxEPD_BLACK);
m_display.drawBitmap(10, 177, Icons::steps, 19, 23, GxEPD_BLACK);
m_display.setCursor(40, 195);
m_display.print(m_features.stepCounter.GetSteps());
m_display.display(partialRefresh);
}
@ -65,19 +91,22 @@ void WatchFacePages::Clock::DrawBatteryIcon()
m_display.fillRect(200 - 44, 9, (int)std::round(35.0f * level), 15, GxEPD_BLACK);
int x = 200 - 85;
int16_t x = 200 - 85;
if (intLevel == 100) {
x -= 13;
}
m_display.setFont(&FreeMonoBold9pt7b);
m_display.setCursor(x, 22);
m_display.setTextColor(GxEPD_BLACK);
m_display.print(intLevel);
m_display.print("%");
std::ostringstream oss;
oss << intLevel << "%";
m_display.setFont(&FreeMonoBold12pt7b);
m_display.drawBitmap(10, 177, Icons::steps, 19, 23, GxEPD_BLACK);
m_display.setCursor(40, 195);
m_display.print(m_features.stepCounter.GetSteps());
m_display.setFont(&FreeSans9pt7b);
m_display.setTextColor(GxEPD_BLACK);
int16_t y;
uint16_t w, h;
m_display.getTextBounds(oss.str().c_str(), 0, 0, &x, &y, &w, &h);
m_display.setCursor(142 - w, 22);
m_display.print(oss.str().c_str());
}

View file

@ -129,6 +129,11 @@ bool WatchFeatures::RTC::CheckWakeup()
return true;
}
std::string WatchFeatures::RTC::GetDateString()
{
return std::string(m_rtcPcf.formatDate(RTCC_DATE_ISO8601));
}
void WatchFeatures::RTC::Resync()
{
m_rtcPcf.getDateTime();

View file

@ -16,6 +16,7 @@ public:
void Get(tmElements_t & tm);
void Set(tmElements_t tm);
uint64_t GetTimestamp();
std::string GetDateString();
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