feat(power): dim the backlight after ten idle seconds
This commit is contained in:
@@ -43,6 +43,22 @@ static void fallbackScreen(const char* message) {
|
||||
halted = true;
|
||||
}
|
||||
|
||||
// ponytail: fixed 10s / 8% dim, no fade. Make it a setting when someone asks.
|
||||
constexpr uint32_t kDimAfterMs = 10000;
|
||||
constexpr int kBacklightChannel = 0;
|
||||
uint32_t lastTouchMs = 0;
|
||||
bool dimmed = false;
|
||||
|
||||
void updateBacklight() {
|
||||
if (touch.touched())
|
||||
lastTouchMs = millis();
|
||||
bool idle = millis() - lastTouchMs > kDimAfterMs;
|
||||
if (idle == dimmed)
|
||||
return;
|
||||
dimmed = idle;
|
||||
ledcWrite(kBacklightChannel, dimmed ? 20 : 255);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
@@ -61,6 +77,12 @@ void setup() {
|
||||
touchSpi.begin(14, 12, 13, TOUCH_CS);
|
||||
touch.begin(touchSpi);
|
||||
|
||||
// TFT_eSPI leaves TFT_BL a plain output; LEDC takes it over for dimming.
|
||||
ledcSetup(kBacklightChannel, 5000, 8);
|
||||
ledcAttachPin(TFT_BL, kBacklightChannel);
|
||||
ledcWrite(kBacklightChannel, 255);
|
||||
lastTouchMs = millis();
|
||||
|
||||
sdSpi.begin(SD_SCK, SD_MISO, SD_MOSI, SD_CS);
|
||||
if (!SD.begin(SD_CS, sdSpi)) {
|
||||
fallbackScreen("SD card mount failed");
|
||||
@@ -79,6 +101,7 @@ void loop() {
|
||||
delay(100);
|
||||
return;
|
||||
}
|
||||
updateBacklight();
|
||||
net::loop();
|
||||
host.loop();
|
||||
// The launcher failing to start is the one error no app can recover from.
|
||||
|
||||
Reference in New Issue
Block a user