Reset interaction timeout on wake
Prevents the device from immediately going back to sleep, rendering it less responsive.
This commit is contained in:
parent
e6ee237dbf
commit
5fe1d93b7d
1 changed files with 9 additions and 2 deletions
11
src/main.cpp
11
src/main.cpp
|
@ -498,6 +498,10 @@ public:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!awake) {
|
||||||
|
awake = true;
|
||||||
|
last_interaction_time = current_time;
|
||||||
|
}
|
||||||
if (current_time >= next_clock_update) {
|
if (current_time >= next_clock_update) {
|
||||||
ESP_LOGD("LifeTracker", "Updating clock and battery display");
|
ESP_LOGD("LifeTracker", "Updating clock and battery display");
|
||||||
next_clock_update = next_minute(current_time);
|
next_clock_update = next_minute(current_time);
|
||||||
|
@ -505,6 +509,8 @@ public:
|
||||||
drawBattery();
|
drawBattery();
|
||||||
} else {
|
} else {
|
||||||
if (current_time - last_interaction_time > INACTIVITY_THRESHOLD) {
|
if (current_time - last_interaction_time > INACTIVITY_THRESHOLD) {
|
||||||
|
awake = false;
|
||||||
|
drawBattery();
|
||||||
int seconds = next_clock_update - current_time;
|
int seconds = next_clock_update - current_time;
|
||||||
ESP_LOGD("LifeTracker", "Sleep for %d seconds", seconds);
|
ESP_LOGD("LifeTracker", "Sleep for %d seconds", seconds);
|
||||||
M5.Power.lightSleep(seconds * 1000000, true); // Delay in microseconds
|
M5.Power.lightSleep(seconds * 1000000, true); // Delay in microseconds
|
||||||
|
@ -518,6 +524,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
enum Mode {Playing, CommanderDamage, ConfirmReset};
|
enum Mode {Playing, CommanderDamage, ConfirmReset};
|
||||||
Mode mode;
|
Mode mode;
|
||||||
|
bool awake = true;
|
||||||
struct Rect {
|
struct Rect {
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
|
@ -734,12 +741,12 @@ protected:
|
||||||
M5Canvas canvas(&M5.Display);
|
M5Canvas canvas(&M5.Display);
|
||||||
canvas.setFont(&fonts::Font0);
|
canvas.setFont(&fonts::Font0);
|
||||||
canvas.setTextSize(3);
|
canvas.setTextSize(3);
|
||||||
canvas.createSprite(canvas.fontHeight(), canvas.textWidth("100%"));
|
canvas.createSprite(canvas.fontHeight(), canvas.textWidth("100% "));
|
||||||
canvas.fillSprite(TFT_BLACK);
|
canvas.fillSprite(TFT_BLACK);
|
||||||
canvas.setTextColor(TFT_WHITE);
|
canvas.setTextColor(TFT_WHITE);
|
||||||
canvas.setRotation(3);
|
canvas.setRotation(3);
|
||||||
int battery = M5.Power.getBatteryLevel();
|
int battery = M5.Power.getBatteryLevel();
|
||||||
canvas.printf("%3d%%", battery);
|
canvas.printf("%3d%% %s", battery, awake ? " " : "zZ");
|
||||||
canvas.pushSprite(0, M5.Display.height() - canvas.width());
|
canvas.pushSprite(0, M5.Display.height() - canvas.width());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue