diff --git a/src/SevenSegment.cpp b/src/SevenSegment.cpp index a69d700..9f04eff 100644 --- a/src/SevenSegment.cpp +++ b/src/SevenSegment.cpp @@ -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 & display, uint8_t digit, uint16_t x, uint16_t y, uint8_t color) +void SevenSegment::DrawDigit(GxEPD2_BW & 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 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() { - static const std::vector menuPages = { - { - 0, // backPageNum - "WATCHY", // title - ALIGNMENT_CENTER, // titleAlignment - "", // body - { // Menu items - { - "Sync NTP", // title - nullptr, // callback - 1 // pageNum - }, - { - "Back", // title - nullptr, // callback - 0 // pageNum - } - }, - }, - { - 0, // backPageNum - "SYNC NTP", // title - ALIGNMENT_CENTER, // titleAlignment - "Sync with:\n" NTP_SERVER, // body - { // Menu items - { - "Sync", // title - std::bind(&WatchFace::MenuNTPSyncSelected, this), // callback - 1 // pageNum - }, - { - "Back", // title - nullptr, // callback - 0 // pageNum - } - }, - }, - }; + static const std::vector menuPages = { + { + 0, // backPageNum + "WATCHY", // title + ALIGNMENT_CENTER, // titleAlignment + "", // body + { // Menu items + { + "Sync NTP", // title + nullptr, // callback + 1 // pageNum + }, + { + "Back", // title + nullptr, // callback + 0 // pageNum + } + }, + }, + { + 0, // backPageNum + "SYNC NTP", // title + ALIGNMENT_CENTER, // titleAlignment + "Sync with:\n" NTP_SERVER, // body + { // Menu items + { + "Sync", // title + std::bind(&WatchFace::MenuNTPSyncSelected, this), // callback + 1 // pageNum + }, + { + "Back", // title + nullptr, // callback + 0 // pageNum + } + }, + }, + }; - 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; - m_menu.Reset(); - DrawWatchFace(false); - } -} \ No newline at end of file + if (m_inMenu) { + m_inMenu = false; + m_menu.Reset(); + DrawWatchFace(false); + } +}