Merge branch 'Truck_complains_about_formatting' of git.demoscene.dev:leblane/WatchyWatchFace into Truck_complains_about_formatting
This commit is contained in:
commit
41470931b1
2 changed files with 107 additions and 94 deletions
|
@ -1,11 +1,24 @@
|
||||||
#include "SevenSegment.h"
|
#include "SevenSegment.h"
|
||||||
|
|
||||||
SevenSegment::SevenSegment(uint16_t digitWidth, uint16_t digitHeight, uint16_t digitGap, uint16_t segmentThickness, uint16_t segmentGap)
|
SevenSegment::SevenSegment(uint16_t digitWidth,
|
||||||
: m_digitWidth(digitWidth), m_digitHeight(digitHeight), m_digitGap(digitGap), m_segmentThickness(segmentThickness), m_segmentGap(segmentGap)
|
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) {
|
if (digit > 9) {
|
||||||
return;
|
return;
|
||||||
|
@ -13,6 +26,8 @@ void SevenSegment::DrawDigit(GxEPD2_BW<WatchyDisplayBase, WatchyDisplayBase::HEI
|
||||||
|
|
||||||
uint16_t digitX = x;
|
uint16_t digitX = x;
|
||||||
uint16_t digitY = y;
|
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
|
// 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];
|
const bool * segments = drawSegments[digit];
|
||||||
|
|
||||||
// Top
|
// Top
|
||||||
if (segments[0]) {
|
display.fillRect(digitX + m_segmentThickness,
|
||||||
display.fillRect(digitX + m_segmentThickness, digitY, m_digitWidth - 2 * m_segmentThickness, m_segmentThickness, color);
|
digitY,
|
||||||
} else {
|
m_digitWidth - 2 * m_segmentThickness,
|
||||||
display.fillRect(digitX + m_segmentThickness, digitY, m_digitWidth - 2 * m_segmentThickness, m_segmentThickness, color ^ 0xFF);
|
m_segmentThickness,
|
||||||
}
|
drawcolors[segments[0]]);
|
||||||
|
|
||||||
// Top-right
|
// Top-right
|
||||||
if (segments[1]) {
|
display.fillRect(digitX + m_digitWidth - m_segmentThickness,
|
||||||
display.fillRect(digitX + m_digitWidth - m_segmentThickness, digitY + m_segmentThickness, m_segmentThickness, m_digitHeight / 2 - m_segmentThickness * 2, color);
|
digitY + m_segmentThickness,
|
||||||
} else {
|
m_segmentThickness,
|
||||||
display.fillRect(digitX + m_digitWidth - m_segmentThickness, digitY + m_segmentThickness, m_segmentThickness, m_digitHeight / 2 - m_segmentThickness * 2, color ^ 0xFF);
|
m_digitHeight / 2 - m_segmentThickness * 2,
|
||||||
}
|
drawcolors[segments[1]]);
|
||||||
|
|
||||||
// Bottom-right
|
// Bottom-right
|
||||||
if (segments[2]) {
|
display.fillRect(digitX + m_digitWidth - m_segmentThickness,
|
||||||
display.fillRect(digitX + m_digitWidth - m_segmentThickness, digitY + m_digitHeight / 2, m_segmentThickness, m_digitHeight / 2 - m_segmentThickness * 2, color);
|
digitY + m_digitHeight / 2, m_segmentThickness,
|
||||||
} else {
|
m_digitHeight / 2 - m_segmentThickness * 2,
|
||||||
display.fillRect(digitX + m_digitWidth - m_segmentThickness, digitY + m_digitHeight / 2, m_segmentThickness, m_digitHeight / 2 - m_segmentThickness * 2, color ^ 0xFF);
|
drawcolors[segments[2]]);
|
||||||
}
|
|
||||||
|
|
||||||
// Bottom
|
// Bottom
|
||||||
if (segments[3]) {
|
display.fillRect(digitX + m_segmentThickness,
|
||||||
display.fillRect(digitX + m_segmentThickness, digitY + m_digitHeight - m_segmentThickness * 2, m_digitWidth - 2 * m_segmentThickness, m_segmentThickness, color);
|
digitY + m_digitHeight - m_segmentThickness * 2,
|
||||||
} else {
|
m_digitWidth - 2 * m_segmentThickness,
|
||||||
display.fillRect(digitX + m_segmentThickness, digitY + m_digitHeight - m_segmentThickness * 2, m_digitWidth - 2 * m_segmentThickness, m_segmentThickness, color ^ 0xFF);
|
m_segmentThickness,
|
||||||
}
|
drawcolors[segments[3]]);
|
||||||
|
|
||||||
// Bottom-left
|
// Bottom-left
|
||||||
if (segments[4]) {
|
display.fillRect(digitX,
|
||||||
display.fillRect(digitX, digitY + m_digitHeight / 2, m_segmentThickness, m_digitHeight / 2 - m_segmentThickness * 2, color);
|
digitY + m_digitHeight / 2,
|
||||||
} else {
|
m_segmentThickness, m_digitHeight / 2 - m_segmentThickness * 2,
|
||||||
display.fillRect(digitX, digitY + m_digitHeight / 2, m_segmentThickness, m_digitHeight / 2 - m_segmentThickness * 2, color ^ 0xFF);
|
drawcolors[segments[4]]);
|
||||||
}
|
|
||||||
|
|
||||||
// Top-left
|
// Top-left
|
||||||
if (segments[5]) {
|
display.fillRect(digitX,
|
||||||
display.fillRect(digitX, digitY + m_segmentThickness, m_segmentThickness, m_digitHeight / 2 - m_segmentThickness * 2, color);
|
digitY + m_segmentThickness,
|
||||||
} else {
|
m_segmentThickness,
|
||||||
display.fillRect(digitX, digitY + m_segmentThickness, m_segmentThickness, m_digitHeight / 2 - m_segmentThickness * 2, color ^ 0xFF);
|
m_digitHeight / 2 - m_segmentThickness * 2,
|
||||||
}
|
drawcolors[segments[5]]);
|
||||||
|
|
||||||
// Middle
|
// Middle
|
||||||
if (segments[6]) {
|
display.fillRect(digitX + m_segmentThickness,
|
||||||
display.fillRect(digitX + m_segmentThickness, digitY + m_digitHeight / 2 - m_segmentThickness, m_digitWidth - 2 * m_segmentThickness, m_segmentThickness, color);
|
digitY + m_digitHeight / 2 - m_segmentThickness,
|
||||||
} else {
|
m_digitWidth - 2 * m_segmentThickness,
|
||||||
display.fillRect(digitX + m_segmentThickness, digitY + m_digitHeight / 2 - m_segmentThickness, m_digitWidth - 2 * m_segmentThickness, m_segmentThickness, color ^ 0xFF);
|
m_segmentThickness,
|
||||||
}
|
drawcolors[segments[6]]);
|
||||||
}
|
}
|
|
@ -23,71 +23,71 @@ void WatchFace::Setup() // Called after hardware is set up
|
||||||
|
|
||||||
void WatchFace::HandleButtonPress(uint64_t buttonMask)
|
void WatchFace::HandleButtonPress(uint64_t buttonMask)
|
||||||
{
|
{
|
||||||
if (m_inMenu) {
|
if (m_inMenu) {
|
||||||
m_menu.HandleButtonPress(buttonMask);
|
m_menu.HandleButtonPress(buttonMask);
|
||||||
} else {
|
} else {
|
||||||
if (buttonMask & MENU_BTN_MASK) {
|
if (buttonMask & MENU_BTN_MASK) {
|
||||||
m_inMenu = true;
|
m_inMenu = true;
|
||||||
m_menu.Redraw(false);
|
m_menu.Redraw(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WatchFace::DrawWatchFace(bool partialRefresh)
|
void WatchFace::DrawWatchFace(bool partialRefresh)
|
||||||
{
|
{
|
||||||
if (m_inMenu) {
|
if (m_inMenu) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_display.setFullWindow();
|
m_display.setFullWindow();
|
||||||
|
|
||||||
if (!partialRefresh) {
|
if (!partialRefresh) {
|
||||||
m_display.clearScreen();
|
m_display.clearScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_display.fillScreen(GxEPD_WHITE);
|
m_display.fillScreen(GxEPD_WHITE);
|
||||||
DrawBatteryIcon();
|
DrawBatteryIcon();
|
||||||
|
|
||||||
tmElements_t currentTime;
|
tmElements_t currentTime;
|
||||||
m_RTC.read(currentTime, m_tzOffset);
|
m_RTC.read(currentTime, m_tzOffset);
|
||||||
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, 10, 75, GxEPD_BLACK);
|
||||||
} else {
|
} else {
|
||||||
sevenSegment.DrawDigit(m_display, currentTime.Hour / 10, 10, 75, GxEPD_BLACK);
|
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) {
|
if (currentTime.Minute < 10) {
|
||||||
sevenSegment.DrawDigit(m_display, 0, 100, 75, GxEPD_BLACK);
|
sevenSegment.DrawDigit(m_display, 0, 100, 75, GxEPD_BLACK);
|
||||||
} else {
|
} else {
|
||||||
sevenSegment.DrawDigit(m_display, currentTime.Minute / 10, 100, 75, GxEPD_BLACK);
|
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, 90, 5, 5, GxEPD_BLACK);
|
||||||
m_display.fillRect(87, 110, 5, 5, GxEPD_BLACK);
|
m_display.fillRect(87, 110, 5, 5, GxEPD_BLACK);
|
||||||
|
|
||||||
m_display.display(partialRefresh);
|
m_display.display(partialRefresh);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WatchFace::DrawBatteryIcon()
|
void WatchFace::DrawBatteryIcon()
|
||||||
{
|
{
|
||||||
m_display.fillRect(200 - 48, 5, 43, 23, GxEPD_BLACK);
|
m_display.fillRect(200 - 48, 5, 43, 23, GxEPD_BLACK);
|
||||||
m_display.fillRect(200 - 46, 7, 39, 19, GxEPD_WHITE);
|
m_display.fillRect(200 - 46, 7, 39, 19, GxEPD_WHITE);
|
||||||
float VBAT = GetBatteryVoltage();
|
float VBAT = GetBatteryVoltage();
|
||||||
float level = (VBAT - 3.6f) / 0.6f;
|
float level = (VBAT - 3.6f) / 0.6f;
|
||||||
if (level > 1.0f) {
|
if (level > 1.0f) {
|
||||||
level = 1.0f;
|
level = 1.0f;
|
||||||
} else if (level < 0.0f) {
|
} else if (level < 0.0f) {
|
||||||
level = 0.0f;
|
level = 0.0f;
|
||||||
}
|
}
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WatchFace::SetupVolatileMenuStuff()
|
void WatchFace::SetupVolatileMenuStuff()
|
||||||
|
@ -169,23 +169,23 @@ void WatchFace::SetupVolatileMenuStuff()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
m_menu.SetPages(menuPages);
|
m_menu.SetPages(menuPages);
|
||||||
m_menu.SetExitCallback(std::bind(&WatchFace::MenuExited, this));
|
m_menu.SetExitCallback(std::bind(&WatchFace::MenuExited, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
void WatchFace::MenuExited()
|
void WatchFace::MenuExited()
|
||||||
{
|
{
|
||||||
if (m_inMenu) {
|
if (m_inMenu) {
|
||||||
m_inMenu = false;
|
m_inMenu = false;
|
||||||
DrawWatchFace(false);
|
DrawWatchFace(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WatchFace::MenuNTPSyncSelected()
|
void WatchFace::MenuNTPSyncSelected()
|
||||||
{
|
{
|
||||||
ConnectWiFi();
|
ConnectWiFi();
|
||||||
SyncNTPTime();
|
SyncNTPTime();
|
||||||
DisconnectWiFi();
|
DisconnectWiFi();
|
||||||
|
|
||||||
if (m_inMenu) {
|
if (m_inMenu) {
|
||||||
m_inMenu = false;
|
m_inMenu = false;
|
||||||
|
|
Loading…
Reference in a new issue