Skip to content

Commit

Permalink
feat: screen sleeping
Browse files Browse the repository at this point in the history
  • Loading branch information
DriftKingTW committed Mar 19, 2023
1 parent 18b65b4 commit 0938e17
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ const int outputCount = sizeof(outputs) / sizeof(outputs[0]);

// Auto sleep timer
unsigned long sleepPreviousMillis = 0;
const long SLEEP_INTERVAL = 10 * 60 * 1000;
const long SLEEP_INTERVAL = 30 * 60 * 1000;
const long SCREEN_SLEEP_INTERVAL = 3 * 60 * 1000;

// Battery timer
unsigned long batteryPreviousMillis = 0;
Expand Down Expand Up @@ -93,6 +94,7 @@ bool isCaffeinated = false;
bool isOutputLocked = false;
bool isScreenInverted = false;
bool isScreenDisabled = false;
bool isScreenSleeping = false;

// OLED Screen Content
String contentTop = "";
Expand Down Expand Up @@ -1057,7 +1059,7 @@ void renderScreen() {
u8g2.drawGlyph(0, 16, 0x00);
}

while (clearDisplay || isScreenDisabled) {
while (clearDisplay || isScreenDisabled || isScreenSleeping) {
u8g2.clearBuffer();
u8g2.sendBuffer();
delay(100);
Expand Down Expand Up @@ -1132,6 +1134,9 @@ void checkIdle() {
if (!isCaffeinated &&
currentMillis - sleepPreviousMillis > SLEEP_INTERVAL) {
goSleeping();
} else if (!isCaffeinated &&
currentMillis - sleepPreviousMillis > SCREEN_SLEEP_INTERVAL) {
isScreenSleeping = true;
}
}

Expand Down Expand Up @@ -1161,7 +1166,7 @@ void checkBattery() {
void showLowBatteryWarning() {
if (!isLowBattery) {
if (bleKeyboard.isConnected()) {
if (isScreenDisabled) {
if (isScreenDisabled || isScreenSleeping) {
tp.DotStar_SetPower(true);
tp.DotStar_SetBrightness(1);
tp.DotStar_SetPixelColor(0, 0, 255);
Expand Down Expand Up @@ -1192,7 +1197,10 @@ void showLowBatteryWarning() {
* Update sleepPreviousMillis' value to reset idle timer
*
*/
void resetIdle() { sleepPreviousMillis = currentMillis; }
void resetIdle() {
sleepPreviousMillis = currentMillis;
isScreenSleeping = false;
}

/**
* Activate WiFi and start the server
Expand Down

0 comments on commit 0938e17

Please sign in to comment.