mirror of
https://github.com/correl/m5paper.git
synced 2024-11-24 03:00:10 +00:00
Add sidebar text, clock, and battery to tracker
This commit is contained in:
parent
41bce1e679
commit
95da693225
1 changed files with 56 additions and 2 deletions
58
src/main.cpp
58
src/main.cpp
|
@ -315,13 +315,17 @@ public:
|
||||||
M5.Display.setRotation(1);
|
M5.Display.setRotation(1);
|
||||||
M5.Display.setFont(&fonts::Orbitron_Light_32);
|
M5.Display.setFont(&fonts::Orbitron_Light_32);
|
||||||
M5.Display.setTextSize(3);
|
M5.Display.setTextSize(3);
|
||||||
sidebarRect = {.x=0, .y=0, .width=M5.Display.width() / 10, .height=M5.Display.height(), .rotation=0};
|
sidebarRect = {.x=0, .y=0, .width=M5.Display.width() / 10, .height=M5.Display.height(), .rotation=3};
|
||||||
|
|
||||||
M5.Display.startWrite();
|
M5.Display.startWrite();
|
||||||
M5.Display.clearDisplay(TFT_WHITE);
|
M5.Display.clearDisplay(TFT_WHITE);
|
||||||
|
|
||||||
// Sidebar
|
// Sidebar
|
||||||
M5.Display.fillRect(sidebarRect.x, sidebarRect.y, sidebarRect.width, sidebarRect.height, TFT_BLACK);
|
time_t current_time = time(nullptr);
|
||||||
|
next_clock_update = next_minute(current_time);
|
||||||
|
drawSidebar();
|
||||||
|
drawClock(current_time);
|
||||||
|
drawBattery();
|
||||||
|
|
||||||
// Players
|
// Players
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
|
@ -378,6 +382,12 @@ public:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const time_t current_time = time(nullptr);
|
||||||
|
if (current_time >= next_clock_update) {
|
||||||
|
next_clock_update = next_minute(current_time);
|
||||||
|
drawClock(current_time);
|
||||||
|
drawBattery();
|
||||||
|
}
|
||||||
return App::LifeTracker;
|
return App::LifeTracker;
|
||||||
}
|
}
|
||||||
void shutdown() {
|
void shutdown() {
|
||||||
|
@ -415,6 +425,7 @@ protected:
|
||||||
Rect playerRect[4];
|
Rect playerRect[4];
|
||||||
LGFX_Button button_ok;
|
LGFX_Button button_ok;
|
||||||
LGFX_Button button_cancel;
|
LGFX_Button button_cancel;
|
||||||
|
time_t next_clock_update;
|
||||||
|
|
||||||
void drawPlayer(int player) {
|
void drawPlayer(int player) {
|
||||||
if (player < 0 || player >= 4) return;
|
if (player < 0 || player >= 4) return;
|
||||||
|
@ -500,6 +511,49 @@ protected:
|
||||||
button_cancel.drawButton();
|
button_cancel.drawButton();
|
||||||
M5.Display.endWrite();
|
M5.Display.endWrite();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void drawSidebar() {
|
||||||
|
M5Canvas canvas(&M5.Display);
|
||||||
|
canvas.createSprite(sidebarRect.width, sidebarRect.height);
|
||||||
|
canvas.fillSprite(TFT_BLACK);
|
||||||
|
canvas.setRotation(sidebarRect.rotation);
|
||||||
|
canvas.setTextColor(TFT_WHITE);
|
||||||
|
canvas.setFont(&fonts::Orbitron_Light_32);
|
||||||
|
canvas.setTextSize(1);
|
||||||
|
canvas.drawCenterString("TAP TO", canvas.width() / 2, (canvas.height() / 2) - canvas.fontHeight());
|
||||||
|
canvas.drawCenterString("RESET", canvas.width() / 2, (canvas.height() / 2));
|
||||||
|
canvas.pushSprite(sidebarRect.x, sidebarRect.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
time_t next_minute(time_t timestamp) {
|
||||||
|
return 60 * ((timestamp / 60) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawClock(time_t t) {
|
||||||
|
M5Canvas canvas(&M5.Display);
|
||||||
|
canvas.setFont(&fonts::Orbitron_Light_32);
|
||||||
|
canvas.setTextSize(1);
|
||||||
|
canvas.createSprite(canvas.fontHeight(), canvas.textWidth("00:00"));
|
||||||
|
canvas.fillSprite(TFT_BLACK);
|
||||||
|
canvas.setTextColor(TFT_WHITE);
|
||||||
|
canvas.setRotation(3);
|
||||||
|
auto tm = localtime(&t);
|
||||||
|
canvas.printf("%02d:%02d", tm->tm_hour, tm->tm_min);
|
||||||
|
canvas.pushSprite(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawBattery() {
|
||||||
|
M5Canvas canvas(&M5.Display);
|
||||||
|
canvas.setFont(&fonts::Font0);
|
||||||
|
canvas.setTextSize(3);
|
||||||
|
canvas.createSprite(canvas.fontHeight(), canvas.textWidth("100%"));
|
||||||
|
canvas.fillSprite(TFT_BLACK);
|
||||||
|
canvas.setTextColor(TFT_WHITE);
|
||||||
|
canvas.setRotation(3);
|
||||||
|
int battery = M5.Power.getBatteryLevel();
|
||||||
|
canvas.printf("%3d%%", battery);
|
||||||
|
canvas.pushSprite(0, M5.Display.height() - canvas.width());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
App* app;
|
App* app;
|
||||||
|
|
Loading…
Reference in a new issue