Merge branch 'Truck_complains_about_formatting' of git.demoscene.dev:leblane/WatchyWatchFace into Truck_complains_about_formatting

This commit is contained in:
Lewis Jackson 2023-05-29 22:13:28 +03:00
commit 41470931b1
2 changed files with 107 additions and 94 deletions

View file

@ -1,11 +1,24 @@
#include "SevenSegment.h"
SevenSegment::SevenSegment(uint16_t digitWidth, uint16_t digitHeight, uint16_t digitGap, uint16_t segmentThickness, uint16_t segmentGap)
: m_digitWidth(digitWidth), m_digitHeight(digitHeight), m_digitGap(digitGap), m_segmentThickness(segmentThickness), m_segmentGap(segmentGap)
SevenSegment::SevenSegment(uint16_t digitWidth,
uint16_t digitHeight,
uint16_t digitGap,
uint16_t segmentThickness,
uint16_t segmentGap)
: m_digitWidth(digitWidth),
m_digitHeight(digitHeight),
m_digitGap(digitGap),
m_segmentThickness(segmentThickness),
m_segmentGap(segmentGap)
{
}
void SevenSegment::DrawDigit(GxEPD2_BW<WatchyDisplayBase, WatchyDisplayBase::HEIGHT> & display, uint8_t digit, uint16_t x, uint16_t y, uint8_t color)
void SevenSegment::DrawDigit(GxEPD2_BW<WatchyDisplayBase,
WatchyDisplayBase::HEIGHT> & display,
uint8_t digit,
uint16_t x,
uint16_t y,
uint8_t color)
{
if (digit > 9) {
return;
@ -13,6 +26,8 @@ void SevenSegment::DrawDigit(GxEPD2_BW<WatchyDisplayBase, WatchyDisplayBase::HEI
uint16_t digitX = x;
uint16_t digitY = y;
uint8_t drawcolors[] = { (uint8_t) (color ^ 0xFF) ,
(uint8_t) color };
// top top-right bottom-right bottom bottom-left top-left middle
@ -32,51 +47,49 @@ void SevenSegment::DrawDigit(GxEPD2_BW<WatchyDisplayBase, WatchyDisplayBase::HEI
const bool * segments = drawSegments[digit];
// Top
if (segments[0]) {
display.fillRect(digitX + m_segmentThickness, digitY, m_digitWidth - 2 * m_segmentThickness, m_segmentThickness, color);
} else {
display.fillRect(digitX + m_segmentThickness, digitY, m_digitWidth - 2 * m_segmentThickness, m_segmentThickness, color ^ 0xFF);
}
display.fillRect(digitX + m_segmentThickness,
digitY,
m_digitWidth - 2 * m_segmentThickness,
m_segmentThickness,
drawcolors[segments[0]]);
// Top-right
if (segments[1]) {
display.fillRect(digitX + m_digitWidth - m_segmentThickness, digitY + m_segmentThickness, m_segmentThickness, m_digitHeight / 2 - m_segmentThickness * 2, color);
} else {
display.fillRect(digitX + m_digitWidth - m_segmentThickness, digitY + m_segmentThickness, m_segmentThickness, m_digitHeight / 2 - m_segmentThickness * 2, color ^ 0xFF);
}
display.fillRect(digitX + m_digitWidth - m_segmentThickness,
digitY + m_segmentThickness,
m_segmentThickness,
m_digitHeight / 2 - m_segmentThickness * 2,
drawcolors[segments[1]]);
// Bottom-right
if (segments[2]) {
display.fillRect(digitX + m_digitWidth - m_segmentThickness, digitY + m_digitHeight / 2, m_segmentThickness, m_digitHeight / 2 - m_segmentThickness * 2, color);
} else {
display.fillRect(digitX + m_digitWidth - m_segmentThickness, digitY + m_digitHeight / 2, m_segmentThickness, m_digitHeight / 2 - m_segmentThickness * 2, color ^ 0xFF);
}
display.fillRect(digitX + m_digitWidth - m_segmentThickness,
digitY + m_digitHeight / 2, m_segmentThickness,
m_digitHeight / 2 - m_segmentThickness * 2,
drawcolors[segments[2]]);
// Bottom
if (segments[3]) {
display.fillRect(digitX + m_segmentThickness, digitY + m_digitHeight - m_segmentThickness * 2, m_digitWidth - 2 * m_segmentThickness, m_segmentThickness, color);
} else {
display.fillRect(digitX + m_segmentThickness, digitY + m_digitHeight - m_segmentThickness * 2, m_digitWidth - 2 * m_segmentThickness, m_segmentThickness, color ^ 0xFF);
}
display.fillRect(digitX + m_segmentThickness,
digitY + m_digitHeight - m_segmentThickness * 2,
m_digitWidth - 2 * m_segmentThickness,
m_segmentThickness,
drawcolors[segments[3]]);
// Bottom-left
if (segments[4]) {
display.fillRect(digitX, digitY + m_digitHeight / 2, m_segmentThickness, m_digitHeight / 2 - m_segmentThickness * 2, color);
} else {
display.fillRect(digitX, digitY + m_digitHeight / 2, m_segmentThickness, m_digitHeight / 2 - m_segmentThickness * 2, color ^ 0xFF);
}
display.fillRect(digitX,
digitY + m_digitHeight / 2,
m_segmentThickness, m_digitHeight / 2 - m_segmentThickness * 2,
drawcolors[segments[4]]);
// Top-left
if (segments[5]) {
display.fillRect(digitX, digitY + m_segmentThickness, m_segmentThickness, m_digitHeight / 2 - m_segmentThickness * 2, color);
} else {
display.fillRect(digitX, digitY + m_segmentThickness, m_segmentThickness, m_digitHeight / 2 - m_segmentThickness * 2, color ^ 0xFF);
}
display.fillRect(digitX,
digitY + m_segmentThickness,
m_segmentThickness,
m_digitHeight / 2 - m_segmentThickness * 2,
drawcolors[segments[5]]);
// Middle
if (segments[6]) {
display.fillRect(digitX + m_segmentThickness, digitY + m_digitHeight / 2 - m_segmentThickness, m_digitWidth - 2 * m_segmentThickness, m_segmentThickness, color);
} else {
display.fillRect(digitX + m_segmentThickness, digitY + m_digitHeight / 2 - m_segmentThickness, m_digitWidth - 2 * m_segmentThickness, m_segmentThickness, color ^ 0xFF);
}
}
display.fillRect(digitX + m_segmentThickness,
digitY + m_digitHeight / 2 - m_segmentThickness,
m_digitWidth - 2 * m_segmentThickness,
m_segmentThickness,
drawcolors[segments[6]]);
}

View file

@ -23,71 +23,71 @@ void WatchFace::Setup() // Called after hardware is set up
void WatchFace::HandleButtonPress(uint64_t buttonMask)
{
if (m_inMenu) {
m_menu.HandleButtonPress(buttonMask);
} else {
if (buttonMask & MENU_BTN_MASK) {
m_inMenu = true;
m_menu.Redraw(false);
}
}
if (m_inMenu) {
m_menu.HandleButtonPress(buttonMask);
} else {
if (buttonMask & MENU_BTN_MASK) {
m_inMenu = true;
m_menu.Redraw(false);
}
}
}
void WatchFace::DrawWatchFace(bool partialRefresh)
{
if (m_inMenu) {
return;
}
if (m_inMenu) {
return;
}
m_display.setFullWindow();
m_display.setFullWindow();
if (!partialRefresh) {
m_display.clearScreen();
}
if (!partialRefresh) {
m_display.clearScreen();
}
m_display.fillScreen(GxEPD_WHITE);
DrawBatteryIcon();
m_display.fillScreen(GxEPD_WHITE);
DrawBatteryIcon();
tmElements_t currentTime;
m_RTC.read(currentTime, m_tzOffset);
SevenSegment sevenSegment(30, 60, 6, 5, 5);
if (currentTime.Hour < 10) {
sevenSegment.DrawDigit(m_display, 0, 10, 75, GxEPD_BLACK);
} else {
sevenSegment.DrawDigit(m_display, currentTime.Hour / 10, 10, 75, GxEPD_BLACK);
}
if (currentTime.Hour < 10) {
sevenSegment.DrawDigit(m_display, 0, 10, 75, GxEPD_BLACK);
} else {
sevenSegment.DrawDigit(m_display, currentTime.Hour / 10, 10, 75, GxEPD_BLACK);
}
sevenSegment.DrawDigit(m_display, currentTime.Hour % 10, 50, 75, GxEPD_BLACK);
sevenSegment.DrawDigit(m_display, currentTime.Hour % 10, 50, 75, GxEPD_BLACK);
if (currentTime.Minute < 10) {
sevenSegment.DrawDigit(m_display, 0, 100, 75, GxEPD_BLACK);
} else {
sevenSegment.DrawDigit(m_display, currentTime.Minute / 10, 100, 75, GxEPD_BLACK);
}
if (currentTime.Minute < 10) {
sevenSegment.DrawDigit(m_display, 0, 100, 75, GxEPD_BLACK);
} else {
sevenSegment.DrawDigit(m_display, currentTime.Minute / 10, 100, 75, GxEPD_BLACK);
}
sevenSegment.DrawDigit(m_display, currentTime.Minute % 10, 140, 75, GxEPD_BLACK);
sevenSegment.DrawDigit(m_display, currentTime.Minute % 10, 140, 75, GxEPD_BLACK);
m_display.fillRect(87, 90, 5, 5, GxEPD_BLACK);
m_display.fillRect(87, 110, 5, 5, GxEPD_BLACK);
m_display.fillRect(87, 90, 5, 5, GxEPD_BLACK);
m_display.fillRect(87, 110, 5, 5, GxEPD_BLACK);
m_display.display(partialRefresh);
m_display.display(partialRefresh);
}
void WatchFace::DrawBatteryIcon()
{
m_display.fillRect(200 - 48, 5, 43, 23, GxEPD_BLACK);
m_display.fillRect(200 - 46, 7, 39, 19, GxEPD_WHITE);
float VBAT = GetBatteryVoltage();
float level = (VBAT - 3.6f) / 0.6f;
if (level > 1.0f) {
level = 1.0f;
} else if (level < 0.0f) {
level = 0.0f;
}
level = 0.5f - sin(asin(1.0f - 2.0f * level) / 3.0f);
m_display.fillRect(200 - 48, 5, 43, 23, GxEPD_BLACK);
m_display.fillRect(200 - 46, 7, 39, 19, GxEPD_WHITE);
float VBAT = GetBatteryVoltage();
float level = (VBAT - 3.6f) / 0.6f;
if (level > 1.0f) {
level = 1.0f;
} else if (level < 0.0f) {
level = 0.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);
}
void WatchFace::SetupVolatileMenuStuff()
@ -169,23 +169,23 @@ void WatchFace::SetupVolatileMenuStuff()
}
};
m_menu.SetPages(menuPages);
m_menu.SetExitCallback(std::bind(&WatchFace::MenuExited, this));
m_menu.SetPages(menuPages);
m_menu.SetExitCallback(std::bind(&WatchFace::MenuExited, this));
}
void WatchFace::MenuExited()
{
if (m_inMenu) {
m_inMenu = false;
DrawWatchFace(false);
}
if (m_inMenu) {
m_inMenu = false;
DrawWatchFace(false);
}
}
void WatchFace::MenuNTPSyncSelected()
{
ConnectWiFi();
SyncNTPTime();
DisconnectWiFi();
ConnectWiFi();
SyncNTPTime();
DisconnectWiFi();
if (m_inMenu) {
m_inMenu = false;
@ -203,4 +203,4 @@ void WatchFace::MenuTimeZoneSelected(int tzOffset)
m_menu.Reset();
DrawWatchFace(false);
}
}
}