From 12ee5a913c7afdeb720799bd46ed4817baa22b40 Mon Sep 17 00:00:00 2001 From: spaceAngel Date: Sun, 19 Jun 2022 23:10:44 +0200 Subject: [PATCH] Rendering neon circles watch faces + calendar with hight cpu speed #feature --- .../Components/MainPanel/Calendar.cpp | 39 +++++---- .../WatchFaces/SubComponents/NeonCircle.cpp | 85 +++++++++++-------- .../WatchFaces/SubComponents/NeonCircle.h | 2 + 3 files changed, 73 insertions(+), 53 deletions(-) diff --git a/src/UserInterface/Components/MainPanel/Calendar.cpp b/src/UserInterface/Components/MainPanel/Calendar.cpp index 057ae3c..0d6ac35 100644 --- a/src/UserInterface/Components/MainPanel/Calendar.cpp +++ b/src/UserInterface/Components/MainPanel/Calendar.cpp @@ -5,6 +5,7 @@ #include "Calendar.h" #include "UserInterface/Components/MainPanel.h" #include "Utils/DateUtil.h" +#include "System/Esp32.h" Calendar::Calendar() { RTC_Date currentDate = TTGOClass::getWatch()->rtc->getDateTime(); @@ -15,24 +16,30 @@ Calendar::Calendar() { void Calendar::render() { if (this->shouldReRender() == true) { - uint8_t dayInWeek = DateUtil::weekday(this->year, this->month, 1); - uint8_t day = 0; - uint8_t row = 0; - while (day < DateUtil::getDaysInMonth(this->year, this->month)) { - if ((int32_t)dayInWeek == 0) { - dayInWeek = 7; - } - day++; - this->renderDay(day, row, dayInWeek); - this->renderIsNowBox(day, row, dayInWeek); - this->renderDelimiter(day, row, dayInWeek); - if (((int32_t)dayInWeek % 7) == 0) { - dayInWeek = 0; - row++; + Esp32::getInstance()->runWithCpuSpeedHigh( + [this] { + + uint8_t dayInWeek = DateUtil::weekday(this->year, this->month, 1); + uint8_t day = 0; + uint8_t row = 0; + while (day < DateUtil::getDaysInMonth(this->year, this->month)) { + + if ((int32_t)dayInWeek == 0) { + dayInWeek = 7; + } + day++; + this->renderDay(day, row, dayInWeek); + this->renderIsNowBox(day, row, dayInWeek); + this->renderDelimiter(day, row, dayInWeek); + if (((int32_t)dayInWeek % 7) == 0) { + dayInWeek = 0; + row++; + } + dayInWeek++; + } } - dayInWeek++; - } + ); this->renderMonthYearLabel(); this->setShouldReRender(false); } diff --git a/src/UserInterface/Components/MainPanel/WatchFaces/SubComponents/NeonCircle.cpp b/src/UserInterface/Components/MainPanel/WatchFaces/SubComponents/NeonCircle.cpp index bdf0cb7..e343cce 100644 --- a/src/UserInterface/Components/MainPanel/WatchFaces/SubComponents/NeonCircle.cpp +++ b/src/UserInterface/Components/MainPanel/WatchFaces/SubComponents/NeonCircle.cpp @@ -4,6 +4,7 @@ #include #include "Utils/Geometry.h" +#include "System/Esp32.h" NeonCircle::NeonCircle(uint8_t x, uint8_t y, uint8_t maxValue, long color) { this->x = x; @@ -17,44 +18,54 @@ void NeonCircle::render(int32_t value) { (this->prevValue != value) || this->shouldReRender() ) { - TTGOClass::getWatch()->tft->setTextColor(this->color); - TTGOClass::getWatch()->tft->setTextSize(2); - TTGOClass::getWatch()->tft->fillCircle(this->x, this->y + TTGOClass::getWatch()->tft->fontHeight() / 2, 44, this->color); - TTGOClass::getWatch()->tft->fillCircle(this->x, this->y + TTGOClass::getWatch()->tft->fontHeight() / 2, 34, COLOR_BACKGROUND); - TTGOClass::getWatch()->tft->drawCircle(this->x, this->y + TTGOClass::getWatch()->tft->fontHeight() / 2, 49, this->color); - TTGOClass::getWatch()->tft->drawCircle(this->x, this->y + TTGOClass::getWatch()->tft->fontHeight() / 2, 50, this->color); - int32_t step = 360 / this->maxValue; - for (int32_t i = 0; i < 12; i++) { - TTGOClass::getWatch()->tft->fillTriangle( - this->x, - this->y + TTGOClass::getWatch()->tft->fontHeight() / 2, - Geometry::getCalculatedXPointOnCircle(this->x, (i * 30) + 3, 44), - Geometry::getCalculatedYPointOnCircle(this->y + TTGOClass::getWatch()->tft->fontHeight() / 2, (i * 30) + 2, 44), - Geometry::getCalculatedXPointOnCircle(this->x, (i * 30) - 2, 44), - Geometry::getCalculatedYPointOnCircle(this->y + TTGOClass::getWatch()->tft->fontHeight() / 2, (i * 30) - 3, 44), - TFT_BLACK - ); - - } - for (int32_t i = ((value < this->maxValue) ? value : (value % this->maxValue)) * step; i < (this->maxValue * step); i++) { - int32_t pointX = Geometry::getCalculatedXPointOnCircle(this->x, i, 45 ); - int32_t pointY = Geometry::getCalculatedYPointOnCircle(this->y + TTGOClass::getWatch()->tft->fontHeight() / 2, i, 45); - - TTGOClass::getWatch()->tft->drawLine(this->x, this->y + TTGOClass::getWatch()->tft->fontHeight() / 2, pointX, pointY, COLOR_BACKGROUND); - TTGOClass::getWatch()->tft->drawLine(this->x, this->y + TTGOClass::getWatch()->tft->fontHeight() / 2, pointX, pointY+1, COLOR_BACKGROUND); - TTGOClass::getWatch()->tft->drawLine(this->x, this->y + TTGOClass::getWatch()->tft->fontHeight() / 2, pointX, pointY-1, COLOR_BACKGROUND); - } - char txt[3]; - (void)snprintf(txt, sizeof(txt), "%02d", value); - TTGOClass::getWatch()->tft->drawString( - txt, - this->x - TTGOClass::getWatch()->tft->textWidth(txt) / 2, - this->y + 6 - ); - TTGOClass::getWatch()->tft->setTextColor(COLOR_MAIN_1); - TTGOClass::getWatch()->tft->setTextSize(1); - setShouldReRender(false); + Esp32::getInstance()->runWithCpuSpeedHigh( + [value, this]() { + this->renderCircle(value); + } + ); + this->setShouldReRender(false); this->prevValue = value; } } + +void NeonCircle::renderCircle(int32_t value) { + TTGOClass::getWatch()->tft->setTextColor(this->color); + TTGOClass::getWatch()->tft->setTextSize(2); + TTGOClass::getWatch()->tft->fillCircle(this->x, this->y + TTGOClass::getWatch()->tft->fontHeight() / 2, 44, this->color); + TTGOClass::getWatch()->tft->fillCircle(this->x, this->y + TTGOClass::getWatch()->tft->fontHeight() / 2, 34, COLOR_BACKGROUND); + TTGOClass::getWatch()->tft->drawCircle(this->x, this->y + TTGOClass::getWatch()->tft->fontHeight() / 2, 49, this->color); + TTGOClass::getWatch()->tft->drawCircle(this->x, this->y + TTGOClass::getWatch()->tft->fontHeight() / 2, 50, this->color); + int32_t step = 360 / this->maxValue; + for (int32_t i = 0; i < 12; i++) { + TTGOClass::getWatch()->tft->fillTriangle( + this->x, + this->y + TTGOClass::getWatch()->tft->fontHeight() / 2, + Geometry::getCalculatedXPointOnCircle(this->x, (i * 30) + 3, 44), + Geometry::getCalculatedYPointOnCircle(this->y + TTGOClass::getWatch()->tft->fontHeight() / 2, (i * 30) + 2, 44), + Geometry::getCalculatedXPointOnCircle(this->x, (i * 30) - 2, 44), + Geometry::getCalculatedYPointOnCircle(this->y + TTGOClass::getWatch()->tft->fontHeight() / 2, (i * 30) - 3, 44), + TFT_BLACK + ); + + } + for (int32_t i = ((value < this->maxValue) ? value : (value % this->maxValue)) * step; i < (this->maxValue * step); i++) { + int32_t pointX = Geometry::getCalculatedXPointOnCircle(this->x, i, 45 ); + int32_t pointY = Geometry::getCalculatedYPointOnCircle(this->y + TTGOClass::getWatch()->tft->fontHeight() / 2, i, 45); + + TTGOClass::getWatch()->tft->drawLine(this->x, this->y + TTGOClass::getWatch()->tft->fontHeight() / 2, pointX, pointY, COLOR_BACKGROUND); + TTGOClass::getWatch()->tft->drawLine(this->x, this->y + TTGOClass::getWatch()->tft->fontHeight() / 2, pointX, pointY+1, COLOR_BACKGROUND); + TTGOClass::getWatch()->tft->drawLine(this->x, this->y + TTGOClass::getWatch()->tft->fontHeight() / 2, pointX, pointY-1, COLOR_BACKGROUND); + } + + char txt[3]; + (void)snprintf(txt, sizeof(txt), "%02d", value); + TTGOClass::getWatch()->tft->drawString( + txt, + this->x - TTGOClass::getWatch()->tft->textWidth(txt) / 2, + this->y + 6 + ); + + TTGOClass::getWatch()->tft->setTextColor(COLOR_MAIN_1); + TTGOClass::getWatch()->tft->setTextSize(1); +} diff --git a/src/UserInterface/Components/MainPanel/WatchFaces/SubComponents/NeonCircle.h b/src/UserInterface/Components/MainPanel/WatchFaces/SubComponents/NeonCircle.h index fb8635f..ca78c76 100644 --- a/src/UserInterface/Components/MainPanel/WatchFaces/SubComponents/NeonCircle.h +++ b/src/UserInterface/Components/MainPanel/WatchFaces/SubComponents/NeonCircle.h @@ -16,4 +16,6 @@ class NeonCircle : public MainComponent { int32_t prevValue; int32_t maxValue; + void renderCircle(int32_t value); + };