WatchyWatchFace/src/WatchFacePages/Clock.cpp
Lewis Jackson 90c66be515
Some checks failed
Compile / Compile (push) Failing after 1m5s
WIP refactoring
2023-06-01 03:07:52 +03:00

81 lines
No EOL
2.2 KiB
C++

#include "Clock.h"
#include "../SevenSegment.h"
#include "../Icons.h"
#include <Fonts/FreeSans9pt7b.h>
#include <Fonts/FreeMonoBold9pt7b.h>
#include <Fonts/FreeMonoBold12pt7b.h>
WatchFacePages::Clock::Clock(WatchyDisplay & display, WatchFeatures::WatchFeatures & features)
: m_display(display), m_features(features)
{
}
void WatchFacePages::Clock::InitBoot()
{
}
void WatchFacePages::Clock::InitWake()
{
}
void WatchFacePages::Clock::DrawPage(bool partialRefresh)
{
m_display.setFullWindow();
m_display.fillScreen(GxEPD_WHITE);
DrawBatteryIcon();
tmElements_t currentTime;
m_features.rtc.Get(currentTime);
int tzOffset = m_features.storage.GetTzOffset();
m_features.rtc.OffsetTime(currentTime, tzOffset);
SevenSegment sevenSegment(30, 60, 6, 5, 5);
if (currentTime.Hour < 10) {
sevenSegment.DrawDigit(m_display, 0, 15, 75, GxEPD_BLACK);
} else {
sevenSegment.DrawDigit(m_display, currentTime.Hour / 10, 20, 75, GxEPD_BLACK);
}
sevenSegment.DrawDigit(m_display, currentTime.Hour % 10, 60, 75, GxEPD_BLACK);
if (currentTime.Minute < 10) {
sevenSegment.DrawDigit(m_display, 0, 110, 75, GxEPD_BLACK);
} else {
sevenSegment.DrawDigit(m_display, currentTime.Minute / 10, 110, 75, GxEPD_BLACK);
}
sevenSegment.DrawDigit(m_display, currentTime.Minute % 10, 150, 75, GxEPD_BLACK);
m_display.fillRect(97, 90, 5, 5, GxEPD_BLACK);
m_display.fillRect(97, 110, 5, 5, GxEPD_BLACK);
m_display.display(partialRefresh);
}
void WatchFacePages::Clock::DrawBatteryIcon()
{
m_display.fillRect(200 - 48, 5, 43, 23, GxEPD_BLACK);
m_display.fillRect(200 - 46, 7, 39, 19, GxEPD_WHITE);
int intLevel = m_features.battery.GetPercentage();
uint8_t level = intLevel / 100.0f;
m_display.fillRect(200 - 44, 9, (int)std::round(35.0f * level), 15, GxEPD_BLACK);
int 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("%");
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());
}