Compare commits

...

3 commits

Author SHA1 Message Date
5fe1d93b7d Reset interaction timeout on wake
Prevents the device from immediately going back to sleep, rendering it
less responsive.
2023-07-25 15:19:55 -04:00
e6ee237dbf Display commander damage 2023-05-02 16:30:53 -04:00
d991d7c563 Mount SD card on startup 2023-04-11 18:43:22 -04:00

View file

@ -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;