Skip to content

Commit

Permalink
Rendering neon circles watch faces + calendar with hight cpu speed #f…
Browse files Browse the repository at this point in the history
…eature
  • Loading branch information
spaceAngel committed Jun 19, 2022
1 parent a6c0825 commit 12ee5a9
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 53 deletions.
39 changes: 23 additions & 16 deletions src/UserInterface/Components/MainPanel/Calendar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <LilyGoWatch.h>
#include "Utils/Geometry.h"
#include "System/Esp32.h"

NeonCircle::NeonCircle(uint8_t x, uint8_t y, uint8_t maxValue, long color) {
this->x = x;
Expand All @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ class NeonCircle : public MainComponent {
int32_t prevValue;
int32_t maxValue;

void renderCircle(int32_t value);

};

0 comments on commit 12ee5a9

Please sign in to comment.