"Simplified" the 7 segment to be less verbose.

- also made the formatting far less wide.
This commit is contained in:
Sir Garbagetruck 2023-05-29 21:40:49 +03:00
parent 06839fa806
commit cb360a8eae
2 changed files with 159 additions and 145 deletions

View file

@ -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]]);
} }

View file

@ -45,6 +45,7 @@ void WatchFace::DrawWatchFace(bool partialRefresh)
tmElements_t currentTime; tmElements_t currentTime;
m_RTC.read(currentTime, TZ_OFFSET); m_RTC.read(currentTime, TZ_OFFSET);
SevenSegment sevenSegment(30, 60, 6, 5, 5); SevenSegment sevenSegment(30, 60, 6, 5, 5);
if (currentTime.Hour < 10) { if (currentTime.Hour < 10) {