From 5fe1d93b7d44ebfac38acc415b6040164ae9b953 Mon Sep 17 00:00:00 2001 From: Correl Date: Tue, 25 Jul 2023 15:19:55 -0400 Subject: [PATCH] Reset interaction timeout on wake Prevents the device from immediately going back to sleep, rendering it less responsive. --- src/main.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1ac5119..0e69bde 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -498,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); @@ -505,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 @@ -518,6 +524,7 @@ public: protected: enum Mode {Playing, CommanderDamage, ConfirmReset}; Mode mode; + bool awake = true; struct Rect { int x; int y; @@ -734,12 +741,12 @@ 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()); } };