Cleaning up 7 segment library

This commit is contained in:
Lewis Jackson 2023-05-29 14:09:08 +03:00
parent 62bcff8485
commit d382753dc2

View file

@ -7,67 +7,73 @@ SevenSegment::SevenSegment(uint16_t digitWidth, uint16_t digitHeight, uint16_t d
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;
}
uint16_t digitX = x; uint16_t digitX = x;
uint16_t digitY = y; uint16_t digitY = y;
// top top-right bottom-right bottom bottom-left top-left middle // top top-right bottom-right bottom bottom-left top-left middle
bool drawSegments0[7] = { true, true, true, true, true, true, false }; const bool drawSegments[10][7] = {
bool drawSegments1[7] = { false, true, true, false, false, false, false }; { true, true, true, true, true, true, false },
bool drawSegments2[7] = { true, true, false, true, true, false, true }; { false, true, true, false, false, false, false },
bool drawSegments3[7] = { true, true, true, true, false, false, true }; { true, true, false, true, true, false, true },
bool drawSegments4[7] = { false, true, true, false, false, true, true }; { true, true, true, true, false, false, true },
bool drawSegments5[7] = { true, false, true, true, false, true, true }; { false, true, true, false, false, true, true },
bool drawSegments6[7] = { false, false, true, true, true, true, true }; { true, false, true, true, false, true, true },
bool drawSegments7[7] = { true, true, true, false, false, false, false }; { false, false, true, true, true, true, true },
bool drawSegments8[7] = { true, true, true, true, true, true, true }; { true, true, true, false, false, false, false },
bool drawSegments9[7] = { true, true, true, true, false, true, true }; { true, true, true, true, true, true, true },
bool * drawSegments[10] = { drawSegments0, drawSegments1, drawSegments2, drawSegments3, drawSegments4, drawSegments5, drawSegments6, drawSegments7, drawSegments8, drawSegments9 }; { true, true, true, true, false, true, true }
bool * segments = drawSegments[digit]; };
// A const bool * segments = drawSegments[digit];
// Top
if (segments[0]) { if (segments[0]) {
display.fillRect(digitX + m_segmentThickness, digitY, m_digitWidth - 2 * m_segmentThickness, m_segmentThickness, color); display.fillRect(digitX + m_segmentThickness, digitY, m_digitWidth - 2 * m_segmentThickness, m_segmentThickness, color);
} else { } 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, color ^ 0xFF);
} }
// B // Top-right
if (segments[1]) { if (segments[1]) {
display.fillRect(digitX + m_digitWidth - m_segmentThickness, digitY + m_segmentThickness, m_segmentThickness, m_digitHeight / 2 - m_segmentThickness * 2, color); display.fillRect(digitX + m_digitWidth - m_segmentThickness, digitY + m_segmentThickness, m_segmentThickness, m_digitHeight / 2 - m_segmentThickness * 2, color);
} else { } 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, color ^ 0xFF);
} }
// C // Bottom-right
if (segments[2]) { if (segments[2]) {
display.fillRect(digitX + m_digitWidth - m_segmentThickness, digitY + m_digitHeight / 2, m_segmentThickness, m_digitHeight / 2 - m_segmentThickness * 2, color); display.fillRect(digitX + m_digitWidth - m_segmentThickness, digitY + m_digitHeight / 2, m_segmentThickness, m_digitHeight / 2 - m_segmentThickness * 2, color);
} else { } 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, color ^ 0xFF);
} }
// D // Bottom
if (segments[3]) { if (segments[3]) {
display.fillRect(digitX + m_segmentThickness, digitY + m_digitHeight - m_segmentThickness * 2, m_digitWidth - 2 * m_segmentThickness, m_segmentThickness, color); display.fillRect(digitX + m_segmentThickness, digitY + m_digitHeight - m_segmentThickness * 2, m_digitWidth - 2 * m_segmentThickness, m_segmentThickness, color);
} else { } 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, color ^ 0xFF);
} }
// E // Bottom-left
if (segments[4]) { if (segments[4]) {
display.fillRect(digitX, digitY + m_digitHeight / 2, m_segmentThickness, m_digitHeight / 2 - m_segmentThickness * 2, color); display.fillRect(digitX, digitY + m_digitHeight / 2, m_segmentThickness, m_digitHeight / 2 - m_segmentThickness * 2, color);
} else { } 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, color ^ 0xFF);
} }
// F // Top-left
if (segments[5]) { if (segments[5]) {
display.fillRect(digitX, digitY + m_segmentThickness, m_segmentThickness, m_digitHeight / 2 - m_segmentThickness * 2, color); display.fillRect(digitX, digitY + m_segmentThickness, m_segmentThickness, m_digitHeight / 2 - m_segmentThickness * 2, color);
} else { } 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, color ^ 0xFF);
} }
// G // Middle
if (segments[6]) { if (segments[6]) {
display.fillRect(digitX + m_segmentThickness, digitY + m_digitHeight / 2 - m_segmentThickness, m_digitWidth - 2 * m_segmentThickness, m_segmentThickness, color); display.fillRect(digitX + m_segmentThickness, digitY + m_digitHeight / 2 - m_segmentThickness, m_digitWidth - 2 * m_segmentThickness, m_segmentThickness, color);
} else { } else {