Skip to content

Commit 0938e17

Browse files
committed
feat: screen sleeping
1 parent 18b65b4 commit 0938e17

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/main.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ const int outputCount = sizeof(outputs) / sizeof(outputs[0]);
6464

6565
// Auto sleep timer
6666
unsigned long sleepPreviousMillis = 0;
67-
const long SLEEP_INTERVAL = 10 * 60 * 1000;
67+
const long SLEEP_INTERVAL = 30 * 60 * 1000;
68+
const long SCREEN_SLEEP_INTERVAL = 3 * 60 * 1000;
6869

6970
// Battery timer
7071
unsigned long batteryPreviousMillis = 0;
@@ -93,6 +94,7 @@ bool isCaffeinated = false;
9394
bool isOutputLocked = false;
9495
bool isScreenInverted = false;
9596
bool isScreenDisabled = false;
97+
bool isScreenSleeping = false;
9698

9799
// OLED Screen Content
98100
String contentTop = "";
@@ -1057,7 +1059,7 @@ void renderScreen() {
10571059
u8g2.drawGlyph(0, 16, 0x00);
10581060
}
10591061

1060-
while (clearDisplay || isScreenDisabled) {
1062+
while (clearDisplay || isScreenDisabled || isScreenSleeping) {
10611063
u8g2.clearBuffer();
10621064
u8g2.sendBuffer();
10631065
delay(100);
@@ -1132,6 +1134,9 @@ void checkIdle() {
11321134
if (!isCaffeinated &&
11331135
currentMillis - sleepPreviousMillis > SLEEP_INTERVAL) {
11341136
goSleeping();
1137+
} else if (!isCaffeinated &&
1138+
currentMillis - sleepPreviousMillis > SCREEN_SLEEP_INTERVAL) {
1139+
isScreenSleeping = true;
11351140
}
11361141
}
11371142

@@ -1161,7 +1166,7 @@ void checkBattery() {
11611166
void showLowBatteryWarning() {
11621167
if (!isLowBattery) {
11631168
if (bleKeyboard.isConnected()) {
1164-
if (isScreenDisabled) {
1169+
if (isScreenDisabled || isScreenSleeping) {
11651170
tp.DotStar_SetPower(true);
11661171
tp.DotStar_SetBrightness(1);
11671172
tp.DotStar_SetPixelColor(0, 0, 255);
@@ -1192,7 +1197,10 @@ void showLowBatteryWarning() {
11921197
* Update sleepPreviousMillis' value to reset idle timer
11931198
*
11941199
*/
1195-
void resetIdle() { sleepPreviousMillis = currentMillis; }
1200+
void resetIdle() {
1201+
sleepPreviousMillis = currentMillis;
1202+
isScreenSleeping = false;
1203+
}
11961204

11971205
/**
11981206
* Activate WiFi and start the server

0 commit comments

Comments
 (0)