Add numeric battery level and step counter

This commit is contained in:
Lewis Jackson 2023-05-30 04:03:08 +03:00
parent ca117ea3fc
commit 0e5c686b76
2 changed files with 29 additions and 9 deletions

View file

@ -1,7 +1,10 @@
#include "WatchFace.h" #include "WatchFace.h"
#include "SevenSegment.h" #include "SevenSegment.h"
#include "Icons.h"
#include <cmath> #include <cmath>
#include <Fonts/FreeSans9pt7b.h> #include <Fonts/FreeSans9pt7b.h>
#include <Fonts/FreeMonoBold9pt7b.h>
#include <Fonts/FreeMonoBold12pt7b.h>
RTC_DATA_ATTR bool WatchFace::m_menuSetup = false; RTC_DATA_ATTR bool WatchFace::m_menuSetup = false;
RTC_DATA_ATTR bool WatchFace::m_inMenu = false; RTC_DATA_ATTR bool WatchFace::m_inMenu = false;
@ -89,23 +92,23 @@ void WatchFace::DrawWatchFace(bool partialRefresh)
SevenSegment sevenSegment(30, 60, 6, 5, 5); SevenSegment sevenSegment(30, 60, 6, 5, 5);
if (currentTime.Hour < 10) { if (currentTime.Hour < 10) {
sevenSegment.DrawDigit(m_display, 0, 10, 75, GxEPD_BLACK); sevenSegment.DrawDigit(m_display, 0, 15, 75, GxEPD_BLACK);
} else { } else {
sevenSegment.DrawDigit(m_display, currentTime.Hour / 10, 10, 75, GxEPD_BLACK); sevenSegment.DrawDigit(m_display, currentTime.Hour / 10, 20, 75, GxEPD_BLACK);
} }
sevenSegment.DrawDigit(m_display, currentTime.Hour % 10, 50, 75, GxEPD_BLACK); sevenSegment.DrawDigit(m_display, currentTime.Hour % 10, 60, 75, GxEPD_BLACK);
if (currentTime.Minute < 10) { if (currentTime.Minute < 10) {
sevenSegment.DrawDigit(m_display, 0, 100, 75, GxEPD_BLACK); sevenSegment.DrawDigit(m_display, 0, 110, 75, GxEPD_BLACK);
} else { } else {
sevenSegment.DrawDigit(m_display, currentTime.Minute / 10, 100, 75, GxEPD_BLACK); sevenSegment.DrawDigit(m_display, currentTime.Minute / 10, 110, 75, GxEPD_BLACK);
} }
sevenSegment.DrawDigit(m_display, currentTime.Minute % 10, 140, 75, GxEPD_BLACK); sevenSegment.DrawDigit(m_display, currentTime.Minute % 10, 150, 75, GxEPD_BLACK);
m_display.fillRect(87, 90, 5, 5, GxEPD_BLACK); m_display.fillRect(97, 90, 5, 5, GxEPD_BLACK);
m_display.fillRect(87, 110, 5, 5, GxEPD_BLACK); m_display.fillRect(97, 110, 5, 5, GxEPD_BLACK);
m_display.display(partialRefresh); m_display.display(partialRefresh);
} }
@ -124,6 +127,23 @@ void WatchFace::DrawBatteryIcon()
level = 0.5f - sin(asin(1.0f - 2.0f * level) / 3.0f); level = 0.5f - sin(asin(1.0f - 2.0f * level) / 3.0f);
m_display.fillRect(200 - 44, 9, (int)std::round(35.0f * level), 15, GxEPD_BLACK); m_display.fillRect(200 - 44, 9, (int)std::round(35.0f * level), 15, GxEPD_BLACK);
int x = 200 - 85;
int intLevel = (int)std::round(100.0f * level);
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, steps, 19, 23, GxEPD_BLACK);
m_display.setCursor(40, 195);
m_display.print(GetSteps());
} }
void WatchFace::SetupVolatileMenuStuff() void WatchFace::SetupVolatileMenuStuff()

View file

@ -151,7 +151,7 @@ void Watchy::ConnectWiFi()
void Watchy::SyncNTPTime() void Watchy::SyncNTPTime()
{ {
WiFiUDP ntpUDP; WiFiUDP ntpUDP;
// GMT offset should be, RTC class will adjust to local time // GMT offset should be 0, RTC class will adjust to local time
NTPClient timeClient(ntpUDP, NTP_SERVER, 0); NTPClient timeClient(ntpUDP, NTP_SERVER, 0);
timeClient.begin(); timeClient.begin();
bool success = timeClient.forceUpdate(); bool success = timeClient.forceUpdate();