Compare commits
3 commits
0eac844638
...
5fe1d93b7d
Author | SHA1 | Date | |
---|---|---|---|
5fe1d93b7d | |||
e6ee237dbf | |||
d991d7c563 |
1 changed files with 34 additions and 2 deletions
36
src/main.cpp
36
src/main.cpp
|
@ -1,4 +1,5 @@
|
|||
#include <Arduino.h>
|
||||
#include <SD.h>
|
||||
#include <M5Unified.h>
|
||||
#include <WiFi.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
|
@ -497,6 +498,10 @@ public:
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (!awake) {
|
||||
awake = true;
|
||||
last_interaction_time = current_time;
|
||||
}
|
||||
if (current_time >= next_clock_update) {
|
||||
ESP_LOGD("LifeTracker", "Updating clock and battery display");
|
||||
next_clock_update = next_minute(current_time);
|
||||
|
@ -504,6 +509,8 @@ public:
|
|||
drawBattery();
|
||||
} else {
|
||||
if (current_time - last_interaction_time > INACTIVITY_THRESHOLD) {
|
||||
awake = false;
|
||||
drawBattery();
|
||||
int seconds = next_clock_update - current_time;
|
||||
ESP_LOGD("LifeTracker", "Sleep for %d seconds", seconds);
|
||||
M5.Power.lightSleep(seconds * 1000000, true); // Delay in microseconds
|
||||
|
@ -517,6 +524,7 @@ public:
|
|||
protected:
|
||||
enum Mode {Playing, CommanderDamage, ConfirmReset};
|
||||
Mode mode;
|
||||
bool awake = true;
|
||||
struct Rect {
|
||||
int x;
|
||||
int y;
|
||||
|
@ -579,6 +587,16 @@ protected:
|
|||
canvas.setFont(&fonts::Orbitron_Light_32);
|
||||
canvas.setTextSize(3);
|
||||
canvas.drawCenterString(String(lifeTotal, DEC), rect->width / 2, (rect->height / 2) - (canvas.fontHeight() / 2));
|
||||
if (mode == Playing) {
|
||||
canvas.setTextSize(1);
|
||||
canvas.setTextColor(TFT_DARKGREY);
|
||||
int rotate = rect->rotation == 0 ? 1 : -1;
|
||||
int offset = 60 * rotate;
|
||||
canvas.drawCenterString(String(players[player].commanderDamage[0], DEC), rect->width / 2 - offset, (rect->height / 2) - (canvas.fontHeight() / 2) - offset, &fonts::Orbitron_Light_24);
|
||||
canvas.drawCenterString(String(players[player].commanderDamage[1], DEC), rect->width / 2 + offset, (rect->height / 2) - (canvas.fontHeight() / 2) - offset, &fonts::Orbitron_Light_24);
|
||||
canvas.drawCenterString(String(players[player].commanderDamage[2], DEC), rect->width / 2 - offset, (rect->height / 2) - (canvas.fontHeight() / 2) + offset, &fonts::Orbitron_Light_24);
|
||||
canvas.drawCenterString(String(players[player].commanderDamage[3], DEC), rect->width / 2 + offset, (rect->height / 2) - (canvas.fontHeight() / 2) + offset, &fonts::Orbitron_Light_24);
|
||||
}
|
||||
canvas.pushSprite(rect->x, rect->y);
|
||||
}
|
||||
|
||||
|
@ -723,18 +741,20 @@ protected:
|
|||
M5Canvas canvas(&M5.Display);
|
||||
canvas.setFont(&fonts::Font0);
|
||||
canvas.setTextSize(3);
|
||||
canvas.createSprite(canvas.fontHeight(), canvas.textWidth("100%"));
|
||||
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.printf("%3d%% %s", battery, awake ? " " : "zZ");
|
||||
canvas.pushSprite(0, M5.Display.height() - canvas.width());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
App* app;
|
||||
App::Choices current_app;
|
||||
bool sd_ok = false;
|
||||
|
||||
void setup(void) {
|
||||
auto cfg = M5.config();
|
||||
|
@ -746,6 +766,18 @@ void setup(void) {
|
|||
M5.Display.init();
|
||||
M5.Display.setTextSize(3);
|
||||
M5.Display.setCursor(0, M5.Display.height() / 4);
|
||||
M5.Display.print("Mounting SD.");
|
||||
sd_ok = SD.begin(GPIO_NUM_4, SPI, 25000000);
|
||||
int sd_tries = 1;
|
||||
while (!sd_ok) {
|
||||
sd_tries++;
|
||||
if (sd_tries > 5) break;
|
||||
delay(500);
|
||||
M5.Display.print(".");
|
||||
sd_ok = SD.begin(GPIO_NUM_4, SPI, 25000000);
|
||||
}
|
||||
M5.Display.println(sd_ok ? "ok." : "failed.");
|
||||
delay(500);
|
||||
M5.Display.println("Starting up...");
|
||||
|
||||
app = new System;
|
||||
|
|
Loading…
Reference in a new issue